Mercurial > hg
changeset 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 | b3e94785ab69 11d12bd6e1dc |
files | mercurial/commands.py mercurial/localrepo.py tests/test-cat tests/test-cat.out |
diffstat | 4 files changed, 43 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Thu Dec 01 10:51:45 2005 -0600 +++ b/mercurial/commands.py Tue Dec 06 14:10:38 2005 +0100 @@ -42,16 +42,16 @@ return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), opts.get('exclude'), head) + (cwd,) -def makewalk(repo, pats, opts, head=''): +def makewalk(repo, pats, opts, node=None, head=''): files, matchfn, anypats, cwd = matchpats(repo, pats, opts, head) exact = dict(zip(files, files)) def walk(): - for src, fn in repo.walk(files=files, match=matchfn): + for src, fn in repo.walk(node=node, files=files, match=matchfn): yield src, fn, util.pathto(cwd, fn), fn in exact return files, matchfn, walk() -def walk(repo, pats, opts, head=''): - files, matchfn, results = makewalk(repo, pats, opts, head) +def walk(repo, pats, opts, node=None, head=''): + files, matchfn, results = makewalk(repo, pats, opts, node, head) for r in results: yield r @@ -634,20 +634,14 @@ mf = {} rev = opts['rev'] if rev: - change = repo.changelog.read(repo.lookup(rev)) - mf = repo.manifest.read(change[0]) - for src, abs, rel, exact in walk(repo, (file1,) + pats, opts): + node = repo.lookup(rev) + else: + node = repo.changelog.tip() + change = repo.changelog.read(node) + mf = repo.manifest.read(change[0]) + for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): r = repo.file(abs) - if rev: - try: - n = mf[abs] - except (hg.RepoError, KeyError): - try: - n = r.lookup(rev) - except KeyError, inst: - raise util.Abort(_('cannot find file %s in rev %s'), rel, rev) - else: - n = r.tip() + n = mf[abs] fp = make_file(repo, r, opts['output'], node=n, pathname=abs) fp.write(r.read(n))
--- a/mercurial/localrepo.py Thu Dec 01 10:51:45 2005 -0600 +++ b/mercurial/localrepo.py Tue Dec 06 14:10:38 2005 +0100 @@ -462,8 +462,14 @@ def walk(self, node=None, files=[], match=util.always): if node: + fdict = dict.fromkeys(files) for fn in self.manifest.read(self.changelog.read(node)[0]): - if match(fn): yield 'm', fn + fdict.pop(fn, None) + if match(fn): + yield 'm', fn + for fn in fdict: + self.ui.warn(_('%s: No such file in rev %s\n') % ( + util.pathto(self.getcwd(), fn), short(node))) else: for src, fn in self.dirstate.walk(files, match): yield src, fn
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-cat Tue Dec 06 14:10:38 2005 +0100 @@ -0,0 +1,18 @@ +#!/bin/sh +# +mkdir t +cd t +hg init +echo 0 > a +echo 0 > b +hg ci -A -m m -d "0 0" +hg rm a +hg cat a +sleep 1 # make sure mtime is changed +echo 1 > b +hg ci -m m -d "0 0" +echo 2 > b +hg cat -r 0 a +hg cat -r 0 b +hg cat -r 1 a +hg cat -r 1 b