GNU bug report logs - #42145
vc-git file order mismatch between vc-dir and vc-diff

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Tue, 30 Jun 2020 21:34:01 UTC

Severity: normal

To reply to this bug, email your comments to 42145 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#42145; Package emacs. (Tue, 30 Jun 2020 21:34:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> linkov.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 30 Jun 2020 21:34:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: bug-gnu-emacs <at> gnu.org
Subject: vc-git file order mismatch between vc-dir and vc-diff
Date: Tue, 30 Jun 2020 23:57:28 +0300
There is an old usability problem in vc-dir.

Typing ‘=’ in a vc-dir buffer displays a vc-diff buffer where files are
sorted by different order than files are sorted in the vc-dir buffer.

For example, there is a need to commit only part of changes.
To decide what files should be marked in the vc-dir buffer,
a convenient way is to browse diffs in the vc-diff buffer
one by one and mark corresponding files in the vc-dir buffer.
But since these file lists are in different order, the task
becomes a major hassle because vc-diff doesn't distinguish
between files and directories while sorting them by name,
but vc-dir puts directories at the end after files.

Is it possible to fix the file sorting order either in vc-dir
or in vc-diff buffers?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42145; Package emacs. (Tue, 30 Jun 2020 22:09:02 GMT) Full text and rfc822 format available.

Message #8 received at 42145 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Juri Linkov <juri <at> linkov.net>, 42145 <at> debbugs.gnu.org
Subject: Re: bug#42145: vc-git file order mismatch between vc-dir and vc-diff
Date: Wed, 1 Jul 2020 01:08:04 +0300
On 30.06.2020 23:57, Juri Linkov wrote:
> There is an old usability problem in vc-dir.
> 
> Typing ‘=’ in a vc-dir buffer displays a vc-diff buffer where files are
> sorted by different order than files are sorted in the vc-dir buffer.

vc-dir has its own presentation logic, it's pretty complex.

'git diff' has a '-O' argument, which accepts <orderfile>. Maybe it'll 
help, but I kind of doubt that. Ideas welcome.

> For example, there is a need to commit only part of changes.
> To decide what files should be marked in the vc-dir buffer,
> a convenient way is to browse diffs in the vc-diff buffer
> one by one and mark corresponding files in the vc-dir buffer.
> But since these file lists are in different order, the task
> becomes a major hassle because vc-diff doesn't distinguish
> between files and directories while sorting them by name,
> but vc-dir puts directories at the end after files.

Here's a bigger feature I've wanted to see in VC for a while: commit 
from a diff.

There is a third-party package: https://github.com/caldwell/commit-patch

But it implements some of its logic in Perl, and the message buffer it 
creates is non-standard. I'd really like to see it ported to VC.

The idea is, you open a diff, maybe split some of the hunks, kill the 
ones you don't need (diff-mode supports all these operations), and then 
commit the remaining ones, from multiple files, if needed. Seems like a 
good replacement for 'git add -p' for Emacs power users.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42145; Package emacs. (Wed, 01 Jul 2020 22:11:03 GMT) Full text and rfc822 format available.

Message #11 received at 42145 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: 42145 <at> debbugs.gnu.org
Subject: Re: bug#42145: vc-git file order mismatch between vc-dir and vc-diff
Date: Thu, 02 Jul 2020 00:44:04 +0300
>> There is an old usability problem in vc-dir.
>> Typing ‘=’ in a vc-dir buffer displays a vc-diff buffer where files are
>> sorted by different order than files are sorted in the vc-dir buffer.
>
> vc-dir has its own presentation logic, it's pretty complex.

The current sorting order in vc-dir is quite good,
so better not to change it.

> 'git diff' has a '-O' argument, which accepts <orderfile>. Maybe it'll
> help, but I kind of doubt that. Ideas welcome.

Maybe it's possible to write a diff-mode function to sort file hunks in
vc-diff output buffer?  Maybe by just giving the right file-beginning regexp
to sort-subr?

> Here's a bigger feature I've wanted to see in VC for a while: commit from
> a diff.
>
> There is a third-party package: https://github.com/caldwell/commit-patch
>
> But it implements some of its logic in Perl, and the message buffer it
> creates is non-standard. I'd really like to see it ported to VC.

