* Newbie question: equiv of: cvs co -p <filename> ?
@ 2005-08-09 21:59 John Ellson
2005-08-09 22:10 ` Johannes Schindelin
2005-08-10 0:36 ` Linus Torvalds
0 siblings, 2 replies; 7+ messages in thread
From: John Ellson @ 2005-08-09 21:59 UTC (permalink / raw)
To: git
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question: equiv of: cvs co -p <filename> ?
2005-08-09 21:59 Newbie question: equiv of: cvs co -p <filename> ? John Ellson
@ 2005-08-09 22:10 ` Johannes Schindelin
2005-08-09 22:18 ` Rene Scharfe
2005-08-10 0:36 ` Linus Torvalds
1 sibling, 1 reply; 7+ messages in thread
From: Johannes Schindelin @ 2005-08-09 22:10 UTC (permalink / raw)
To: John Ellson; +Cc: git
Hi,
On Tue, 9 Aug 2005, John Ellson wrote:
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question: equiv of: cvs co -p <filename> ?
2005-08-09 22:10 ` Johannes Schindelin
@ 2005-08-09 22:18 ` Rene Scharfe
0 siblings, 0 replies; 7+ messages in thread
From: Rene Scharfe @ 2005-08-09 22:18 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: John Ellson, git
Johannes Schindelin wrote:
> On Tue, 9 Aug 2005, John Ellson wrote:
>>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
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question: equiv of: cvs co -p <filename> ?
2005-08-09 21:59 Newbie question: equiv of: cvs co -p <filename> ? John Ellson
2005-08-09 22:10 ` Johannes Schindelin
@ 2005-08-10 0:36 ` Linus Torvalds
2005-08-10 14:38 ` [PATCH] cg-cat [was: Re: Newbie question: equiv of: cvs co -p <filename> ? ] John Ellson
1 sibling, 1 reply; 7+ messages in thread
From: Linus Torvalds @ 2005-08-10 0:36 UTC (permalink / raw)
To: John Ellson; +Cc: git
On Tue, 9 Aug 2005, John Ellson wrote:
>
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] cg-cat [was: Re: Newbie question: equiv of: cvs co -p <filename> ? ]
2005-08-10 0:36 ` Linus Torvalds
@ 2005-08-10 14:38 ` John Ellson
2005-08-11 23:03 ` Petr Baudis
0 siblings, 1 reply; 7+ messages in thread
From: John Ellson @ 2005-08-10 14:38 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 431 bytes --]
Linus Torvalds wrote:
>
> On Tue, 9 Aug 2005, John Ellson wrote:
>
>>I hacked this:
> 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.
Signed-off-by: John Ellson <ellson@research.att.com>
---
[-- Attachment #2: patch0.patch --]
[-- Type: text/x-patch, Size: 1549 bytes --]
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/cg-cat b/cg-cat
new file mode 100755
--- /dev/null
+++ b/cg-cat
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# Cat a file(s) by filename from a GIT repository.
+
+# Initiated from a request from: erg@research.att.com
+# for an equivalent to "cvs co -p <filename>"
+# Question posted with really bad initial solution: ellson@research.att.com
+# Suggestions offered by: Johannes.Schindelin@gmx.de
+# rene.scharfe@lsrfire.ath.cx
+# This solution based on posting from: torvalds@osdl.org
+# Polish and test by: ellson@research.att.com
+
+USAGE="cg-cat [-r rev] FILE"
+
+. ${COGITO_LIB}cg-Xlib
+
+default=HEAD
+while optparse; do
+ if optparse -r; then
+ default="$OPTARG"
+ else
+ optfail
+ fi
+done
+
+[ "$ARGS" ] || usage
+
+git-ls-tree $(git-rev-parse --default $default "${ARGS[@]}") |
+ while read mode type sha name
+ do
+ case "$type" in
+ blob)
+ git-cat-file blob "$sha"
+ ;;
+ tree)
+ git-ls-tree "$sha"
+ ;;
+ *)
+ exit 1
+ ;;
+ esac
+ done
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] cg-cat [was: Re: Newbie question: equiv of: cvs co -p <filename> ? ]
2005-08-10 14:38 ` [PATCH] cg-cat [was: Re: Newbie question: equiv of: cvs co -p <filename> ? ] John Ellson
@ 2005-08-11 23:03 ` Petr Baudis
2005-08-12 7:53 ` Matthias Urlichs
0 siblings, 1 reply; 7+ messages in thread
From: Petr Baudis @ 2005-08-11 23:03 UTC (permalink / raw)
To: John Ellson; +Cc: Linus Torvalds, git
Dear diary, on Wed, Aug 10, 2005 at 04:38:08PM CEST, I got a letter
where John Ellson <ellson@research.att.com> told me that...
> Linus Torvalds wrote:
> >
> >On Tue, 9 Aug 2005, John Ellson wrote:
> >
> >>I hacked this:
>
> >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.
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.)
--
Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
If you want the holes in your knowledge showing up try teaching
someone. -- Alan Cox
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] cg-cat [was: Re: Newbie question: equiv of: cvs co -p <filename> ? ]
2005-08-11 23:03 ` Petr Baudis
@ 2005-08-12 7:53 ` Matthias Urlichs
0 siblings, 0 replies; 7+ messages in thread
From: Matthias Urlichs @ 2005-08-12 7:53 UTC (permalink / raw)
To: git
Hi, Petr Baudis wrote:
> cg-admin-cat [-r TREE_ID] FILE...
> cg-admin-ls [-t TREE_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.
--
Matthias Urlichs | {M:U} IT Design @ m-u-it.de | smurf@smurf.noris.de
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 Shaw
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-08-12 7:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-09 21:59 Newbie question: equiv of: cvs co -p <filename> ? John Ellson
2005-08-09 22:10 ` Johannes Schindelin
2005-08-09 22:18 ` Rene Scharfe
2005-08-10 0:36 ` Linus Torvalds
2005-08-10 14:38 ` [PATCH] cg-cat [was: Re: Newbie question: equiv of: cvs co -p <filename> ? ] John Ellson
2005-08-11 23:03 ` Petr Baudis
2005-08-12 7:53 ` Matthias Urlichs
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).