Skip to content

Commit

Permalink
tg-tag: handle reflog entries with extra tabs
Browse files Browse the repository at this point in the history
It's very possible for a reflog entry to have more than one
tab in it.

The actual format of the reflog is one entry per line as detailed
in the `git help update-ref` documentation.

That documentation overlooks the possibility of there being more
than one "TAB" present in a single line (i.e. entry) of a reflog.

The relevant code that actually parses these lines can be found in
the Git file refs/files-backend.c in the show_one_reflog_ent function.

Behave more like the show_one_reflog_ent function when parsing
reflog entry lines to avoid any confusion over where the optional
message actually starts (if it's present).

Toggle the two affected unit tests in t6102 from `test_expect_failure`
to `test_expect_success` as they now pass with this change.

Signed-off-by: Kyle J. McKay <[email protected]>
  • Loading branch information
mackyle committed Sep 8, 2021
1 parent 5f4bc24 commit 54c563f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions t/t6102-tag-reflog-tabs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ test_expect_success 'setup main' '
test_when_finished test_set_prereq SETUP
'

test_expect_failure SETUP 'tg tag -g log' '
test_expect_success SETUP 'tg tag -g log' '
cd main &&
squish <<-EOT >../expected &&
=== 2005-04-07 ===
Expand All @@ -135,7 +135,7 @@ test_expect_success LASTOK,SETUP 'tg tag -g --reflog-message matches' '
test_cmp ../actual ../expected
'

test_expect_failure SETUP 'tg tag -g --commit-message log' '
test_expect_success SETUP 'tg tag -g --commit-message log' '
cd main &&
squish <<-EOT >../expected2 &&
=== 2005-04-07 ===
Expand Down
14 changes: 7 additions & 7 deletions tg-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,14 @@ if [ -n "$reflog" ]; then
while read -r newrev type rest; do
stashnum=$(( $stashnum + 1 ))
[ "$type" != "missing" ] || continue
IFS="$tab" read -r cmmttr msg <<-~EOT~
$rest
ne= rest2=
IFS=">" read -r ne rest2 <<-~EOT~ || :
${rest}X
~EOT~
es= ez= msg=
read -r es ez msg <<-~EOT~ || :
${rest2%X}
~EOT~
ne="${cmmttr% *}"
ne="${ne% *}"
es="${cmmttr#$ne}"
es="${es% *}"
es="${es# }"
obj="$(git rev-parse --verify --quiet --short "$newrev" --)"
extra=
[ "$type" = "tag" ] || [ -n "$notype" ] ||
Expand Down

0 comments on commit 54c563f

Please sign in to comment.