Patchwork [-V2] cat: added --follow flag (issue3253)

login
register
mail settings
Submitter Iulian Stana
Date Aug. 2, 2013, 10:01 a.m.
Message ID <c958bf44ad0aa12d9d14.1375437718@doppler>
Download mbox | patch
Permalink /patch/1981/
State Rejected
Headers show

Comments

Iulian Stana - Aug. 2, 2013, 10:01 a.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1373125686 -10800
#      Sat Jul 06 18:48:06 2013 +0300
# Node ID c958bf44ad0aa12d9d1495d1453bbbd5ebb6c8d0
# Parent  a58251c0568fc5e86089a803ca75f75cc8c01678
cat: added --follow flag (issue3253)

Adding -f (follow) option to the cat command. Adding the possibility to 'cat' a
file that was renamed.
If you choose -f option you must specify a file from the parent revision.
Giovanni Gherdovich - Aug. 5, 2013, 5:44 a.m.
:::: which I'm guessing is what Matt meant when he [...]
:::: closed the bug as WONTFIX.

Woooops.

Thanks Kevin for having done the extra mile and checked the bz.

I encouraged Iulian to re-send the patch after the first remark
from Matt, and didn't actually bothered to check the bz...

Iulian: when a bug's status is set as WONTFIX, it means
that it is *closed* and "WON'T be FIXed".
There is no point in sending patches for it.

Next time for a quick check of a bug's status, just go
on #mercurial and type something like

<ggherdov> !bug 3253
<hgbot> Bug http://bz.selenic.com/show_bug.cgi?id=3253 RESOLVED WONTFIX,
"hg cat -r [rev]" doesn't work with renamed files

or, go and check in the bz.

Cheers,
Giovanni
Iulian Stana - Aug. 5, 2013, 11:57 a.m.
2013/8/5 Giovanni Gherdovich <g.gherdovich@gmail.com>

> :::: which I'm guessing is what Matt meant when he [...]
> :::: closed the bug as WONTFIX.
>
> Woooops.
>
> Thanks Kevin for having done the extra mile and checked the bz.
>
> I encouraged Iulian to re-send the patch after the first remark
> from Matt, and didn't actually bothered to check the bz...
>

Woops, for me too, I haven't checked the bug status before re-sending it.


Iulian: when a bug's status is set as WONTFIX, it means
> that it is *closed* and "WON'T be FIXed".
> There is no point in sending patches for it.
>
> Next time for a quick check of a bug's status, just go
> on #mercurial and type something like
>
> <ggherdov> !bug 3253
> <hgbot> Bug http://bz.selenic.com/show_bug.cgi?id=3253 RESOLVED WONTFIX,
> "hg cat -r [rev]" doesn't work with renamed files
>

Nice to know.


> or, go and check in the bz.
>
> Cheers,
> Giovanni
>

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1008,7 +1008,7 @@ 
 class FileWalkError(Exception):
     pass
 
-def walkfilerevs(repo, match, follow, revs, fncache):
+def walkfilerevs(repo, match, follow, revs, fncache, filename=False):
     '''Walks the file history for the matched files.
 
     Returns the changeset revs that are involved in the file history.
@@ -1100,7 +1100,10 @@ 
                     ancestors.update(flparentlinkrevs)
 
             fncache.setdefault(rev, []).append(file_)
-            wanted.add(rev)
+            if filename:
+                wanted.add((rev, file_))
+            else:
+                wanted.add(rev)
             if copied:
                 copies.append(copied)
 
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1128,7 +1128,10 @@ 
     changegroup.writebundle(cg, fname, bundletype)
 
 @command('cat',
-    [('o', 'output', '',
+    [('f', 'follow', None,
+    _('follow changeset history,'
+    ' or file history across copies and renames')),
+    ('o', 'output', '',
      _('print output to file with formatted name'), _('FORMAT')),
     ('r', 'rev', '', _('print the given revision'), _('REV')),
     ('', 'decode', None, _('apply any matching decode filter')),
@@ -1152,8 +1155,8 @@ 
     """
     ctx = scmutil.revsingle(repo, opts.get('rev'))
     err = 1
-    m = scmutil.match(ctx, (file1,) + pats, opts)
-    for abs in ctx.walk(m):
+
+    def writedata(abs):
         fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
                                  pathname=abs)
         data = ctx[abs].data()
@@ -1161,7 +1164,23 @@ 
             data = repo.wwritedata(abs, data)
         fp.write(data)
         fp.close()
-        err = 0
+        return 0
+
+    if opts.get('follow'):
+        m = scmutil.match(repo[None], (file1,) + pats, opts)
+        wanted = cmdutil.walkfilerevs(repo, m, True, [0], {}, filename=True)
+        revs = [rev for rev, file in wanted]
+        try:
+            position = revs.index(int(opts.get('rev')))
+            file = list(wanted)[position][1]
+            print ("%s was %s:") % (file1, file)
+            err = writedata(file)
+        except:
+            print ('%s has no ancestor in rev %s') % (file1, ctx)
+    else:
+        m = scmutil.match(ctx, (file1,) + pats, opts)
+        for abs in ctx.walk(m):
+            err = writedata(abs)
     return err
 
 @command('^clone',