From d7125044b6571c606830c28abf583fdfb15a47f7 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Tue, 20 Jun 2017 13:16:58 -0700 Subject: [PATCH] tg: disambiguate refs/heads/refs/remotes// When recursing for updates and out-of-date checks, remotes are handled (when present) by outputting a full ref name. However, if a refs-namespace-like branch name should be used (e.g. refs/heads/refs/remote/origin/master) it could be misinterpreted as being a remote instead of a branch. Fix this by prefixing a ":" to any full ref names. Since ":" is not a valid ref name character (and an isolated ":" is already being used by branch_needs_update), this succeeds in disambiguating the two cases with practically no impact. There's no conflict with the pre-existing branch_needs_update usage since the new usage will never produce an isolated ":". Some code has even become simplified as a result (and in fact this update removes more lines than it adds). Signed-off-by: Kyle J. McKay --- t/t4200-out-of-date.sh | 6 +++--- tg-export.sh | 2 +- tg-info.sh | 19 +++++++++---------- tg-update.sh | 2 +- tg.sh | 14 +++++++------- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/t/t4200-out-of-date.sh b/t/t4200-out-of-date.sh index ce352f3..412a643 100755 --- a/t/t4200-out-of-date.sh +++ b/t/t4200-out-of-date.sh @@ -188,7 +188,7 @@ test_expect_success 'branch_needs_update hasbase uptodate' ' test_expect_success 'branch_needs_update hasrmt1 outofdate' ' > expected && - echo "refs/remotes/rmt1/top-bases/hasrmt1 hasrmt1" > expected-base && + echo ":refs/remotes/rmt1/top-bases/hasrmt1 hasrmt1" > expected-base && branch_needs_update -C outofdate hasrmt1 > actual && test_diff expected actual && test_must_fail branch_needs_update -C outofdate -r rmt1 hasrmt1 > actual && @@ -271,7 +271,7 @@ test_expect_success 'branch_needs_update uphasbase uptodate' ' test_expect_success 'branch_needs_update uphasrmt1 outofdate' ' > expected && - echo "refs/remotes/rmt1/top-bases/hasrmt1 hasrmt1 uphasrmt1" > expected-base && + echo ":refs/remotes/rmt1/top-bases/hasrmt1 hasrmt1 uphasrmt1" > expected-base && branch_needs_update -C outofdate uphasrmt1 > actual && test_diff expected actual && test_must_fail branch_needs_update -C outofdate -r rmt1 uphasrmt1 > actual && @@ -292,7 +292,7 @@ test_expect_success 'branch_needs_update uphasrmt1 uptodate' ' test_expect_success 'branch_needs_update uphasrmt2 outofdate' ' > expected && - echo "refs/remotes/rmt2/hasrmt2 hasrmt2 uphasrmt2" > expected-remote && + echo ":refs/remotes/rmt2/hasrmt2 hasrmt2 uphasrmt2" > expected-remote && branch_needs_update -C outofdate uphasrmt2 > actual && test_diff expected actual && branch_needs_update -C outofdate -r rmt1 uphasrmt2 > actual && diff --git a/tg-export.sh b/tg-export.sh index bcf6f41..9c92348 100644 --- a/tg-export.sh +++ b/tg-export.sh @@ -376,7 +376,7 @@ driver() [ -z "$_dep_is_tgish" ] || [ -z "$_dep_annihilated" ] || return 0 - case $_dep in refs/remotes/*) return;; esac + case $_dep in ":"*) return; esac branch_needs_update >/dev/null [ "$_ret" -eq 0 ] || die "cancelling export of $_dep (-> $_name): branch not up-to-date" diff --git a/tg-info.sh b/tg-info.sh index 4ec2c0d..287fcdf 100644 --- a/tg-info.sh +++ b/tg-info.sh @@ -247,23 +247,22 @@ sed '/^!/d' <"$depcheck" >"$depcheck2" if [ -s "$depcheck2" ]; then echo "Needs update from:" # 's/ [^ ]* *$//' -- last is $name - # 's/^[:] /:/' -- don't distinguish base updates + # 's/^[:] /::/' -- don't distinguish base updates <"$depcheck2" sed -e 's/ [^ ]* *$//' -e 's/^[:] /:/' | while read dep chain; do + extradep= case "$dep" in - :*) - dep="${dep#:}" + ::*) + dep="${dep#::}" fulldep="refs/heads/$dep" extradep="refs/$topbases/$dep" ;; + :*) + dep="${dep#:}" + fulldep="$dep" + ;; *) - extradep= - case "$dep" in - refs/*) - fulldep="$dep";; - *) - fulldep="refs/heads/$dep";; - esac + fulldep="refs/heads/$dep" ;; esac printf '%s' "$dep " diff --git a/tg-update.sh b/tg-update.sh index d97e30d..c6e4c01 100644 --- a/tg-update.sh +++ b/tg-update.sh @@ -938,7 +938,7 @@ update_branch_internal() { # We do not distinguish between dependencies out-of-date # and base/remote out-of-date cases for $dep here, - # but thanks to needs_update returning : or refs/remotes// + # but thanks to needs_update returning : or :refs/remotes/... # for the latter, we do correctly recurse here # in both cases. diff --git a/tg.sh b/tg.sh index f789f35..15f0407 100644 --- a/tg.sh +++ b/tg.sh @@ -955,7 +955,7 @@ recurse_deps_internal() tmptgrmtbr="$tg_tmp_dir/tgrmtbr.$$" ratr_opts="$ratr_opts -rmr" fi - ratr_opts="$ratr_opts -r=\"\$tmptgrmtbr\" -u=\"refs/remotes/\$base_remote/\${topbases#heads/}\"" + ratr_opts="$ratr_opts -r=\"\$tmptgrmtbr\" -u=\":refs/remotes/\$base_remote/\${topbases#heads/}\"" fi [ -z "$dogfer" ] || eval git for-each-ref '--format="%(refname) %(objectname)"' "$refpats" >"$tmprfs" @@ -1052,9 +1052,9 @@ ensure_ident_available() # CMD can refer to the following variables: # # _ret starts as 0; CMD can change; will be final return result -# _dep bare branch name or "refs/remotes/..." for a remote base +# _dep bare branch name or ":refs/remotes/..." for a remote # _name has $_dep in its .topdeps ("" for top and $with_top_level) -# _depchain 0+ space-separated branch names forming a path to top +# _depchain 0+ space-sep branch names (_name first) form a path to top # _dep_missing boolean "1" if no such $_dep ref; "" if ref present # _dep_is_leaf boolean "1" if leaf; "" if not # _dep_is_tgish boolean "1" if tgish; "" if not (which implies no remote) @@ -1188,7 +1188,7 @@ branch_needs_update() if [ -n "$_dep_has_remote" ]; then branch_contains "refs/heads/$_dep" "refs/remotes/$base_remote/$_dep" || { - echo "refs/remotes/$base_remote/$_dep $_dep $_depchain" + echo ":refs/remotes/$base_remote/$_dep $_dep $_depchain" _ret=1 } fi @@ -1205,7 +1205,7 @@ branch_needs_update() fi if [ -n "$_name" ]; then - case "$_dep" in refs/*) _fulldep="$_dep";; *) _fulldep="refs/heads/$_dep";; esac + case "$_dep" in :*) _fulldep="${_dep#:}";; *) _fulldep="refs/heads/$_dep";; esac if ! branch_contains "refs/$topbases/$_name" "$_fulldep"; then # Some new commits in _dep echo "$_dep $_depchain" @@ -1217,7 +1217,7 @@ branch_needs_update() # needs_update NAME # This function is recursive; it outputs reverse path from NAME # to the branch (e.g. B_DIRTY B1 B2 NAME), one path per line, -# inner paths first. Innermost name can be refs/remotes// +# inner paths first. Innermost name can be :refs/remotes// # if the head is not in sync with the branch , ':' if # the head is not in sync with the base (in this order of priority) # or '!' if dependency is missing. Note that the remote branch, base @@ -1319,7 +1319,7 @@ needs_update_check() # recurse_deps_internal directly recurse_deps_internal -s -o=-1 "$nucname" >"$tmptgrdi" while read -r _rdi_m _rdi_t _rdi_l _rdi_v _rdi_node _rdi_parent _rdi_chain; do - case "$_rdi_node" in ""|refs/remotes/?*) continue; esac # empty or checked with remote head + case "$_rdi_node" in ""|:*) continue; esac # empty or checked with remote vsetadd needs_update_processed "$_rdi_node" if [ "$_rdi_m" != "0" ]; then # missing vsetadd needs_update_partial "$_rdi_node" -- 2.11.4.GIT