[PATCH 1 of 2] patch: add new diffopt filenameonly

Matt Mackall mpm at selenic.com
Wed Aug 12 12:32:19 CDT 2015


On Tue, 2015-08-11 at 17:10 +0100, Simon King wrote:
> On Tue, Aug 11, 2015 at 2:03 PM, Laurent Charignon <lcharignon at fb.com> wrote:
> > # HG changeset patch
> > # User Laurent Charignon <lcharignon at fb.com>
> > # Date 1439295186 25200
> > #      Tue Aug 11 05:13:06 2015 -0700
> > # Node ID e3166b55525d48d0b69231d793ef2918046320e0
> > # Parent  a7527c5769bbe9e6a5afda9e615ad40e69665e9e
> > patch: add new diffopt filenameonly
> >
> > This series of patches adds a --filenameonly flag to hg diff --stat to only
> > display the filenames and omit the number of changes and summary line.
> >
> > I had the need for this feature trying to compute the list of files that changed
> > between two branches with:
> >
> > hg log -T {files % "{file}\\n"} -r 'only(r1,r2)'
> >  and having to pipe the result to sort, uniq to get the list of file that
> >  changed between the branches without duplicates
> >
> > hg diff -r r1 -r r2 --stat
> >  gave the right result but required parsing the output to eliminate the +,- and
> >  summary line
> >
> > This series solves this issues with a new flag that combines with --stat:
> >  hg diff -r r1 -r r2 --stat --filenameonly
> >
> 
> Isn't "hg status --rev r1 --rev r2" supposed to give the same result?

Nope. The diff format predates Mercurial by a few decades so it has
different ideas about the shape of the world that we can't perfectly
wedge Mercurial's worldview into. Renames, copies, exec bits, symlinks,
newline types, binary files, merges, deletions, empty files, etc. etc.
etc. Git diffs have similar problems that are not as severe, but still
present. Consider:

$ hg init a
$ cd a
$ touch a
$ hg ci -Am0
adding a
$ hg rm a
$ hg st
R a
$ hg diff
$

This counterintuitive result is actually correct, because the standard
diff format has no way to distinguish between empty and not-present
files.

The moral is still:

Diffs Cannot And Do Not And Are Not Intended To Reliably Represent
Mercurial's State

That said, hg status is probably the right answer to whatever the
question that lead to this was!

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list