# HG changeset patch # User Mathias De Maré # Date 1422796171 -3600 # Node ID 07c1a7d1ef69ac335fc194cc5f97a7516e8aa4e9 # Parent a8dc5a3f4f4c2d7195a1ccf1712ef70e2080dc0e subrepo: add 'cat' support for git subrepos V2: use 'self._ctx.node()' instead of 'rev' in makefileobj. As Matt Harbison mentioned, using 'rev' does not make sense, since we'd be passing a git revision to the top-level Mercurial repository. diff -r a8dc5a3f4f4c -r 07c1a7d1ef69 mercurial/help/subrepos.txt --- a/mercurial/help/subrepos.txt Mon Feb 02 12:50:48 2015 -0600 +++ b/mercurial/help/subrepos.txt Sun Feb 01 14:09:31 2015 +0100 @@ -91,7 +91,7 @@ -S/--subrepos is specified. :cat: cat currently only handles exact file matches in subrepos. - Git and Subversion subrepositories are currently ignored. + Subversion subrepositories are currently ignored. :commit: commit creates a consistent snapshot of the state of the entire project and its subrepositories. If any subrepositories diff -r a8dc5a3f4f4c -r 07c1a7d1ef69 mercurial/subrepo.py --- a/mercurial/subrepo.py Mon Feb 02 12:50:48 2015 -0600 +++ b/mercurial/subrepo.py Sun Feb 01 14:09:31 2015 +0100 @@ -1577,6 +1577,25 @@ @annotatesubrepoerror + def cat(self, match, prefix, **opts): + rev = self._state[1] + if match.anypats(): + return 1 #No support for include/exclude yet + + if not match.files(): + return 1 + + for f in match.files(): + output = self._gitcommand(["show", "%s:%s" % (rev, f)]) + fp = cmdutil.makefileobj(self._subparent, opts.get('output'), + self._ctx.node(), + pathname=os.path.join(prefix, f)) + fp.write(output) + fp.close() + return 0 + + + @annotatesubrepoerror def status(self, rev2, **opts): rev1 = self._state[1] if self._gitmissing() or not rev1: diff -r a8dc5a3f4f4c -r 07c1a7d1ef69 tests/test-subrepo-git.t --- a/tests/test-subrepo-git.t Mon Feb 02 12:50:48 2015 -0600 +++ b/tests/test-subrepo-git.t Sun Feb 01 14:09:31 2015 +0100 @@ -802,4 +802,52 @@ $ hg status --subrepos ? s/barfoo +show file at specific revision + $ cat > s/foobar << EOF + > woop woop + > fooo bar + > EOF + $ hg commit --subrepos -m "updated foobar" + committing subrepository s + $ cat > s/foobar << EOF + > current foobar + > (should not be visible using hg cat) + > EOF + + $ hg cat -r . s/foobar + woop woop + fooo bar (no-eol) + $ hg cat -r "parents(.)" s/foobar > catparents + + $ mkdir -p tmp/s + + $ hg cat -r "parents(.)" --output tmp/%% s/foobar + $ diff tmp/% catparents + + $ hg cat -r "parents(.)" --output tmp/%s s/foobar + $ diff tmp/foobar catparents + + $ hg cat -r "parents(.)" --output tmp/%d/otherfoobar s/foobar + $ diff tmp/s/otherfoobar catparents + + $ hg cat -r "parents(.)" --output tmp/%p s/foobar + $ diff tmp/s/foobar catparents + + $ hg cat -r "parents(.)" --output tmp/%H s/foobar + $ diff tmp/255ee8cf690ec86e99b1e80147ea93ece117cd9d catparents + + $ hg cat -r "parents(.)" --output tmp/%R s/foobar + $ diff tmp/10 catparents + + $ hg cat -r "parents(.)" --output tmp/%h s/foobar + $ diff tmp/255ee8cf690e catparents + + $ rm tmp/10 + $ hg cat -r "parents(.)" --output tmp/%r s/foobar + $ diff tmp/10 catparents + + $ mkdir tmp/tc + $ hg cat -r "parents(.)" --output tmp/%b/foobar s/foobar + $ diff tmp/tc/foobar catparents + $ cd ..