unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#42145: vc-git file order mismatch between vc-dir and vc-diff
@ 2020-06-30 20:57 Juri Linkov
  2020-06-30 22:08 ` Dmitry Gutov
  0 siblings, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2020-06-30 20:57 UTC (permalink / raw)
  To: 42145

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?





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

* bug#42145: vc-git file order mismatch between vc-dir and vc-diff
  2020-06-30 20:57 bug#42145: vc-git file order mismatch between vc-dir and vc-diff Juri Linkov
@ 2020-06-30 22:08 ` Dmitry Gutov
  2020-07-01 21:44   ` Juri Linkov
  2021-03-30 19:23   ` Juri Linkov
  0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Gutov @ 2020-06-30 22:08 UTC (permalink / raw)
  To: Juri Linkov, 42145

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.





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

* bug#42145: vc-git file order mismatch between vc-dir and vc-diff
  2020-06-30 22:08 ` Dmitry Gutov
@ 2020-07-01 21:44   ` Juri Linkov
  2020-07-01 22:44     ` Dmitry Gutov
  2021-03-30 19:23   ` Juri Linkov
  1 sibling, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2020-07-01 21:44 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 42145

>> 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".





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

* bug#42145: vc-git file order mismatch between vc-dir and vc-diff
  2020-07-01 21:44   ` Juri Linkov
@ 2020-07-01 22:44     ` Dmitry Gutov
  0 siblings, 0 replies; 5+ messages in thread
From: Dmitry Gutov @ 2020-07-01 22:44 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 42145

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.





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

* bug#42145: vc-git file order mismatch between vc-dir and vc-diff
  2020-06-30 22:08 ` Dmitry Gutov
  2020-07-01 21:44   ` Juri Linkov
@ 2021-03-30 19:23   ` Juri Linkov
  1 sibling, 0 replies; 5+ messages in thread
From: Juri Linkov @ 2021-03-30 19:23 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 42145

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





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

end of thread, other threads:[~2021-03-30 19:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-30 20:57 bug#42145: vc-git file order mismatch between vc-dir and vc-diff Juri Linkov
2020-06-30 22:08 ` Dmitry Gutov
2020-07-01 21:44   ` Juri Linkov
2020-07-01 22:44     ` Dmitry Gutov
2021-03-30 19:23   ` Juri Linkov

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).