all messages for Emacs-related lists mirrored at yhetil.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

* Re: How to get a list of changed files with VC?
  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-19  0:37   ` Michael Heerdegen
  0 siblings, 2 replies; 9+ messages in thread
From: Dmitry Gutov @ 2017-07-15 17:41 UTC (permalink / raw)
  To: Michael Heerdegen, Emacs Development

On 7/13/17 4:23 AM, Michael Heerdegen wrote:

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

For the changed files relative to HEAD, you can call the backend command 
(with vc-call-backend) named dir-status-files. But there is no way to 
specify the reference revision. Maybe calling the VC backend diff 
command on the whole repo and parsing the output could work.

> 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).
I'll need some more details to answer this.



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

* Re: How to get a list of changed files with VC?
  2017-07-15 17:41 ` Dmitry Gutov
@ 2017-07-15 17:52   ` Eli Zaretskii
  2017-07-16 17:12     ` Dmitry Gutov
  2017-07-19  0:37   ` Michael Heerdegen
  1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2017-07-15 17:52 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: michael_heerdegen, emacs-devel

> From: Dmitry Gutov <dgutov@yandex.ru>
> Date: Sat, 15 Jul 2017 20:41:29 +0300
> 
> On 7/13/17 4:23 AM, Michael Heerdegen wrote:
> 
> > 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?
> 
> For the changed files relative to HEAD, you can call the backend command 
> (with vc-call-backend) named dir-status-files. But there is no way to 
> specify the reference revision.

Maybe we should extend dir-status-files to accept a version, or even a
range of versions.

> Maybe calling the VC backend diff command on the whole repo and
> parsing the output could work.

I think Git is the odd one out providing this information as a
side-effect of a diff command (with a option that makes little sense
for a diff command).  All the other back-ends I know of provide the
info as part of the status command.  I think.



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

* Re: How to get a list of changed files with VC?
  2017-07-15 17:52   ` Eli Zaretskii
@ 2017-07-16 17:12     ` Dmitry Gutov
  2017-07-16 17:40       ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry Gutov @ 2017-07-16 17:12 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: michael_heerdegen, emacs-devel

On 7/15/17 8:52 PM, Eli Zaretskii wrote:

> Maybe we should extend dir-status-files to accept a version, or even a
> range of versions.

I have no concrete opinion on this, except that the result might be 
pushing it, complexity-wise. Let's maybe wait until we see more requests 
for exactly this functionality.

>> Maybe calling the VC backend diff command on the whole repo and
>> parsing the output could work.
> 
> I think Git is the odd one out providing this information as a
> side-effect of a diff command (with a option that makes little sense
> for a diff command).  All the other back-ends I know of provide the
> info as part of the status command.  I think.

Not sure which information you mean. I only suggested diff because one 
call pass a reference revision to it.



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

* Re: How to get a list of changed files with VC?
  2017-07-16 17:12     ` Dmitry Gutov
@ 2017-07-16 17:40       ` Eli Zaretskii
  2017-07-16 17:45         ` Dmitry Gutov
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2017-07-16 17:40 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: michael_heerdegen, emacs-devel

> Cc: michael_heerdegen@web.de, emacs-devel@gnu.org
> From: Dmitry Gutov <dgutov@yandex.ru>
> Date: Sun, 16 Jul 2017 20:12:33 +0300
> 
> >> Maybe calling the VC backend diff command on the whole repo and
> >> parsing the output could work.
> > 
> > I think Git is the odd one out providing this information as a
> > side-effect of a diff command (with a option that makes little sense
> > for a diff command).  All the other back-ends I know of provide the
> > info as part of the status command.  I think.
> 
> Not sure which information you mean. I only suggested diff because one 
> call pass a reference revision to it.

I meant the files that changed between two revisions.  AFAIU, that's
what Michael was after.



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

* Re: How to get a list of changed files with VC?
  2017-07-16 17:40       ` Eli Zaretskii
@ 2017-07-16 17:45         ` Dmitry Gutov
  2017-07-16 17:49           ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry Gutov @ 2017-07-16 17:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: michael_heerdegen, emacs-devel

On 7/16/17 8:40 PM, Eli Zaretskii wrote:

>> Not sure which information you mean. I only suggested diff because one
>> call pass a reference revision to it.
> 
> I meant the files that changed between two revisions.  AFAIU, that's
> what Michael was after.

The file names are a part of the Diff output format.

Do you mean that the FILES argument is effectively optional, or can be a 
directory?

I believe it can be a directory in all repository-granular. vc-hg-diff, 
at least, as another example, happily allows FILES to be a 
single-element list containing the repository root.



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

* Re: How to get a list of changed files with VC?
  2017-07-16 17:45         ` Dmitry Gutov
@ 2017-07-16 17:49           ` Eli Zaretskii
  2017-07-16 17:59             ` Dmitry Gutov
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2017-07-16 17:49 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: michael_heerdegen, emacs-devel

> Cc: michael_heerdegen@web.de, emacs-devel@gnu.org
> From: Dmitry Gutov <dgutov@yandex.ru>
> Date: Sun, 16 Jul 2017 20:45:27 +0300
> 
> On 7/16/17 8:40 PM, Eli Zaretskii wrote:
> 
> >> Not sure which information you mean. I only suggested diff because one
> >> call pass a reference revision to it.
> > 
> > I meant the files that changed between two revisions.  AFAIU, that's
> > what Michael was after.
> 
> The file names are a part of the Diff output format.

Yes, but it's strange to invoke a diff command only to see the names
of the changed files, without any information about the changes
themselves.



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

* Re: How to get a list of changed files with VC?
  2017-07-16 17:49           ` Eli Zaretskii
@ 2017-07-16 17:59             ` Dmitry Gutov
  0 siblings, 0 replies; 9+ messages in thread
From: Dmitry Gutov @ 2017-07-16 17:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: michael_heerdegen, emacs-devel

On 7/16/17 8:49 PM, Eli Zaretskii wrote:

> Yes, but it's strange to invoke a diff command only to see the names
> of the changed files, without any information about the changes
> themselves.

No argument that it's strange, but it might be practical and compatible 
with earlier Emacs versions as well.



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

* Re: How to get a list of changed files with VC?
  2017-07-15 17:41 ` Dmitry Gutov
  2017-07-15 17:52   ` Eli Zaretskii
@ 2017-07-19  0:37   ` Michael Heerdegen
  1 sibling, 0 replies; 9+ messages in thread
From: Michael Heerdegen @ 2017-07-19  0:37 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Emacs Development

Dmitry Gutov <dgutov@yandex.ru> writes:

> For the changed files relative to HEAD, you can call the backend
> command (with vc-call-backend) named dir-status-files. But there is no
> way to specify the reference revision. Maybe calling the VC backend
> diff command on the whole repo and parsing the output could work.

That's what I expected.  Then I think I wait until Emacs provides
something appropriate, and just change the name of my pattern to
"git-change" or something like that.

> > 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).
> I'll need some more details to answer this.

Ok, I'll try to investigate.


Thanks,

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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.