Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emacs isn't resyncing its internal vc state after a commit-patch commit #14

Closed
dkogan opened this issue Feb 18, 2018 · 7 comments
Closed

Comments

@dkogan
Copy link
Contributor

dkogan commented Feb 18, 2018

This feels like it's probably a regression, but I'm not sure. Problematic behavior I observe:

  1. Open some version-controlled file in emacs. I'm using git; probably this doesn't matter

  2. (vc-working-revision buffer-file-name) should return either HEAD or maybe the most recent revision of that one file. Either is fine

  3. make a change to that file, commit it with commit-patch.

  4. (vc-working-revision buffer-file-name) SHOULD now return the new revision but it doesn't for me. This being out-of-date makes vc-annotate and vc-log and others lie to you.

It looks like commit-patch tries to deal with this, but it's broken currently. I'm not patching it because I'd like to know what the intent was, and what you THINK it's doing.

Currently commit-patch-buffer-in-directory looks at the patch buffer, extracts a list of filenames in the patch, and tries to re-synchronize them with emacs. It does this by invoking "lsdiff" on the patch and parsing the output. Problem is, the patch often contains relative paths, so the patch-files variable ends up with strings like "a/file1.c", where "a" isn't a real directory, so the (find-buffer-visiting) call doesn't find the relevant buffer. The code is there. Did this ever work?

If we found a buffer, we'd do this for each one:

                                        (vc-resynch-buffer (buffer-file-name buf) 'revert 'noquery)
                                        ;; stupid vc-revert-buffer1 doesn't call revert-buffer
                                        ;; with preserve-modes which means the CVS version doesn't
                                        ;; get updated, so we do it by hand.
                                        (run-hooks 'find-file-hooks)))

The comment implies that only CVS is affected, but it's all VCSs I'm guessing. At least in this case (vc-resync-buffer) doesn't fix this, but the (run-hooks) call does. The specific call that we need is (vc-file-clearprops buffer-file-name). Maybe we don't need to run ALL the hooks, but you can decide that.

Maybe vc-resynch-buffer should do the vc-clearprops.

@caldwell
Copy link
Owner

caldwell commented Feb 3, 2019

My memory is that the revert buffer stuff was from back before commit-patch supported anything other than CVS. It's specifically because our CVS files had CVS keywords in them—on commit CVS would change the file on disk to update version numbers and even add commit logs (in comments at the end of our C files).

So the point of this code was to do a real revert so the emacs buffer would match what was on the disk. I think at least SVN can do that same keyword stuff. I doubt any of the distributed ones do it (though maybe BZR—it's strange).

But—it does use vc-resynch-buffer which sounds like it might be intending to more. @radford might know, I believe he wrote that part.

@dkogan
Copy link
Contributor Author

dkogan commented Sep 3, 2021

Bug ping. This is still a problem. Are either of you still using this? I am, and it's constantly bugging me. If you're all done with this thing, please tell me, and I'll fix it myself.

Thanks!

@caldwell
Copy link
Owner

caldwell commented Sep 3, 2021

I still use this every day—it probably accounts for 99% of commits I make. However, I never use vc-annotate or vc-log, so I've not noticed this (and it doesn't constantly bug me). I just tested and I do see vc-annotate was wrong for something I just commit-patched.

I looks like it might be as simple as adding 'reset-vc-info to the vc-resynch-buffer call:

(vc-resynch-buffer (buffer-file-name buf) 'revert 'noquery 'reset-vc-info)

Can you try that locally and see if it fixes your issue?

@dkogan
Copy link
Contributor Author

dkogan commented Sep 3, 2021 via email

@caldwell
Copy link
Owner

caldwell commented Sep 3, 2021

I think I found the issue. It was staring me in the face with the message that comes up on every commit:

Patched and committed 1 file(s) and reverted 0.

That "reverted 0" shows that it isn't actually hitting any of that revert code. The crux seems to be when we go looking for buffers earlier in the code. There were 2 things:

  1. git uses a/some/file where cvs used some/file.
  2. (find-buffer-visiting) doesn't seem to work with relative paths.

I'm not sure how 2 ever worked? Maybe cvs diff returned absolute paths? Anyway, those are both fixable. Can you try this patch?

diff --git a/commit-patch-buffer.el b/commit-patch-buffer.el
index 487e02d..7877996 100644
--- a/commit-patch-buffer.el
+++ b/commit-patch-buffer.el
@@ -90,8 +90,12 @@ one."
                             (split-string (buffer-string))))))
          (log-buffer-name (if amend "*amend*" "*commit*"))
          (f patch-files) visiting-buffers)
-    (while (car f)
-      (let ((buf (find-buffer-visiting (car f))))
+   (while (car f)
+      (let* ((default-directory directory)
+             (buf (or
+                  (find-buffer-visiting (expand-file-name (car f)))
+                  (find-buffer-visiting (expand-file-name (diff-filename-drop-dir (car f))))
+                  )))
         (when buf
           (with-current-buffer buf (vc-buffer-sync))
           (add-to-list 'visiting-buffers buf)))

With that (and without the 'reset-vc-info, which doesn't seem to matter here), it now updates the vc-working-revision correctly for me after commit-patching.

@dkogan
Copy link
Contributor Author

dkogan commented Sep 6, 2021 via email

@caldwell
Copy link
Owner

caldwell commented Sep 6, 2021

Lol, I apparently can't read. My eyes must have been drawn to the nicely formatted code section

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants