bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#18481: vc/vc-git.el: use `with-demoted-errors' instead of `ignore-er


From: Lars Ingebrigtsen
Subject: bug#18481: vc/vc-git.el: use `with-demoted-errors' instead of `ignore-errors'.
Date: Sat, 03 Aug 2019 20:27:03 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Emilio Lopes <address@hidden> writes:

> cf. http://lists.gnu.org/archive/html/bug-gnu-emacs/2014-09/msg00394.html
>
> --- lisp/ChangeLog    2014-09-15 00:20:21 +0000
> +++ lisp/ChangeLog    2014-09-15 13:36:10 +0000
> @@ -1,3 +1,14 @@
> +2014-09-15  Emilio C. Lopes  <address@hidden>
> +
> +    * vc/vc-git.el (vc-git-registered): use `with-demoted-errors'
> +    instead of `ignore-errors' so that the user is informed if
> +    something unexpected happens.

(I'm going through old bug reports that unfortunately have not received
any responses yet.)

So, in that URL Stefan suggested using with-demoted-errors instead of
ignore-errors here, and that seems sensible.  But I'm wondering whether
this code is expected to fail, and whether the errors (in that case) are
totally uninteresting?

I've done some testing (without the `ignore-errors'), and in my tests
the code doesn't fail, so I think the patch suggested makes sense.

Does this patch makes sense to everybody else, too?

(defun vc-git-registered (file)
  "Check whether FILE is registered with git."
  (let ((dir (vc-git-root file)))
    (when dir
      (with-temp-buffer
        (let* (process-file-side-effects
               ;; Do not use the `file-name-directory' here: git-ls-files
               ;; sometimes fails to return the correct status for relative
               ;; path specs.
               ;; See also: http://marc.info/?l=git&m=125787684318129&w=2
               (name (file-relative-name file dir))
               (str (ignore-errors
                      (cd dir)
                      (vc-git--out-ok "ls-files" "-c" "-z" "--" name)
                      ;; If result is empty, use ls-tree to check for deleted
                      ;; file.
                      (when (eq (point-min) (point-max))
                        (vc-git--out-ok "ls-tree" "--name-only" "-z" "HEAD"
                                        "--" name))
                      (buffer-string))))
          (and str
               (> (length str) (length name))
               (string= (substring str 0 (1+ (length name)))
                        (concat name "\0"))))))))


>                 ;; path specs.
>                 ;; See also: http://marc.info/?l=git&m=125787684318129&w=2
>                 (name (file-relative-name file dir))
> -               (str (ignore-errors
> +               (str (with-demoted-errors "Error: %S"
>                        (cd dir)
>                        (vc-git--out-ok "ls-files" "-c" "-z" "--" name)
>                        ;; If result is empty, use ls-tree to check for deleted


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





reply via email to

[Prev in Thread] Current Thread [Next in Thread]