unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How to get a list of changed files with VC?
@ 2017-07-13  1:23 Michael Heerdegen
  2017-07-15 17:41 ` Dmitry Gutov
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Heerdegen @ 2017-07-13  1:23 UTC (permalink / raw)
  To: Emacs Development

Hello,

For el-search' `change' pattern, I need the following functions:

#+begin_src emacs-lisp
(defun el-search--changed-files-in-repo (repo-root-dir &optional commit)
  "Return a list of files that changed relative to COMMIT.
COMMIT defaults to HEAD."
  (cl-callf or commit "HEAD")
  (let ((default-directory repo-root-dir))
    (mapcar #'expand-file-name
            (split-string
             (shell-command-to-string
              (format "git diff -z --name-only %s --" (shell-quote-argument commit)))
             "\0" t))))

(defun el-search--file-changed-p (file revision)
  "Return non-nil when FILE has changed relative to REVISION."
  (cl-callf file-truename file)
  (when-let ((backend (vc-backend file)))
    (ignore-errors
      (let ((default-directory (file-name-directory file))
            (vc-git-diff-switches nil))
        (and
         (with-temp-buffer
           (= 1 (vc-call-backend backend 'diff (list file) nil revision
                 (current-buffer))))
         (with-temp-buffer
           (= 1 (vc-call-backend backend 'diff (list file) revision nil
                 (current-buffer)))))))))
#+end_src

I didn't find something like this existing in VC (or did I miss it?).


More specific questions about my implementation:

1.  The implementation of the first function
`el-search--changed-files-in-repo' is currently git-specific, but I
didn't find a way to implement it with functions that VC defines to make
it work for other version control systems.  Any idea?

2.  The second function `el-search--file-changed-p' doesn't have this
problem.  However, I gained it from trial and error.  Does the
implementation make sense?  How can I avoid binding vc-git-diff-switches
-> nil (I get an error for some files if I don't).  And I also need to
wrap the thing inside `ignore-errors' to avoid a more complicate
`condition-case' where I don't fully understand which errors I need to
catch.

Any help for a better implementation is greatly appreciated.


TIA,

Michael.



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

end of thread, other threads:[~2017-07-19  0:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-13  1:23 How to get a list of changed files with VC? Michael Heerdegen
2017-07-15 17:41 ` Dmitry Gutov
2017-07-15 17:52   ` Eli Zaretskii
2017-07-16 17:12     ` Dmitry Gutov
2017-07-16 17:40       ` Eli Zaretskii
2017-07-16 17:45         ` Dmitry Gutov
2017-07-16 17:49           ` Eli Zaretskii
2017-07-16 17:59             ` Dmitry Gutov
2017-07-19  0:37   ` Michael Heerdegen

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