Newbie question: equiv of: cvs co -p <filename> ?
How can we cat the latest committed state of a file to stdout?
I hacked this:
#!/bin/bash ID=`git-ls-files -s | grep $1 | cut -d ' ' -f 2` TMP=`git-unpack-file $ID` cat $TMP rm $TMP
but its really ugly! It must be easier than this?
John
Quoted 5 lines · John Ellson
I hacked this:
#!/bin/bash ID=`git-ls-files -s | grep $1 | cut -d ' ' -f 2`
No. "git-ls-files" shows the latest _index_ state, not the latest committed state.
Use "git-ls-tree HEAD pathname" to get the latest committed state for the pathname, and then pick out the SHA1 from there, use
git-cat-file blob <sha1>
to cat the result.
Of course, this will work with any revision, not just HEAD. So you could do something like
git-ls-tree $(git-rev-parse --default HEAD "$@") | while read mode type sha name do case "$type" in blob) git-cat-file blob "$sha" ;; tree) git-ls-tree "$sha" ;; *) exit 1 done
(totally untested)
Linus
PATCH 1/1 cg-cat [was: Re: Newbie question: equiv of: cvs co -p <filename> ? ]
Quoted 5 lines · Linus Torvalds
Quoted 1 line · John Ellson
I hacked this:
Quoted 7 lines
No. ...
So you could do something like ...
(totally untested)
Linus
Thanks Linus, also Rene and Johannes.
I applied a bit of polish and testing and now I'm ready to offer my first contribution to cogito.
cg-cat [-r rev] FILE
I hope that this is useful to others.
---
Makefile +1 -1
@@ -14,11 +14,11 @@ INSTALL?=install SCRIPT= commit-id tree-id parent-id cg-add cg-admin-lsobj cg-admin-uncommit \ cg-branch-add cg-branch-ls cg-reset cg-clone cg-commit cg-diff \ cg-export cg-help cg-init cg-log cg-merge cg-mkpatch cg-patch \ cg-pull cg-restore cg-rm cg-seek cg-status cg-tag cg-tag-ls cg-update \ - cg cg-admin-ls cg-push cg-branch-chg + cg cg-admin-ls cg-push cg-branch-chg cg-cat LIB_SCRIPT=cg-Xlib cg-Xmergefile cg-Xnormid GEN_SCRIPT= cg-version
cg-cat new file +42 -0
42 lines not on this page · raw message
Re: [PATCH] cg-cat [was: Re: Newbie question: equiv of: cvs co -p <filename> ? ]
Dear diary, on Wed, Aug 10, 2005 at 04:38:08PM CEST, I got a letter where John Ellson <[email protected]> told me that...
Quoted 15 lines
Quoted 5 lines · Linus Torvalds
Quoted 1 line · John Ellson
I hacked this:
Quoted 7 lines
No. ...
So you could do something like ...
(totally untested)
Linus
Quoted 8 lines
Thanks Linus, also Rene and Johannes.
I applied a bit of polish and testing and now I'm ready to offer my first contribution to cogito.
cg-cat [-r rev] FILE
I hope that this is useful to others.
Thanks, cleaned up and applied. I only renamed it to cg-admin-cat since I think it's indeed a bit obscure. Also, note the remarkable similarity:
cg-admin-cat [-r TREE_ID] FILE...
cg-admin-ls [-t TREE_ID] [PATH]
What about joining those to cg-admin-dig or something? (Catting a directory or ls'ing file contents just feels wrong, although the first one would make some sense to people not acquainted with UNIX.)
Signature · 4 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ If you want the holes in your knowledge showing up try teaching someone. -- Alan Cox
Re: [PATCH] cg-cat [was: Re: Newbie question: equiv of: cvs co -p <filename> ? ]
Quoted 2 lines · Petr Baudis
cg-admin-cat [-r
TREE_ID] FILE...
cg-admin-ls [-tTREE_ID] [PATH]
I don't know if these need to be merged, *but* please at least change one of the flag names so that the whole mess is slightly more consistent.
Signature · 6 lines
Matthias Urlichs | {M:U} IT Design @ m-u-it.de | [email protected]
Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de
- -
The thought of 2000 thousand people munching celery at the same time
horrifies me.
-- George Bernard ShawHi,
Quoted 6 lines · John Ellson
How can we cat the latest committed state of a file to stdout?
I hacked this:
#!/bin/bash ID=`git-ls-files -s | grep $1 | cut -d ' ' -f 2`
and now:
git-cat-file blob $ID
Voila,
Dscho
Quoted 5 lines · Johannes Schindelin
Quoted 4 lines · John Ellson
How can we cat the latest committed state of a file to stdout?
I hacked this:
Quoted 7 lines
Quoted 2 lines
#!/bin/bash ID=`git-ls-files -s | grep $1 | cut -d ' ' -f 2`and now:
git-cat-file blob $ID
Still not pretty. How about this?
#!/bin/sh git-ls-tree HEAD "$@" | while read mode type hash filename; do [ "$type" = "blob" ] && git-cat-file blob "$hash" done
Rene