forked from cms-sw/cms-git-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-cms-sparse-checkout
executable file
·100 lines (94 loc) · 2.85 KB
/
git-cms-sparse-checkout
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh -e
# Includes in .git/info/sparse-checkout a list of the packages
# which are modified between TAG1 and TAG2
case `uname` in
Darwin) ECHO=echo ;;
*) ECHO="echo -e" ;;
esac
usage () {
echo "git cms-sparse-checkout [options] TAG1 TAG2"
echo
echo "Options:"
$ECHO "-h \tthis help message"
$ECHO
$ECHO "-d, --debug \tenable debug output"
$ECHO "-z, --quiet \tdo not print out progress"
exit $1
}
NORMAL_STREAM=/dev/stdout
VERBOSE_STREAM=/dev/stdout
DEBUG_STREAM=/dev/null
verbose () {
if [ "X$VERBOSE" = X1 ]; then
echo "$@"
fi
}
REF1=
REF2=
while [ "$#" != 0 ]; do
case "$1" in
-h | --help )
usage 0;;
-v|--verbose)
NORMAL_STREAM=/dev/stdout
VERBOSE_STREAM=/dev/stdout
DEBUG_STREAM=/dev/null
shift
;;
-q|--quiet)
NORMAL_STREAM=/dev/null
VERBOSE_STREAM=/dev/null
DEBUG_STREAM=/dev/null
shift
;;
-d|--debug)
NORMAL_STREAM=/dev/stdout
VERBOSE_STREAM=/dev/stdout
DEBUG_STREAM=/dev/stdout
set -x
shift
;;
--exclude-cvs-keywords)
REGEX='^([^$]+$|[^$]*[$][^$]*$|([^$]*[$])($|[^RAIDLNSH]|(R[^eC]|A[^u]|I[^d]|D[^a]|L[^o]|N[^a]|S[^o]|H[^e])|(Re[^v]|RC[^S]|Au[^t]|Id[^:]|Da[^t]|Lo[^g]|Na[^m]|So[^u]|He[^a])|(Rev[^i]|RCS[^f]|Aut[^h]|Dat[^e]|Log[^:]|Nam[^e]|Sou[^r]|Hea[^d])|(Revi[^s]|RCSf[^i]|Auth[^o]|Date[^:]|Name[^:]|Sour[^c]|Head[^e])|(Revis[^i]|RCSfi[^l]|Autho[^r]|Sourc[^e]|Heade[^r])|(Revisi[^o]|RCSfil[^e]|Author[^:]|Source[^:]|Header[^:])|(Revisio[^n]|RCSfile[^:])|(Revision[^:])))'
REGEX_OPT="-G"
shift
;;
-G)
REGEX_OPT="-G"
REGEX="$2"; shift ; shift
;;
-*)
echo Unknown option $1 ; usage 1 ;;
*)
if [ "X$REF1" = X ]; then
REF1=$1
elif [ "X$CMSSW_TAG" = X ]; then
REF2=$1
else
echo "Too many tags / branches specified." ; exit 1
fi
shift 1
;;
esac
done
case `git --version` in
git\ version\ 1.7*)
# git 1.7.x does not support a leading slash in /gitignore and .git/info/sparse-checkout
LEADING_SLASH=
;;
*)
LEADING_SLASH=/
;;
esac
git config core.sparsecheckout true
INFO_DIR=`git rev-parse --show-toplevel`/.git/info/
touch $INFO_DIR/sparse-checkout
cp -f $INFO_DIR/sparse-checkout $INFO_DIR/sparse-checkout-new
for x in `git diff $REGEX_OPT $REGEX $REF1..$REF2 --name-only | grep -v ".gitconfig" | cut -f1,2 -d/ | sort -u`; do
echo "$x" | sed -e "s|[/]*$|/|;s|^/*|${LEADING_SLASH}|" >> $INFO_DIR/sparse-checkout-new
done
for x in `git diff $REF1..$REF2 | grep '^old mode' -C 1 | grep '^diff --git' | sed -e 's|.* ||;s|b/||' | grep -v ".gitconfig" | cut -f1,2 -d/ | sort -u`; do
echo "$x" | sed -e "s|[/]*$|/|;s|^/*|${LEADING_SLASH}|" >> $INFO_DIR/sparse-checkout-new
done
cat $INFO_DIR/sparse-checkout-new | sort -u > $INFO_DIR/sparse-checkout
rm -f $INFO_DIR/sparse-checkout-new