-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcg-admin-cat
executable file
·58 lines (50 loc) · 1.23 KB
/
cg-admin-cat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
#
# Cat file(s) by filename from given tree or revision
# Copyright (c) John Ellson, 2005
#
# Cat a file of a given filename in a given revision (or in the current
# one) to stdout.
#
# OPTIONS
# -------
# -r TREE_ID:: Look for file in the given revision or tree
# ID of the revision or tree where to look for the file, instead of
# HEAD.
# Testsuite: TODO
# The tale of birth:
# 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-admin-cat [-r TREE_ID] FILE..."
_git_wc_unneeded=1
. "${COGITO_LIB}"cg-Xlib || exit 1
rev=HEAD
while optparse; do
if optparse -r=; then
rev="$OPTARG"
else
optfail
fi
done
[ ${#ARGS[*]} -ge 1 ] || usage
id=$(cg-object-id -t "$rev") || exit 1
git-ls-tree "$id" "${ARGS[@]}" |
while read -r mode type sha name
do
case "$type" in
blob)
git-cat-file blob "$sha"
;;
tree)
git-ls-tree "$sha"
;;
*)
exit 1
;;
esac
done