Nice idea.

> The idea is, you open a diff, maybe split some of the hunks, kill the ones
> you don't need (diff-mode supports all these operations), and then commit
> the remaining ones, from multiple files, if needed. Seems like a good
> replacement for 'git add -p' for Emacs power users.

But I wonder how it could handle binary files where git-diff output says just
"Binary files differ".




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42145; Package emacs. (Wed, 01 Jul 2020 22:45:01 GMT) Full text and rfc822 format available.

Message #14 received at 42145 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Juri Linkov <juri <at> linkov.net>
Cc: 42145 <at> debbugs.gnu.org
Subject: Re: bug#42145: vc-git file order mismatch between vc-dir and vc-diff
Date: Thu, 2 Jul 2020 01:44:15 +0300
On 02.07.2020 00:44, Juri Linkov wrote:
>> 'git diff' has a '-O' argument, which accepts <orderfile>. Maybe
>> it'll help, but I kind of doubt that. Ideas welcome.

> Maybe it's possible to write a diff-mode function to sort file hunks
> in
> vc-diff output buffer?  Maybe by just giving the right file-beginning
> regexp to sort-subr?

Which sort-subr?

Overall, it sounds possible. But I would be careful about making the 
display of long diffs slower.

>> The idea is, you open a diff, maybe split some of the hunks, kill the ones
>> you don't need (diff-mode supports all these operations), and then commit
>> the remaining ones, from multiple files, if needed. Seems like a good
>> replacement for 'git add -p' for Emacs power users.
> But I wonder how it could handle binary files where git-diff output says just
> "Binary files differ".

Perhaps it wouldn't.

Or perhaps it would check them in wholesale, without choosing individual 
pieces inside.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#42145; Package emacs. (Tue, 30 Mar 2021 19:25:01 GMT) Full text and rfc822 format available.

Message #17 received at 42145 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: 42145 <at> debbugs.gnu.org
Subject: Re: bug#42145: vc-git file order mismatch between vc-dir and vc-diff
Date: Tue, 30 Mar 2021 22:23:59 +0300
>> There is an old usability problem in vc-dir.
>> Typing ‘=’ in a vc-dir buffer displays a vc-diff buffer where files are
>> sorted by different order than files are sorted in the vc-dir buffer.
>
> vc-dir has its own presentation logic, it's pretty complex.
>
> 'git diff' has a '-O' argument, which accepts <orderfile>. Maybe it'll
> help, but I kind of doubt that. Ideas welcome.

I solved this problem by adding two advises:

1. vc-dir-deduce-fileset - create orderfile
2. vc-git-diff - use orderfile

#+begin_src emacs-lisp
(defvar vc-git-orderfile nil)

(advice-add 'vc-dir-deduce-fileset :after
            (lambda (&rest _)
              (when (and vc-ewoc (eq this-command 'vc-diff))
                (let* ((tmpfile (make-temp-file "vc-git-orderfile-"))
                       files)
                  (ewoc-map (lambda (filearg)
                              (push (vc-dir-fileinfo->name filearg) files))
                            vc-ewoc)
                  (with-temp-file tmpfile
                    (mapcar (lambda (file) (insert file "\n")) (nreverse files)))
                  (setq vc-git-orderfile tmpfile))))
            '((name . vc-dir-create-orderfile)))

(advice-add 'vc-git-diff :around
            (lambda (orig-fun &rest args)
              (if (and vc-git-orderfile (file-exists-p vc-git-orderfile))
                  (let ((vc-git-diff-switches
                         (append (list (format "-O%s" vc-git-orderfile))
                                 vc-git-diff-switches)))
                    (unwind-protect
	                (apply orig-fun args)
	              (delete-file vc-git-orderfile)
                      (setq vc-git-orderfile nil)))
                (apply orig-fun args)))
            '((name . vc-git-diff-use-orderfile)))
#+end_src

Ideas welcome how to integrate this nicely to the vc package.

Also it has one limitation: revert-buffer in the *vc-diff* buffer
doesn't keep the original order, but this is a very minor problem.




This bug report was last modified 3 years and 24 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.