comparison mercurial/commands.py @ 1582:63799b01985c

fix the cat command - improve localrepo.walk when passed a node - make the differents walk commands in commands.py accept a node - change commands.cat to walk over a revision - add a test
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Tue, 06 Dec 2005 14:10:38 +0100
parents 1d7d0c07e8f3
children 5c5aaaa9ab6f
comparison
equal deleted inserted replaced
1568:1d7d0c07e8f3 1582:63799b01985c
40 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] 40 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']]
41 cwd = '' 41 cwd = ''
42 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), 42 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'),
43 opts.get('exclude'), head) + (cwd,) 43 opts.get('exclude'), head) + (cwd,)
44 44
45 def makewalk(repo, pats, opts, head=''): 45 def makewalk(repo, pats, opts, node=None, head=''):
46 files, matchfn, anypats, cwd = matchpats(repo, pats, opts, head) 46 files, matchfn, anypats, cwd = matchpats(repo, pats, opts, head)
47 exact = dict(zip(files, files)) 47 exact = dict(zip(files, files))
48 def walk(): 48 def walk():
49 for src, fn in repo.walk(files=files, match=matchfn): 49 for src, fn in repo.walk(node=node, files=files, match=matchfn):
50 yield src, fn, util.pathto(cwd, fn), fn in exact 50 yield src, fn, util.pathto(cwd, fn), fn in exact
51 return files, matchfn, walk() 51 return files, matchfn, walk()
52 52
53 def walk(repo, pats, opts, head=''): 53 def walk(repo, pats, opts, node=None, head=''):
54 files, matchfn, results = makewalk(repo, pats, opts, head) 54 files, matchfn, results = makewalk(repo, pats, opts, node, head)
55 for r in results: 55 for r in results:
56 yield r 56 yield r
57 57
58 def walkchangerevs(ui, repo, pats, opts): 58 def walkchangerevs(ui, repo, pats, opts):
59 '''Iterate over files and the revs they changed in. 59 '''Iterate over files and the revs they changed in.
632 %p root-relative path name of file being printed 632 %p root-relative path name of file being printed
633 """ 633 """
634 mf = {} 634 mf = {}
635 rev = opts['rev'] 635 rev = opts['rev']
636 if rev: 636 if rev:
637 change = repo.changelog.read(repo.lookup(rev)) 637 node = repo.lookup(rev)
638 mf = repo.manifest.read(change[0]) 638 else:
639 for src, abs, rel, exact in walk(repo, (file1,) + pats, opts): 639 node = repo.changelog.tip()
640 change = repo.changelog.read(node)
641 mf = repo.manifest.read(change[0])
642 for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node):
640 r = repo.file(abs) 643 r = repo.file(abs)
641 if rev: 644 n = mf[abs]
642 try:
643 n = mf[abs]
644 except (hg.RepoError, KeyError):
645 try:
646 n = r.lookup(rev)
647 except KeyError, inst:
648 raise util.Abort(_('cannot find file %s in rev %s'), rel, rev)
649 else:
650 n = r.tip()
651 fp = make_file(repo, r, opts['output'], node=n, pathname=abs) 645 fp = make_file(repo, r, opts['output'], node=n, pathname=abs)
652 fp.write(r.read(n)) 646 fp.write(r.read(n))
653 647
654 def clone(ui, source, dest=None, **opts): 648 def clone(ui, source, dest=None, **opts):
655 """make a copy of an existing repository 649 """make a copy of an existing repository