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 fgrep
-q "$hook_call" "$git_dir/hooks/$1"; then
25 # Another job well done!
29 if [ -x "$git_dir/hooks/$1" ]; then
30 hook_call
="$hook_call"' || exit $?'
32 hook_call
="exec $hook_call"
34 # Insert call into the hook
38 cat "$git_dir/hooks/$1"
39 } >"$git_dir/hooks/$1+"
40 chmod a
+x
"$git_dir/hooks/$1+"
41 mv "$git_dir/hooks/$1+" "$git_dir/hooks/$1"
44 # setup_ours (no arguments)
47 if [ ! -s "$git_dir/info/gitattributes" ] ||
! grep -q topmsg
"$git_dir/info/gitattributes"; then
49 echo -e ".topmsg\tmerge=ours"
50 echo -e ".topdeps\tmerge=ours"
51 } >>"$git_dir/info/gitattributes"
53 if ! git config merge.ours.driver
>/dev
/null
; then
54 git config merge.ours.name
'"always keep ours" merge driver'
55 git config merge.ours.driver
'touch %A'
59 # measure_branch NAME [BASE]
62 _name
="$1"; _base
="$2"
63 [ -n "$_base" ] || _base
="refs/top-bases/$_name"
64 # The caller should've verified $name is valid
65 _commits
="$(git rev-list "$_name" ^"$_base" | wc -l)"
66 _nmcommits
="$(git rev-list --no-merges "$_name" ^"$_base" | wc -l)"
67 if [ $_commits -gt 1 ]; then
72 echo "$_commits/$_nmcommits $_suffix"
75 # branch_contains B1 B2
76 # Whether B1 is a superset of B2.
79 [ -z "$(git rev-list ^"$1" "$2")" ]
82 # needs_update NAME [BRANCHPATH...]
83 # This function is recursive; it outputs reverse path from NAME
84 # to the branch (e.g. B_DIRTY B1 B2 NAME), one path per line,
85 # inner paths first. Innermost name can be ':' if the head is
86 # not in sync with the base.
90 git cat-file blob
"$1:.topdeps" 2>/dev
/null |
93 git rev-parse
--verify "refs/top-bases/$_dep" >/dev
/null
2>&1 ||
96 # Shoo shoo, keep our environment alone!
97 [ -z "$_dep_is_tgish" ] ||
(needs_update
"$_dep" "$@")
100 if [ -n "$_dep_is_tgish" ]; then
101 branch_contains
"$_dep" "refs/top-bases/$_dep" || _dep_base_uptodate
=
104 if [ -z "$_dep_base_uptodate" ]; then
105 # _dep needs to be synced with its base
107 elif ! branch_contains
"refs/top-bases/$1" "$_dep"; then
108 # Some new commits in _dep
112 } ||
: # $1 is not tracked by TopGit anymore
118 [ -z "$(git diff-tree "refs
/top-bases
/$1" "$1" | fgrep -v " .top
")" ]
121 # switch_to_base NAME [SEED]
124 _base
="refs/top-bases/$1"; _seed
="$2"
125 # We have to do all the hard work ourselves :/
126 # This is like git checkout -b "$_base" "$_seed"
127 # (or just git checkout "$_base"),
128 # but does not create a detached HEAD.
129 git read-tree
-u -m HEAD
"${_seed:-$_base}"
130 [ -z "$_seed" ] || git update-ref
"$_base" "$_seed"
131 git symbolic-ref HEAD
"$_base"
138 git_dir
="$(git rev-parse --git-dir)"
139 root_dir
="$(git rev-parse --show-cdup)"; root_dir
="${root_dir:-.}"
140 # make sure merging the .top* files will always behave sanely
142 setup_hook
"pre-commit"
147 # We were sourced from another script for our utility functions;
148 # this is set by hooks.
149 [ -z "$tg__include" ] ||
return 0
152 [ -n "$cmd" ] || die
"He took a duck in the face at two hundred and fifty knots"
157 echo "TopGit v0.1 - A different patch queue manager"
158 echo "Usage: tg (create|delete|info|patch|summary|update|help) ..."
160 create|delete|info|
patch|summary|update
)
161 .
"@cmddir@"/tg-
$cmd;;
166 echo "Unknown subcommand: $cmd" >&2