2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
11 echo "${TG_RECURSIVE}tg: $*"
23 hook_call
="\"\$(tg --hooks-path)\"/$1 \"\$@\""
24 if [ -f "$git_dir/hooks/$1" ] &&
25 fgrep
-q "$hook_call" "$git_dir/hooks/$1"; then
26 # Another job well done!
30 if [ -x "$git_dir/hooks/$1" ]; then
31 hook_call
="$hook_call"' || exit $?'
33 hook_call
="exec $hook_call"
35 # Insert call into the hook
39 [ ! -s "$git_dir/hooks/$1" ] ||
cat "$git_dir/hooks/$1"
40 } >"$git_dir/hooks/$1+"
41 chmod a
+x
"$git_dir/hooks/$1+"
42 mv "$git_dir/hooks/$1+" "$git_dir/hooks/$1"
45 # setup_ours (no arguments)
48 if [ ! -s "$git_dir/info/gitattributes" ] ||
! grep -q topmsg
"$git_dir/info/gitattributes"; then
50 echo -e ".topmsg\tmerge=ours"
51 echo -e ".topdeps\tmerge=ours"
52 } >>"$git_dir/info/gitattributes"
54 if ! git config merge.ours.driver
>/dev
/null
; then
55 git config merge.ours.name
'"always keep ours" merge driver'
56 git config merge.ours.driver
'touch %A'
60 # measure_branch NAME [BASE]
63 _name
="$1"; _base
="$2"
64 [ -n "$_base" ] || _base
="refs/top-bases/$_name"
65 # The caller should've verified $name is valid
66 _commits
="$(git rev-list "$_name" ^"$_base" | wc -l)"
67 _nmcommits
="$(git rev-list --no-merges "$_name" ^"$_base" | wc -l)"
68 if [ $_commits -gt 1 ]; then
73 echo "$_commits/$_nmcommits $_suffix"
76 # branch_contains B1 B2
77 # Whether B1 is a superset of B2.
80 [ -z "$(git rev-list ^"$1" "$2")" ]
83 # needs_update NAME [BRANCHPATH...]
84 # This function is recursive; it outputs reverse path from NAME
85 # to the branch (e.g. B_DIRTY B1 B2 NAME), one path per line,
86 # inner paths first. Innermost name can be ':' if the head is
87 # not in sync with the base.
91 git cat-file blob
"$1:.topdeps" 2>/dev
/null |
94 git rev-parse
--verify "refs/top-bases/$_dep" >/dev
/null
2>&1 ||
97 # Shoo shoo, keep our environment alone!
98 [ -z "$_dep_is_tgish" ] ||
(needs_update
"$_dep" "$@")
101 if [ -n "$_dep_is_tgish" ]; then
102 branch_contains
"$_dep" "refs/top-bases/$_dep" || _dep_base_uptodate
=
105 if [ -z "$_dep_base_uptodate" ]; then
106 # _dep needs to be synced with its base
108 elif ! branch_contains
"refs/top-bases/$1" "$_dep"; then
109 # Some new commits in _dep
113 } ||
: # $1 is not tracked by TopGit anymore
119 [ -z "$(git diff-tree "refs
/top-bases
/$1" "$1" | fgrep -v " .top
")" ]
122 # switch_to_base NAME [SEED]
125 _base
="refs/top-bases/$1"; _seed
="$2"
126 # We have to do all the hard work ourselves :/
127 # This is like git checkout -b "$_base" "$_seed"
128 # (or just git checkout "$_base"),
129 # but does not create a detached HEAD.
130 git read-tree
-u -m HEAD
"${_seed:-$_base}"
131 [ -z "$_seed" ] || git update-ref
"$_base" "$_seed"
132 git symbolic-ref HEAD
"$_base"
139 git_dir
="$(git rev-parse --git-dir)"
140 root_dir
="$(git rev-parse --show-cdup)"; root_dir
="${root_dir:-.}"
141 # make sure merging the .top* files will always behave sanely
143 setup_hook
"pre-commit"
148 # We were sourced from another script for our utility functions;
149 # this is set by hooks.
150 [ -z "$tg__include" ] ||
return 0
153 [ -n "$cmd" ] || die
"He took a duck in the face at two hundred and fifty knots"
158 echo "TopGit v0.1 - A different patch queue manager"
159 echo "Usage: tg (create|delete|info|patch|summary|update|help) ..."
161 create|delete|info|
patch|summary|update
)
162 .
"@cmddir@"/tg-
$cmd;;
167 echo "Unknown subcommand: $cmd" >&2