[PATCH -V2] cat: added --follow flag (issue3253)
Iulian Stana
julian.stana at gmail.com
Fri Aug 2 10:01:58 UTC 2013
# HG changeset patch
# User Iulian Stana <julian.stana at 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.
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',
More information about the Mercurial-devel
mailing list