tg-revert.sh: convert any top-bases in TOPGIT REFS
[topgit/pro.git] / tg.sh
blob8fdd8c78728eb254359ff65dae4fae138a9684af
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # Copyright (C) Petr Baudis <pasky@suse.cz> 2008
4 # Copyright (C) Kyle J. McKay <mackyle@gmail.com> 2014,2015,2016
5 # All rights reserved.
6 # GPLv2
8 TG_VERSION=0.19.4
10 # Update in Makefile if you add any code that requires a newer version of git
11 GIT_MINIMUM_VERSION="@mingitver@"
13 ## SHA-1 pattern
15 octet='[0-9a-f][0-9a-f]'
16 octet4="$octet$octet$octet$octet"
17 octet19="$octet4$octet4$octet4$octet4$octet$octet$octet"
18 octet20="$octet4$octet4$octet4$octet4$octet4"
19 nullsha="0000000000000000000000000000000000000000"
21 ## Auxiliary functions
23 # Preserves current $? value while triggering a non-zero set -e exit if active
24 # This works even for shells that sometimes fail to correctly trigger a -e exit
25 check_exit_code()
27 return $?
30 # This is the POSIX equivalent of which
31 cmd_path()
33 { "unset" -f command unset unalias "$1"; } >/dev/null 2>&1 || :
34 { "unalias" -a; } >/dev/null 2>&1 || :
35 command -v "$1"
38 # Output arguments without any possible interpretation
39 # (Avoid misinterpretation of '\' characters or leading "-n", "-E" or "-e")
40 echol()
42 printf '%s\n' "$*"
45 info()
47 echol "${TG_RECURSIVE}${tgname:-tg}: $*"
50 warn()
52 info "warning: $*" >&2
55 err()
57 info "error: $*" >&2
60 die()
62 info "fatal: $*" >&2
63 exit 1
66 vcmp()
68 # Compare $1 to $3 each of which must match ^[^0-9]*\d*(\.\d*)*.*$
69 # where only the "\d*" parts in the regex participate in the comparison
70 # Since EVERY string matches that regex this function is easy to use
71 # An empty string ('') for $1 or $3 or any "\d*" part is treated as 0
72 # $2 is a compare op '<', '<=', '=', '==', '!=', '>=', '>'
73 # Return code is 0 for true, 1 for false (or unknown compare op)
74 # There is NO difference in behavior between '=' and '=='
75 # Note that "vcmp 1.8 == 1.8.0.0.0.0" correctly returns 0
76 set -- "$1" "$2" "$3" "${1%%[0-9]*}" "${3%%[0-9]*}"
77 set -- "${1#"$4"}" "$2" "${3#"$5"}"
78 set -- "${1%%[!0-9.]*}" "$2" "${3%%[!0-9.]*}"
79 while
80 vcmp_a_="${1%%.*}"
81 vcmp_b_="${3%%.*}"
82 [ "z$vcmp_a_" != "z" -o "z$vcmp_b_" != "z" ]
84 if [ "${vcmp_a_:-0}" -lt "${vcmp_b_:-0}" ]; then
85 unset vcmp_a_ vcmp_b_
86 case "$2" in "<"|"<="|"!=") return 0; esac
87 return 1
88 elif [ "${vcmp_a_:-0}" -gt "${vcmp_b_:-0}" ]; then
89 unset vcmp_a_ vcmp_b_
90 case "$2" in ">"|">="|"!=") return 0; esac
91 return 1;
93 vcmp_a_="${1#$vcmp_a_}"
94 vcmp_b_="${3#$vcmp_b_}"
95 set -- "${vcmp_a_#.}" "$2" "${vcmp_b_#.}"
96 done
97 unset vcmp_a_ vcmp_b_
98 case "$2" in "="|"=="|"<="|">=") return 0; esac
99 return 1
102 precheck() {
103 if ! git_version="$(git version)"; then
104 die "'git version' failed"
106 case "$git_version" in [Gg]"it version "*);;*)
107 die "'git version' output does not start with 'git version '"
108 esac
110 vcmp "$git_version" '>=' "$GIT_MINIMUM_VERSION" ||
111 die "git version >= $GIT_MINIMUM_VERSION required but found $git_version instead"
114 case "$1" in version|--version|-V)
115 echo "TopGit version $TG_VERSION"
116 exit 0
117 esac
119 precheck
120 [ "$1" = "precheck" ] && exit 0
123 cat_depsmsg_internal()
125 _rev="$(ref_exists_rev "refs/heads/$1")" || return 0
126 if [ -s "$tg_cache_dir/$1/.$2" ]; then
127 if read _rev_match && [ "$_rev" = "$_rev_match" ]; then
128 _line=
129 while IFS= read -r _line || [ -n "$_line" ]; do
130 printf '%s\n' "$_line"
131 done
132 return 0
133 fi <"$tg_cache_dir/$1/.$2"
135 [ -d "$tg_cache_dir/$1" ] || mkdir -p "$tg_cache_dir/$1" 2>/dev/null || :
136 if [ -d "$tg_cache_dir/$1" ]; then
137 printf '%s\n' "$_rev" >"$tg_cache_dir/$1/.$2"
138 _line=
139 git cat-file blob "$_rev:.$2" 2>/dev/null |
140 while IFS= read -r _line || [ -n "$_line" ]; do
141 printf '%s\n' "$_line" >&3
142 printf '%s\n' "$_line"
143 done 3>>"$tg_cache_dir/$1/.$2"
144 else
145 git cat-file blob "$_rev:.$2" 2>/dev/null
149 # cat_deps BRANCHNAME
150 # Caches result
151 cat_deps()
153 cat_depsmsg_internal "$1" topdeps
156 # cat_msg BRANCHNAME
157 # Caches result
158 cat_msg()
160 cat_depsmsg_internal "$1" topmsg
163 # cat_file TOPIC:PATH [FROM]
164 # cat the file PATH from branch TOPIC when FROM is empty.
165 # FROM can be -i or -w, than the file will be from the index or worktree,
166 # respectively. The caller should than ensure that HEAD is TOPIC, to make sense.
167 cat_file()
169 path="$1"
170 case "$2" in
172 cat "$root_dir/${path#*:}"
175 # ':file' means cat from index
176 git cat-file blob ":${path#*:}"
179 case "$path" in
180 refs/heads/*:.topdeps)
181 _temp="${path%:.topdeps}"
182 cat_deps "${_temp#refs/heads/}"
184 refs/heads/*:.topmsg)
185 _temp="${path%:.topmsg}"
186 cat_msg "${_temp#refs/heads/}"
189 git cat-file blob "$path"
191 esac
194 die "Wrong argument to cat_file: '$2'"
196 esac
199 # get tree for the committed topic
200 get_tree_()
202 echo "refs/heads/$1"
205 # get tree for the base
206 get_tree_b()
208 echo "refs/$topbases/$1"
211 # get tree for the index
212 get_tree_i()
214 git write-tree
217 # get tree for the worktree
218 get_tree_w()
220 i_tree=$(git write-tree)
222 # the file for --index-output needs to sit next to the
223 # current index file
224 cd "$root_dir"
225 : ${GIT_INDEX_FILE:="$git_dir/index"}
226 TMP_INDEX="$(mktemp "${GIT_INDEX_FILE}-tg.XXXXXX")"
227 git read-tree -m $i_tree --index-output="$TMP_INDEX" &&
228 GIT_INDEX_FILE="$TMP_INDEX" &&
229 export GIT_INDEX_FILE &&
230 git diff --name-only -z HEAD |
231 git update-index -z --add --remove --stdin &&
232 git write-tree &&
233 rm -f "$TMP_INDEX"
237 # strip_ref "$(git symbolic-ref HEAD)"
238 # Output will have a leading refs/heads/ or refs/$topbases/ stripped if present
239 strip_ref()
241 case "$1" in
242 refs/heads/*)
243 echol "${1#refs/heads/}"
245 refs/"$topbases"/*)
246 echol "${1#refs/$topbases/}"
249 echol "$1"
250 esac
253 # pretty_tree NAME [-b | -i | -w]
254 # Output tree ID of a cleaned-up tree without tg's artifacts.
255 # NAME will be ignored for -i and -w, but needs to be present
256 pretty_tree()
258 name=$1
259 source=${2#?}
260 git ls-tree --full-tree "$(get_tree_$source "$name")" |
261 LC_ALL=C sed -ne '/ \.top.*$/!p' |
262 git mktree
265 # return an empty-tree root commit -- date is either passed in or current
266 # If passed in "$*" must be epochsecs followed by optional hhmm offset (+0000 default)
267 # An invalid secs causes the current date to be used, an invalid zone offset
268 # causes +0000 to be used
269 make_empty_commit()
271 # the empty tree is guaranteed to always be there even in a repo with
272 # zero objects, but for completeness we force it to exist as a real object
273 SECS=
274 read -r SECS ZONE JUNK <<-EOT || :
277 case "$SECS" in *[!0-9]*) SECS=; esac
278 if [ -z "$SECS" ]; then
279 MTDATE="$(date '+%s %z')"
280 else
281 case "$ZONE" in
282 -[01][0-9][0-5][0-9]|+[01][0-9][0-5][0-9])
284 [01][0-9][0-5][0-9])
285 ZONE="+$ZONE"
288 ZONE="+0000"
289 esac
290 MTDATE="$SECS $ZONE"
292 EMPTYID="- <-> $MTDATE"
293 EMPTYTREE="$(git hash-object -t tree -w --stdin < /dev/null)"
294 printf '%s\n' "tree $EMPTYTREE" "author $EMPTYID" "committer $EMPTYID" '' |
295 git hash-object -t commit -w --stdin
298 # setup_hook NAME
299 setup_hook()
301 tgname="$(basename "$0")"
302 hook_call="\"\$(\"$tgname\" --hooks-path)\"/$1 \"\$@\""
303 if [ -f "$git_dir/hooks/$1" ] && fgrep -q "$hook_call" "$git_dir/hooks/$1"; then
304 # Another job well done!
305 return
307 # Prepare incantation
308 hook_chain=
309 if [ -s "$git_dir/hooks/$1" -a -x "$git_dir/hooks/$1" ]; then
310 hook_call="$hook_call"' || exit $?'
311 if ! LC_ALL=C sed -n 1p <"$git_dir/hooks/$1" | LC_ALL=C fgrep -qx "#!@SHELL_PATH@"; then
312 chain_num=
313 while [ -e "$git_dir/hooks/$1-chain$chain_num" ]; do
314 chain_num=$(( $chain_num + 1 ))
315 done
316 cp -p "$git_dir/hooks/$1" "$git_dir/hooks/$1-chain$chain_num"
317 hook_chain=1
319 else
320 hook_call="exec $hook_call"
322 # Don't call hook if tg is not installed
323 hook_call="if command -v \"$tgname\" >/dev/null 2>&1; then $hook_call; fi"
324 # Insert call into the hook
326 echol "#!@SHELL_PATH@"
327 echol "$hook_call"
328 if [ -n "$hook_chain" ]; then
329 echol "exec \"\$0-chain$chain_num\" \"\$@\""
330 else
331 [ ! -s "$git_dir/hooks/$1" ] || cat "$git_dir/hooks/$1"
333 } >"$git_dir/hooks/$1+"
334 chmod a+x "$git_dir/hooks/$1+"
335 mv "$git_dir/hooks/$1+" "$git_dir/hooks/$1"
338 # setup_ours (no arguments)
339 setup_ours()
341 if [ ! -s "$git_dir/info/attributes" ] || ! grep -q topmsg "$git_dir/info/attributes"; then
342 [ -d "$git_dir/info" ] || mkdir "$git_dir/info"
344 echo ".topmsg merge=ours"
345 echo ".topdeps merge=ours"
346 } >>"$git_dir/info/attributes"
348 if ! git config merge.ours.driver >/dev/null; then
349 git config merge.ours.name '"always keep ours" merge driver'
350 git config merge.ours.driver 'touch %A'
354 # measure_branch NAME [BASE] [EXTRAHEAD...]
355 measure_branch()
357 _bname="$1"; _base="$2"
358 shift; shift
359 [ -n "$_base" ] || _base="refs/$topbases/$(strip_ref "$_bname")"
360 # The caller should've verified $name is valid
361 _commits="$(git rev-list --count "$_bname" "$@" ^"$_base" --)"
362 _nmcommits="$(git rev-list --count --no-merges "$_bname" "$@" ^"$_base" --)"
363 if [ $_commits -ne 1 ]; then
364 _suffix="commits"
365 else
366 _suffix="commit"
368 echo "$_commits/$_nmcommits $_suffix"
371 # branch_contains B1 B2
372 # Whether B1 is a superset of B2.
373 branch_contains()
375 _revb1="$(ref_exists_rev "$1")" || return 0
376 _revb2="$(ref_exists_rev "$2")" || return 0
377 if [ -s "$tg_cache_dir/$1/.bc/$2/.d" ]; then
378 if read _result _rev_matchb1 _rev_matchb2 &&
379 [ "$_revb1" = "$_rev_matchb1" -a "$_revb2" = "$_rev_matchb2" ]; then
380 return $_result
381 fi <"$tg_cache_dir/$1/.bc/$2/.d"
383 [ -d "$tg_cache_dir/$1/.bc/$2" ] || mkdir -p "$tg_cache_dir/$1/.bc/$2" 2>/dev/null || :
384 _result=0
385 [ -z "$(git rev-list --max-count=1 ^"$_revb1" "$_revb2" --)" ] || _result=$?
386 if [ -d "$tg_cache_dir/$1/.bc/$2" ]; then
387 echo "$_result" "$_revb1" "$_revb2" >"$tg_cache_dir/$1/.bc/$2/.d"
389 return $_result
392 create_ref_dirs()
394 [ ! -s "$tg_tmp_dir/tg~ref-dirs-created" -a -s "$tg_ref_cache" ] || return 0
395 sed -e 's/ .*$//;'"s~^~$tg_tmp_dir/cached/~" <"$tg_ref_cache" | xargs mkdir -p
396 echo 1 >"$tg_tmp_dir/tg~ref-dirs-created"
399 # If the first argument is non-empty, outputs "1" if this call created the cache
400 create_ref_cache()
402 [ -n "$tg_ref_cache" -a ! -s "$tg_ref_cache" ] || return 0
403 _remotespec=
404 [ -z "$base_remote" ] || _remotespec="refs/remotes/$base_remote"
405 [ -z "$1" ] || printf '1'
406 git for-each-ref --format='%(refname) %(objectname)' \
407 refs/heads "refs/$topbases" $_remotespec >"$tg_ref_cache"
408 create_ref_dirs
411 remove_ref_cache()
413 [ -n "$tg_ref_cache" -a -s "$tg_ref_cache" ] || return 0
414 >"$tg_ref_cache"
417 # setting tg_ref_cache_only to non-empty will force non-$tg_ref_cache lookups to fail
418 rev_parse()
420 if [ -n "$tg_ref_cache" -a -s "$tg_ref_cache" ]; then
421 LC_ALL=C awk -v r="$1" 'BEGIN {e=1}; $1 == r {print $2; e=0; exit}; END {exit e}' <"$tg_ref_cache"
422 else
423 [ -z "$tg_ref_cache_only" ] || return 1
424 git rev-parse --quiet --verify "$1^0" -- 2>/dev/null
428 # ref_exists_rev REF
429 # Whether REF is a valid ref name
430 # REF must be fully qualified and start with refs/heads/, refs/$topbases/
431 # or, if $base_remote is set, refs/remotes/$base_remote/
432 # Caches result if $tg_read_only and outputs HASH on success
433 ref_exists_rev()
435 case "$1" in
436 refs/*)
438 $octet20)
439 printf '%s' "$1"
440 return;;
442 die "ref_exists_rev requires fully-qualified ref name"
443 esac
444 [ -n "$tg_read_only" ] || { git rev-parse --quiet --verify "$1^0" -- 2>/dev/null; return; }
445 _result=
446 _result_rev=
447 { read -r _result _result_rev <"$tg_tmp_dir/cached/$1/.ref"; } 2>/dev/null || :
448 [ -z "$_result" ] || { printf '%s' "$_result_rev"; return $_result; }
449 _result_rev="$(rev_parse "$1")"
450 _result=$?
451 [ -d "$tg_tmp_dir/cached/$1" ] || mkdir -p "$tg_tmp_dir/cached/$1" 2>/dev/null
452 [ ! -d "$tg_tmp_dir/cached/$1" ] ||
453 echo $_result $_result_rev >"$tg_tmp_dir/cached/$1/.ref" 2>/dev/null || :
454 printf '%s' "$_result_rev"
455 return $_result
458 # Same as ref_exists_rev but output is abbreviated hash
459 ref_exists_rev_short()
461 case "$1" in
462 refs/*)
464 $octet20)
467 die "ref_exists_rev_short requires fully-qualified ref name"
468 esac
469 [ -n "$tg_read_only" ] || { git rev-parse --quiet --verify --short "$1^0" -- 2>/dev/null; return; }
470 _result=
471 _result_rev=
472 { read -r _result _result_rev <"$tg_tmp_dir/cached/$1/.rfs"; } 2>/dev/null || :
473 [ -z "$_result" ] || { printf '%s' "$_result_rev"; return $_result; }
474 _result_rev="$(rev_parse "$1")"
475 _result=$?
476 if [ $_result -eq 0 ]; then
477 _result_rev="$(git rev-parse --verify --short --quiet "$_result_rev" --)"
478 _result=$?
480 [ -d "$tg_tmp_dir/cached/$1" ] || mkdir -p "$tg_tmp_dir/cached/$1" 2>/dev/null
481 [ ! -d "$tg_tmp_dir/cached/$1" ] ||
482 echo $_result $_result_rev >"$tg_tmp_dir/cached/$1/.rfs" 2>/dev/null || :
483 printf '%s' "$_result_rev"
484 return $_result
487 # ref_exists REF
488 # Whether REF is a valid ref name
489 # REF must be fully qualified and start with refs/heads/, refs/$topbases/
490 # or, if $base_remote is set, refs/remotes/$base_remote/
491 # Caches result
492 ref_exists()
494 ref_exists_rev "$1" >/dev/null
497 # rev_parse_tree REF
498 # Runs git rev-parse REF^{tree}
499 # Caches result if $tg_read_only
500 rev_parse_tree()
502 [ -n "$tg_read_only" ] || { git rev-parse --verify "$1^{tree}" -- 2>/dev/null; return; }
503 if [ -f "$tg_tmp_dir/cached/$1/.rpt" ]; then
504 if IFS= read -r _result <"$tg_tmp_dir/cached/$1/.rpt"; then
505 printf '%s\n' "$_result"
506 return 0
508 return 1
510 [ -d "$tg_tmp_dir/cached/$1" ] || mkdir -p "$tg_tmp_dir/cached/$1" 2>/dev/null || :
511 if [ -d "$tg_tmp_dir/cached/$1" ]; then
512 git rev-parse --verify "$1^{tree}" -- >"$tg_tmp_dir/cached/$1/.rpt" 2>/dev/null || :
513 if IFS= read -r _result <"$tg_tmp_dir/cached/$1/.rpt"; then
514 printf '%s\n' "$_result"
515 return 0
517 return 1
519 git rev-parse --verify "$1^{tree}" -- 2>/dev/null
522 # has_remote BRANCH
523 # Whether BRANCH has a remote equivalent (accepts $topbases/ too)
524 has_remote()
526 [ -n "$base_remote" ] && ref_exists "refs/remotes/$base_remote/$1"
529 # Return the verified TopGit branch name or die with an error.
530 # As a convenience, if HEAD is given and HEAD is a symbolic ref to
531 # refs/heads/... then ... will be verified instead.
532 # if "$2" = "-f" (for fail) then return an error rather than dying.
533 verify_topgit_branch()
535 case "$1" in
536 refs/heads/*)
537 _verifyname="${1#refs/heads/}"
539 refs/"$topbases"/*)
540 _verifyname="${1#refs/$topbases/}"
542 HEAD)
543 _verifyname="$(git symbolic-ref HEAD 2>/dev/null || :)"
544 [ -n "$_verifyname" -o "$2" = "-f" ] || die "HEAD is not a symbolic ref"
545 case "$_verifyname" in refs/heads/*);;*)
546 [ "$2" != "-f" ] || return 1
547 die "HEAD is not a symbolic ref to the refs/heads namespace"
548 esac
549 _verifyname="${_verifyname#refs/heads/}"
552 _verifyname="$1"
554 esac
555 if ! ref_exists "refs/heads/$_verifyname"; then
556 [ "$2" != "-f" ] || return 1
557 die "no such branch: $_verifyname"
559 if ! ref_exists "refs/$topbases/$_verifyname"; then
560 [ "$2" != "-f" ] || return 1
561 die "not a TopGit-controlled branch: $_verifyname"
563 printf '%s' "$_verifyname"
566 # Caches result
567 # $1 = branch name (i.e. "t/foo/bar")
568 # $2 = optional result of rev-parse "refs/heads/$1"
569 # $3 = optional result of rev-parse "refs/$topbases/$1"
570 branch_annihilated()
572 _branch_name="$1"
573 _rev="${2:-$(ref_exists_rev "refs/heads/$_branch_name")}"
574 _rev_base="${3:-$(ref_exists_rev "refs/$topbases/$_branch_name")}"
576 _result=
577 _result_rev=
578 _result_rev_base=
579 { read -r _result _result_rev _result_rev_base <"$tg_cache_dir/$_branch_name/.ann"; } 2>/dev/null || :
580 [ -z "$_result" -o "$_result_rev" != "$_rev" -o "$_result_rev_base" != "$_rev_base" ] || return $_result
582 # use the merge base in case the base is ahead.
583 mb="$(git merge-base "$_rev_base" "$_rev" 2>/dev/null)"
585 test -z "$mb" || test "$(rev_parse_tree "$mb")" = "$(rev_parse_tree "$_rev")"
586 _result=$?
587 [ -d "$tg_cache_dir/$_branch_name" ] || mkdir -p "$tg_cache_dir/$_branch_name" 2>/dev/null
588 [ ! -d "$tg_cache_dir/$_branch_name" ] ||
589 echo $_result $_rev $_rev_base >"$tg_cache_dir/$_branch_name/.ann" 2>/dev/null || :
590 return $_result
593 non_annihilated_branches()
595 [ $# -gt 0 ] || set -- "refs/$topbases"
596 git for-each-ref --format='%(objectname) %(refname)' "$@" |
597 while read rev ref; do
598 name="${ref#refs/$topbases/}"
599 if branch_annihilated "$name" "" "$rev"; then
600 continue
602 echol "$name"
603 done
606 # Make sure our tree is clean
607 ensure_clean_tree()
609 git update-index --ignore-submodules --refresh ||
610 die "the working directory has uncommitted changes (see above) - first commit or reset them"
611 [ -z "$(git diff-index --cached --name-status -r --ignore-submodules HEAD --)" ] ||
612 die "the index has uncommited changes"
615 # is_sha1 REF
616 # Whether REF is a SHA1 (compared to a symbolic name).
617 is_sha1()
619 case "$1" in $octet20) return 0;; esac
620 return 1
623 # recurse_deps_internal NAME [BRANCHPATH...]
624 # get recursive list of dependencies with leading 0 if branch exists 1 if missing
625 # followed by a 1 if the branch is "tgish" or a 0 if not
626 # then the branch name followed by its depedency chain (which might be empty)
627 # An output line might look like this:
628 # 0 1 t/foo/leaf t/foo/int t/stage
629 # If no_remotes is non-empty, exclude remotes
630 # If recurse_preorder is non-empty, do a preorder rather than postorder traversal
631 # any branch names in the space-separated recurse_deps_exclude variable
632 # are skipped (along with their dependencies)
633 recurse_deps_internal()
635 case " $recurse_deps_exclude " in *" $1 "*) return 0; esac
636 _ref_hash=
637 if ! _ref_hash="$(ref_exists_rev "refs/heads/$1")"; then
638 [ -z "$2" ] || echo "1 0 $*"
639 return
642 _is_tgish=0
643 _ref_hash_base=
644 ! _ref_hash_base="$(ref_exists_rev "refs/$topbases/$1")" || _is_tgish=1
645 [ -z "$recurse_preorder" -o -z "$2" ] || echo "0 $_is_tgish $*"
647 # If no_remotes is unset also check our base against remote base.
648 # Checking our head against remote head has to be done in the helper.
649 if [ -n "$_is_tgish" -a -z "$no_remotes" ] && has_remote "$topbases/$1"; then
650 echo "0 0 refs/remotes/$base_remote/$topbases/$1 $*"
653 # if the branch was annihilated, it is considered to have no dependencies
654 if [ -n "$_is_tgish" ] && ! branch_annihilated "$1" "$_ref_hash" "$_ref_hash_base"; then
655 #TODO: handle nonexisting .topdeps?
656 cat_deps "$1" |
657 while read _dname; do
658 # Avoid depedency loops
659 case " $* " in *" $_dname "*)
660 warn "dependency loop detected in branch $_dname"
661 continue
662 esac
663 # Shoo shoo, leave our environment alone!
664 (recurse_deps_internal "$_dname" "$@")
665 done
668 [ -n "$recurse_preorder" -o -z "$2" ] || echo "0 $_is_tgish $*"
671 # do_eval CMD
672 # helper for recurse_deps so that a return statement executed inside CMD
673 # does not return from recurse_deps. This shouldn't be necessary, but it
674 # seems that it actually is.
675 do_eval()
677 eval "$@"
680 # becomes read-only for caching purposes
681 # assigns new value to tg_read_only
682 # become_cacheable/undo_become_cacheable calls may be nested
683 become_cacheable()
685 _old_tg_read_only="$tg_read_only"
686 if [ -z "$tg_read_only" ]; then
687 rm -rf "$tg_tmp_dir/cached" "$tg_tmp_dir/tg~ref-dirs-created"
688 tg_read_only=1
690 _my_ref_cache="$(create_ref_cache 1)"
691 _my_ref_cache="${_my_ref_cache:+1}"
692 tg_read_only="undo${_my_ref_cache:-0}-$_old_tg_read_only"
695 # restores tg_read_only and ref_cache to state before become_cacheable call
696 # become_cacheable/undo_bocome_cacheable calls may be nested
697 undo_become_cacheable()
699 case "$tg_read_only" in
700 "undo"[01]"-"*)
701 _suffix="${tg_read_only#undo?-}"
702 [ "${tg_read_only%$_suffix}" = "undo0-" ] || remove_ref_cache
703 tg_read_only="$_suffix"
704 esac
707 # just call this, no undo, sets tg_read_only= and removes ref cache and cached results
708 become_non_cacheable()
710 remove_ref_cache
711 tg_read_only=
712 rm -rf "$tg_tmp_dir/cached" "$tg_tmp_dir/tg~ref-dirs-created"
715 # call this to make sure Git will not complain about a missing user/email
716 # result is cached in TG_IDENT_CHECKED and a non-empty value suppresses the check
717 ensure_ident_available()
719 [ -z "$TG_IDENT_CHECKED" ] || return 0
720 git var GIT_AUTHOR_IDENT >/dev/null &&
721 git var GIT_COMMITTER_IDENT >/dev/null || exit
722 TG_IDENT_CHECKED=1
723 export TG_IDENT_CHECKED
724 return 0
727 # recurse_deps CMD NAME [BRANCHPATH...]
728 # Recursively eval CMD on all dependencies of NAME.
729 # Dependencies are visited in topological order.
730 # CMD can refer to $_name for queried branch name,
731 # $_dep for dependency name,
732 # $_depchain for space-seperated branch backtrace,
733 # $_dep_missing boolean to check whether $_dep is present
734 # and the $_dep_is_tgish boolean.
735 # It can modify $_ret to affect the return value
736 # of the whole function.
737 # If recurse_deps() hits missing dependencies, it will append
738 # them to space-separated $missing_deps list and skip them
739 # after calling CMD with _dep_missing set.
740 # remote dependencies are processed if no_remotes is unset.
741 # any branch names in the space-separated recurse_deps_exclude variable
742 # are skipped (along with their dependencies)
743 recurse_deps()
745 _cmd="$1"; shift
747 become_cacheable
748 _depsfile="$(get_temp tg-depsfile)"
749 recurse_deps_internal "$@" >>"$_depsfile"
750 undo_become_cacheable
752 _ret=0
753 while read _ismissing _istgish _dep _name _deppath; do
754 _depchain="$_name${_deppath:+ $_deppath}"
755 _dep_is_tgish=
756 [ "$_istgish" = "0" ] || _dep_is_tgish=1
757 _dep_missing=
758 if [ "$_ismissing" != "0" ]; then
759 _dep_missing=1
760 case " $missing_deps " in *" $_dep "*);;*)
761 missing_deps="${missing_deps:+$missing_deps }$_dep"
762 esac
764 do_eval "$_cmd"
765 done <"$_depsfile"
766 rm -f "$_depsfile"
767 return $_ret
770 # branch_needs_update
771 # This is a helper function for determining whether given branch
772 # is up-to-date wrt. its dependencies. It expects input as if it
773 # is called as a recurse_deps() helper.
774 # In case the branch does need update, it will echo it together
775 # with the branch backtrace on the output (see needs_update()
776 # description for details) and set $_ret to non-zero.
777 branch_needs_update()
779 if [ -n "$_dep_missing" ]; then
780 echo "! $_dep $_depchain"
781 return 0
784 if [ -n "$_dep_is_tgish" ]; then
785 branch_annihilated "$_dep" && return 0
787 if has_remote "$_dep"; then
788 branch_contains "refs/heads/$_dep" "refs/remotes/$base_remote/$_dep" ||
789 echo "refs/remotes/$base_remote/$_dep $_dep $_depchain"
791 # We want to sync with our base first and should output this before
792 # the remote branch, but the order does not actually matter to tg-update
793 # as it just recurses regardless, but it does matter for tg-info (which
794 # treats out-of-date bases as though they were already merged in) so
795 # we output the remote before the base.
796 branch_contains "refs/heads/$_dep" "refs/$topbases/$_dep" || {
797 echo ": $_dep $_depchain"
798 _ret=1
799 return
803 if [ -n "$_name" ]; then
804 case "$_dep" in refs/*) _fulldep="$_dep";; *) _fulldep="refs/heads/$_dep";; esac
805 if ! branch_contains "refs/$topbases/$_name" "$_fulldep"; then
806 # Some new commits in _dep
807 echo "$_dep $_depchain"
808 _ret=1
813 # needs_update NAME
814 # This function is recursive; it outputs reverse path from NAME
815 # to the branch (e.g. B_DIRTY B1 B2 NAME), one path per line,
816 # inner paths first. Innermost name can be refs/remotes/<remote>/<name>
817 # if the head is not in sync with the <remote> branch <name>, ':' if
818 # the head is not in sync with the base (in this order of priority)
819 # or '!' if dependency is missing. Note that the remote branch, base
820 # order is reversed from the order they will actually be updated in
821 # order to accomodate tg info which treats out-of-date items that are
822 # only in the base as already being in the head for status purposes.
823 # It will also return non-zero status if NAME needs update.
824 # If needs_update() hits missing dependencies, it will append
825 # them to space-separated $missing_deps list and skip them.
826 needs_update()
828 recurse_deps branch_needs_update "$1"
831 # branch_empty NAME [-i | -w]
832 branch_empty()
834 if [ -z "$2" ]; then
835 _rev="$(ref_exists_rev "refs/heads/$1")" || return 0
836 _result=
837 _result_rev=
838 { read -r _result _result_rev <"$tg_cache_dir/$1/.mt"; } 2>/dev/null || :
839 [ -z "$_result" -o "$_result_rev" != "$_rev" ] || return $_result
840 _result=0
841 [ "$(pretty_tree "$1" -b)" = "$(pretty_tree "$1" $2)" ] || _result=$?
842 [ -d "$tg_cache_dir/$1" ] || mkdir -p "$tg_cache_dir/$1" 2>/dev/null
843 [ ! -d "$tg_cache_dir/$1" ] || echo $_result $_rev >"$tg_cache_dir/$1/.mt"
844 return $_result
845 else
846 [ "$(pretty_tree "$1" -b)" = "$(pretty_tree "$1" $2)" ]
850 # list_deps [-i | -w] [BRANCH]
851 # -i/-w apply only to HEAD
852 list_deps()
854 head_from=
855 [ "$1" != "-i" -a "$1" != "-w" ] || { head_from="$1"; shift; }
856 head="$(git symbolic-ref -q HEAD)" ||
857 head="..detached.."
859 git for-each-ref --format='%(objectname) %(refname)' "refs/$topbases${1:+/$1}" |
860 while read rev ref; do
861 name="${ref#refs/$topbases/}"
862 if branch_annihilated "$name" "" "$rev"; then
863 continue
866 from=$head_from
867 [ "refs/heads/$name" = "$head" ] ||
868 from=
869 cat_file "refs/heads/$name:.topdeps" $from | while read dep; do
870 dep_is_tgish=true
871 ref_exists "refs/$topbases/$dep" ||
872 dep_is_tgish=false
873 if ! "$dep_is_tgish" || ! branch_annihilated $dep; then
874 echo "$name $dep"
876 done
877 done
880 # switch_to_base NAME [SEED]
881 switch_to_base()
883 _base="refs/$topbases/$1"; _seed="$2"
884 # We have to do all the hard work ourselves :/
885 # This is like git checkout -b "$_base" "$_seed"
886 # (or just git checkout "$_base"),
887 # but does not create a detached HEAD.
888 git read-tree -u -m HEAD "${_seed:-$_base}"
889 [ -z "$_seed" ] || git update-ref "$_base" "$_seed"
890 git symbolic-ref HEAD "$_base"
893 # run editor with arguments
894 # the editor setting will be cached in $tg_editor (which is eval'd)
895 # result non-zero if editor fails or GIT_EDITOR cannot be determined
896 run_editor()
898 tg_editor="$GIT_EDITOR"
899 [ -n "$tg_editor" ] || tg_editor="$(git var GIT_EDITOR)" || return $?
900 eval "$tg_editor" '"$@"'
903 # Show the help messages.
904 do_help()
906 _www=
907 if [ "$1" = "-w" ]; then
908 _www=1
909 shift
911 if [ -z "$1" ] ; then
912 # This is currently invoked in all kinds of circumstances,
913 # including when the user made a usage error. Should we end up
914 # providing more than a short help message, then we should
915 # differentiate.
916 # Petr's comment: http://marc.info/?l=git&m=122718711327376&w=2
918 ## Build available commands list for help output
920 cmds=
921 sep=
922 for cmd in "$TG_INST_CMDDIR"/tg-*; do
923 ! [ -r "$cmd" ] && continue
924 # strip directory part and "tg-" prefix
925 cmd="$(basename "$cmd")"
926 cmd="${cmd#tg-}"
927 cmds="$cmds$sep$cmd"
928 sep="|"
929 done
931 echo "TopGit version $TG_VERSION - A different patch queue manager"
932 echo "Usage: $tgname [-C <dir>] [-r <remote> | -u] [-c <name>=<val>] ($cmds) ..."
933 echo " Or: $tgname help [-w] [<command>]"
934 echo "Use \"$tgdisplaydir$tgname help tg\" for overview of TopGit"
935 elif [ -r "$TG_INST_CMDDIR"/tg-$1 -o -r "$TG_INST_SHAREDIR/tg-$1.txt" ] ; then
936 if [ -n "$_www" ]; then
937 nohtml=
938 if ! [ -r "$TG_INST_SHAREDIR/topgit.html" ]; then
939 echo "$(basename "$0"): missing html help file:" \
940 "$TG_INST_SHAREDIR/topgit.html" 1>&2
941 nohtml=1
943 if ! [ -r "$TG_INST_SHAREDIR/tg-$1.html" ]; then
944 echo "$(basename "$0"): missing html help file:" \
945 "$TG_INST_SHAREDIR/tg-$1.html" 1>&2
946 nohtml=1
948 if [ -n "$nohtml" ]; then
949 echo "$(basename "$0"): use" \
950 "\"$(basename "$0") help $1\" instead" 1>&2
951 exit 1
953 git web--browse -c help.browser "$TG_INST_SHAREDIR/tg-$1.html"
954 exit
956 output()
958 if [ -r "$TG_INST_CMDDIR"/tg-$1 ] ; then
959 "$TG_INST_CMDDIR"/tg-$1 -h 2>&1 || :
960 echo
962 if [ -r "$TG_INST_SHAREDIR/tg-$1.txt" ] ; then
963 cat "$TG_INST_SHAREDIR/tg-$1.txt"
966 page output "$1"
967 else
968 echo "$(basename "$0"): no help for $1" 1>&2
969 do_help
970 exit 1
974 ## Pager stuff
976 # isatty FD
977 isatty()
979 test -t $1
982 # pass "diff" to get pager.diff
983 # if pager.$1 is a boolean false returns cat
984 # if set to true or unset fails
985 # otherwise succeeds and returns the value
986 get_pager()
988 if _x="$(git config --bool "pager.$1" 2>/dev/null)"; then
989 [ "$_x" != "true" ] || return 1
990 echo "cat"
991 return 0
993 if _x="$(git config "pager.$1" 2>/dev/null)"; then
994 echol "$_x"
995 return 0
997 return 1
1000 # setup_pager
1001 # Set TG_PAGER to a valid executable
1002 # After calling, code to be paged should be surrounded with {...} | eval "$TG_PAGER"
1003 # See also the following "page" function for ease of use
1004 # emptypager will be set to 1 (otherwise empty) if TG_PAGER was set to "cat" to not be empty
1005 # Preference is (same as Git):
1006 # 1. GIT_PAGER
1007 # 2. pager.$USE_PAGER_TYPE (but only if USE_PAGER_TYPE is set and so is pager.$USE_PAGER_TYPE)
1008 # 3. core.pager (only if set)
1009 # 4. PAGER
1010 # 5. git var GIT_PAGER
1011 # 6. less
1012 setup_pager()
1014 isatty 1 || { emptypager=1; TG_PAGER=cat; return 0; }
1016 emptypager=
1017 if [ -z "$TG_PAGER_IN_USE" ]; then
1018 # TG_PAGER = GIT_PAGER | PAGER | less
1019 # NOTE: GIT_PAGER='' is significant
1020 if [ -n "${GIT_PAGER+set}" ]; then
1021 TG_PAGER="$GIT_PAGER"
1022 elif [ -n "$USE_PAGER_TYPE" ] && _dp="$(get_pager "$USE_PAGER_TYPE")"; then
1023 TG_PAGER="$_dp"
1024 elif _cp="$(git config core.pager 2>/dev/null)"; then
1025 TG_PAGER="$_cp"
1026 elif [ -n "${PAGER+set}" ]; then
1027 TG_PAGER="$PAGER"
1028 else
1029 _gp="$(git var GIT_PAGER 2>/dev/null || :)"
1030 [ "$_gp" != ":" ] || _gp=
1031 TG_PAGER="${_gp:-less}"
1033 if [ -z "$TG_PAGER" ]; then
1034 emptypager=1
1035 TG_PAGER=cat
1037 else
1038 emptypager=1
1039 TG_PAGER=cat
1042 # Set pager default environment variables
1043 # see pager.c:setup_pager
1044 if [ -z "${LESS+set}" ]; then
1045 LESS="-FRX"
1046 export LESS
1048 if [ -z "${LV+set}" ]; then
1049 LV="-c"
1050 export LV
1053 # this is needed so e.g. $(git diff) will still colorize it's output if
1054 # requested in ~/.gitconfig with color.diff=auto
1055 GIT_PAGER_IN_USE=1
1056 export GIT_PAGER_IN_USE
1058 # this is needed so we don't get nested pagers
1059 TG_PAGER_IN_USE=1
1060 export TG_PAGER_IN_USE
1063 # page eval_arg [arg ...]
1065 # Calls setup_pager then evals the first argument passing it all the rest
1066 # where the output is piped through eval "$TG_PAGER" unless emptypager is set
1067 # by setup_pager (in which case the output is left as-is).
1069 # To handle arbitrary paging duties, collect lines to be paged into a
1070 # function and then call page with the function name or perhaps func_name "$@".
1072 # If no arguments at all are passed in do nothing (return with success).
1073 page()
1075 [ $# -gt 0 ] || return 0
1076 setup_pager
1077 _evalarg="$1"; shift
1078 if [ -n "$emptypager" ]; then
1079 eval "$_evalarg" '"$@"'
1080 else
1081 eval "$_evalarg" '"$@"' | eval "$TG_PAGER"
1085 # get_temp NAME [-d]
1086 # creates a new temporary file (or directory with -d) in the global
1087 # temporary directory $tg_tmp_dir with pattern prefix NAME
1088 get_temp()
1090 mktemp $2 "$tg_tmp_dir/$1.XXXXXX"
1093 # automatically called by strftime
1094 # does nothing if already setup
1095 # may be called explicitly if the first call would otherwise be in a subshell
1096 # so that the setup is only done once before subshells start being spawned
1097 setup_strftime()
1099 [ -z "$strftime_is_setup" ] || return 0
1101 # date option to format raw epoch seconds values
1102 daterawopt=
1103 _testes='951807788'
1104 _testdt='2000-02-29 07:03:08 UTC'
1105 _testfm='%Y-%m-%d %H:%M:%S %Z'
1106 if [ "$(TZ=UTC date "-d@$_testes" "+$_testfm" 2>/dev/null)" = "$_testdt" ]; then
1107 daterawopt='-d@'
1108 elif [ "$(TZ=UTC date "-r$_testes" "+$_testfm" 2>/dev/null)" = "$_testdt" ]; then
1109 daterawopt='-r'
1111 strftime_is_setup=1
1114 # $1 => strftime format string to use
1115 # $2 => raw timestamp as seconds since epoch
1116 # $3 => optional time zone string (empty/absent for local time zone)
1117 strftime()
1119 setup_strftime
1120 if [ -n "$daterawopt" ]; then
1121 if [ -n "$3" ]; then
1122 TZ="$3" date "$daterawopt$2" "+$1"
1123 else
1124 date "$daterawopt$2" "+$1"
1126 else
1127 if [ -n "$3" ]; then
1128 TZ="$3" perl -MPOSIX=strftime -le 'print strftime($ARGV[0],localtime($ARGV[1]))' "$1" "$2"
1129 else
1130 perl -MPOSIX=strftime -le 'print strftime($ARGV[0],localtime($ARGV[1]))' "$1" "$2"
1135 ## Initial setup
1136 initial_setup()
1138 # suppress the merge log editor feature since git 1.7.10
1140 GIT_MERGE_AUTOEDIT=no
1141 export GIT_MERGE_AUTOEDIT
1143 auhopt=
1144 ! vcmp "$git_version" '>=' "2.9" || auhopt="--allow-unrelated-histories"
1145 git_dir="$(git rev-parse --git-dir)"
1146 root_dir="$(git rev-parse --show-cdup)"; root_dir="${root_dir:-.}"
1147 logrefupdates="$(git config --bool core.logallrefupdates 2>/dev/null || :)"
1148 [ "$logrefupdates" = "true" ] || logrefupdates=
1149 tgsequester="$(git config --bool topgit.sequester 2>/dev/null || :)"
1150 tgnosequester=
1151 [ "$tgsequester" != "false" ] || tgnosequester=1
1152 unset tgsequester
1154 # make sure root_dir doesn't end with a trailing slash.
1156 root_dir="${root_dir%/}"
1157 [ -n "$base_remote" ] || base_remote="$(git config topgit.remote 2>/dev/null)" || :
1159 # make sure global cache directory exists inside GIT_DIR
1161 tg_cache_dir="$git_dir/tg-cache"
1162 [ -d "$tg_cache_dir" ] || mkdir "$tg_cache_dir"
1164 # create global temporary directories, inside GIT_DIR
1166 tg_tmp_dir=
1167 trap 'rm -rf "$tg_tmp_dir"' EXIT
1168 trap 'exit 129' HUP
1169 trap 'exit 130' INT
1170 trap 'exit 131' QUIT
1171 trap 'exit 134' ABRT
1172 trap 'exit 143' TERM
1173 tg_tmp_dir="$(mktemp -d "$git_dir/tg-tmp.XXXXXX")"
1174 tg_ref_cache="$tg_tmp_dir/tg~ref-cache"
1176 # refer to "top-bases" in a refname with $topbases
1178 topbases="top-bases"
1181 # return the "realpath" for the item except the leaf is not resolved if it's
1182 # a symbolic link. The directory part must exist, but the basename need not.
1183 get_abs_path()
1185 [ -n "$1" -a -d "$(dirname "$1")" ] || return 1
1186 printf '%s' "$(cd -- "$(dirname "$1")" && pwd -P)/$(basename "$1")"
1189 ## Startup
1191 : "${TG_INST_CMDDIR:=@cmddir@}"
1192 : "${TG_INST_SHAREDIR:=@sharedir@}"
1193 : "${TG_INST_HOOKSDIR:=@hooksdir@}"
1195 [ -d "$TG_INST_CMDDIR" ] ||
1196 die "No command directory: '$TG_INST_CMDDIR'"
1198 if [ -n "$tg__include" ]; then
1200 # We were sourced from another script for our utility functions;
1201 # this is set by hooks. Skip the rest of the file. A simple return doesn't
1202 # work as expected in every shell. See http://bugs.debian.org/516188
1204 # ensure setup happens
1206 initial_setup
1208 else
1210 set -e
1212 tg="$0"
1213 tgdir="$(dirname "$tg")/"
1214 tgname="$(basename "$tg")"
1215 [ "$0" != "$tgname" ] || tgdir=""
1217 # If tg contains a '/' but does not start with one then replace it with an absolute path
1219 case "$0" in /*) ;; */*)
1220 tgdir="$(cd "$(dirname "$0")" && pwd -P)/"
1221 tg="$tgdir$tgname"
1222 esac
1224 # If the tg in the PATH is the same as "$tg" just display the basename
1225 # tgdisplay will include any explicit -C <dir> option whereas tg will not
1227 tgdisplaydir="$tgdir"
1228 tgdisplay="$tg"
1229 if [ "$(get_abs_path "$tg")" = "$(get_abs_path "$(cmd_path "$tgname" || :)" || :)" ]; then
1230 tgdisplaydir=""
1231 tgdisplay="$tgname"
1234 explicit_remote=
1235 explicit_dir=
1236 gitcdopt=
1237 noremote=
1239 cmd=
1240 while :; do case "$1" in
1242 help|--help|-h)
1243 cmd=help
1244 shift
1245 break;;
1247 --hooks-path)
1248 cmd=hooks-path
1249 shift
1250 break;;
1253 shift
1254 if [ -z "$1" ]; then
1255 echo "Option -r requires an argument." >&2
1256 do_help
1257 exit 1
1259 unset noremote
1260 base_remote="$1"
1261 explicit_remote="$base_remote"
1262 tg="$tgdir$tgname -r $explicit_remote"
1263 tgdisplay="$tgdisplaydir$tgname"
1264 [ -z "$explicit_dir" ] || tgdisplay="$tgdisplay -C \"$explicit_dir\""
1265 tgdisplay="$tgdisplay -r $explicit_remote"
1266 shift;;
1269 unset base_remote explicit_remote
1270 noremote=1
1271 tg="$tgdir$tgname -u"
1272 tgdisplay="$tgdisplaydir$tgname"
1273 [ -z "$explicit_dir" ] || tgdisplay="$tgdisplay -C \"$explicit_dir\""
1274 tgdisplay="$tgdisplay -u"
1275 shift;;
1278 shift
1279 if [ -z "$1" ]; then
1280 echo "Option -C requires an argument." >&2
1281 do_help
1282 exit 1
1284 cd "$1"
1285 unset GIT_DIR
1286 explicit_dir="$1"
1287 gitcdopt=" -C \"$explicit_dir\""
1288 tg="$tgdir$tgname"
1289 tgdisplay="$tgdisplaydir$tgname -C \"$explicit_dir\""
1290 [ -z "$explicit_remote" ] || tg="$tg -r $explicit_remote"
1291 [ -z "$explicit_remote" ] || tgdisplay="$tgdisplay -r $explicit_remote"
1292 [ -z "$noremote" ] || tg="$tg -u"
1293 [ -z "$noremote" ] || tg="$tgdisplay -u"
1294 shift;;
1297 shift
1298 if [ -z "$1" ]; then
1299 echo "Option -c requires an argument." >&2
1300 do_help
1301 exit 1
1303 param="'$(printf '%s\n' "$1" | sed "s/[']/'\\\\''/g")'"
1304 GIT_CONFIG_PARAMETERS="${GIT_CONFIG_PARAMETERS:+$GIT_CONFIG_PARAMETERS }$param"
1305 export GIT_CONFIG_PARAMETERS
1306 shift;;
1309 shift
1310 break;;
1313 echo "Invalid option $1 (subcommand options must appear AFTER the subcommand)." >&2
1314 do_help
1315 exit 1;;
1318 break;;
1320 esac; done
1322 [ -n "$cmd" -o $# -lt 1 ] || { cmd="$1"; shift; }
1324 ## Dispatch
1326 [ -n "$cmd" ] || { do_help; exit 1; }
1328 case "$cmd" in
1330 help)
1331 do_help "$@"
1332 exit 0;;
1334 hooks-path)
1335 # Internal command
1336 echol "$TG_INST_HOOKSDIR";;
1339 [ -r "$TG_INST_CMDDIR"/tg-$cmd ] || {
1340 echo "Unknown subcommand: $cmd" >&2
1341 do_help
1342 exit 1
1345 initial_setup
1346 [ -z "$noremote" ] || unset base_remote
1348 nomergesetup=
1349 case "$cmd" in info|log|summary|rebase|revert|tag)
1350 # avoid merge setup where not necessary
1352 nomergesetup=1
1353 esac
1355 if [ -z "$nomergesetup" ]; then
1356 # make sure merging the .top* files will always behave sanely
1358 setup_ours
1359 setup_hook "pre-commit"
1362 _use_ref_cache=
1363 tg_read_only=1
1364 case "$cmd" in
1365 summary|info|export|tag)
1366 _use_ref_cache=1;;
1367 annihilate|create|delete|depend|import|update)
1368 tg_read_only=;;
1369 esac
1370 [ -z "$_use_ref_cache" ] || create_ref_cache
1372 . "$TG_INST_CMDDIR"/tg-$cmd;;
1373 esac
1377 # vim:noet