Subject: Re: bug#57400: 29.0.50; Support sending patches from VC directly

From: Philip Kaludercic <[email-masked]>
Date: Thu, 13 Oct 2022 20:25:03 +0000

Philip Kaludercic <[email-masked]> writes:

> Juri Linkov <[email-masked]> writes:
>
>>>>> I have done all of the above and am prepared to push the changes, but
>>>>> before I do I was wondering if anyone would have any objections to the
>>>>> following changes to vc-git.el:
>>>>
>>>> Indeed, abbreviated commits are more usable.  But please wait a little
>>>> for more comments.
>>>
>>> Also note that this change would also only affect working-revision and
>>> previous-revision.  If necessary or preferred, I could also modify the
>>> changes to only affect working-revision.
>>
>> Nicer names would be better everywhere, including previous-revision.
>> But: In my recent mail to RMS I raised questions about 'C-u C-x v ='.
>> And when I tried your patch then the default value for "HEAD"
>> often is very strange.  For example, try to type 'C-u C-x v ='
>> on the file lisp/paren.el.  Here is what it shows:
>>
>>   Older revision [remotes/origin/scratch/eglot2emacs~488]: 
>>
>> I wonder where comes "eglot2emacs" from when the current branch is master?
>
> Hmm, it looks like Git tried to find a symbolic reference at any cost,
> so it found some branch found a relative commit.  I'll try and find out
> if there is a way to avoid this, and only use symbolic references if
> there is no positional offset.

This patch should prevent these kinds things from happening:

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 5d564f3c94..47c9082368 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -2030,14 +2030,17 @@ vc-git--run-command-string
                     (setq ok nil))))))
     (and ok str)))
 
-(defun vc-git-symbolic-commit (commit)
+(defun vc-git-symbolic-commit (commit &optional force)
   "Translate COMMIT string into symbolic form.
-Returns nil if not possible."
+Returns nil if not possible.  If the optional argument FORCE is
+non-nil, revisions containing positional
+arguments (e.g. \"master~8\") will also be accepted."
   (and commit
        (let ((name (with-temp-buffer
                      (and
                       (vc-git--out-ok "name-rev" "--name-only" commit)
                       (goto-char (point-min))
+                      (or force (not (looking-at "^.*[~^].*$" t)))
                       (= (forward-line 2) 1)
                       (bolp)
                       (buffer-substring-no-properties (point-min)