unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#18481: vc/vc-git.el: use `with-demoted-errors' instead of `ignore-errors'.
@ 2014-09-15 13:42 Emilio Lopes
  2019-08-03 18:27 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Emilio Lopes @ 2014-09-15 13:42 UTC (permalink / raw)
  To: 18481

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  <eclig@gmx.net>
+
+    * 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.
+
 2014-09-15  Glenn Morris  <rgm@gnu.org>

     * image.el (image-multi-frame-p): Fix thinko - do not force

=== modified file 'lisp/vc/vc-git.el'
--- lisp/vc/vc-git.el    2014-09-04 16:34:45 +0000
+++ lisp/vc/vc-git.el    2014-09-15 13:36:10 +0000
@@ -185,7 +185,7 @@
                ;; 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





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18481: vc/vc-git.el: use `with-demoted-errors' instead of `ignore-errors'.
  2014-09-15 13:42 bug#18481: vc/vc-git.el: use `with-demoted-errors' instead of `ignore-errors' Emilio Lopes
@ 2019-08-03 18:27 ` Lars Ingebrigtsen
  2020-08-12 17:06   ` Stefan Kangas
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2019-08-03 18:27 UTC (permalink / raw)
  To: Emilio Lopes; +Cc: 18481

Emilio Lopes <eclig@gmx.net> 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  <eclig@gmx.net>
> +
> +    * 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





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18481: vc/vc-git.el: use `with-demoted-errors' instead of `ignore-errors'.
  2019-08-03 18:27 ` Lars Ingebrigtsen
@ 2020-08-12 17:06   ` Stefan Kangas
  2020-08-12 18:21     ` Dmitry Gutov
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Kangas @ 2020-08-12 17:06 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 18481, Emilio Lopes

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Emilio Lopes <eclig@gmx.net> 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  <eclig@gmx.net>
>> +
>> +    * 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?

I'm not a heavy user of vc, but FWIW it seems to me that it should be
safe enough to catch fewer errors.  Maybe we could just install it and
see what blows up, if the patch works for you...

> (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

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18481: vc/vc-git.el: use `with-demoted-errors' instead of `ignore-errors'.
  2020-08-12 17:06   ` Stefan Kangas
@ 2020-08-12 18:21     ` Dmitry Gutov
  2020-08-13  8:02       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Gutov @ 2020-08-12 18:21 UTC (permalink / raw)
  To: Stefan Kangas, Lars Ingebrigtsen; +Cc: 18481, Emilio Lopes

On 12.08.2020 20:06, Stefan Kangas wrote:
> I'm not a heavy user of vc, but FWIW it seems to me that it should be
> safe enough to catch fewer errors.  Maybe we could just install it and
> see what blows up, if the patch works for you..

Yup.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18481: vc/vc-git.el: use `with-demoted-errors' instead of `ignore-errors'.
  2020-08-12 18:21     ` Dmitry Gutov
@ 2020-08-13  8:02       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-13  8:02 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 18481, Stefan Kangas, Emilio Lopes

Dmitry Gutov <dgutov@yandex.ru> writes:

> On 12.08.2020 20:06, Stefan Kangas wrote:
>> I'm not a heavy user of vc, but FWIW it seems to me that it should be
>> safe enough to catch fewer errors.  Maybe we could just install it and
>> see what blows up, if the patch works for you..
>
> Yup.

OK, I've now done this.  And if it gets annoying in some use cases, the
patch should be reverted.

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





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-13  8:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-15 13:42 bug#18481: vc/vc-git.el: use `with-demoted-errors' instead of `ignore-errors' Emilio Lopes
2019-08-03 18:27 ` Lars Ingebrigtsen
2020-08-12 17:06   ` Stefan Kangas
2020-08-12 18:21     ` Dmitry Gutov
2020-08-13  8:02       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).