unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 42145@debbugs.gnu.org
Subject: bug#42145: vc-git file order mismatch between vc-dir and vc-diff
Date: Tue, 30 Mar 2021 22:23:59 +0300	[thread overview]
Message-ID: <871rbwtq5w.fsf@mail.linkov.net> (raw)
In-Reply-To: <fbcbcdb9-391d-50ed-8fb4-6c1b832639bb@yandex.ru> (Dmitry Gutov's message of "Wed, 1 Jul 2020 01:08: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.
>
> '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.





      parent reply	other threads:[~2021-03-30 19:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871rbwtq5w.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=42145@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).