@@ -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)
@@ -1125,7 +1125,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')),
@@ -1150,8 +1153,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()
@@ -1159,7 +1162,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',