mackyle/topgit

tg info --series: allow topic with the same name + suffix

Closed this issue · 5 comments

Hello,

First, thank you for developing and maintaining this great tool!

If I have two topics like t/a-a and t/a-a-a, it creates issues with some commands like tg info --series:

No issue to create the base:

>$ git init .
Initialized empty Git repository in /home/nix.tessares.net/mbaerts/tmp-tg/.git/
>$ touch a
>$ git add a
>$ git commit -sm "init"
[main (root-commit) 5e295f5] init
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
>$ tg create t/a-a
tg: automatically marking dependency on main
tg: creating t/a-a base from main...
Switched to a new branch 't/a-a'
[t/a-a 89f9900] tg create t/a-a
 2 files changed, 5 insertions(+)
 create mode 100644 .topdeps
 create mode 100644 .topmsg
tg: Topic branch t/a-a created.
>$ tg
>$ touch a-a
>$ git add $_
>$ git commit -sm "a-a"
[t/a-a 5eba0c5] a-a
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a-a
>$ tg info --series
t/a-a                                   [PATCH] t/a-a

No issue to create a new topic:

>$ tg create t/a-a-a
tg: automatically marking dependency on t/a-a
tg: creating t/a-a-a base from t/a-a...
Switched to a new branch 't/a-a-a'
[t/a-a-a accf6c4] tg create t/a-a-a
 2 files changed, 5 insertions(+)
 create mode 100644 .topdeps
 create mode 100644 .topmsg
tg: Topic branch t/a-a-a created.

But here, tg info --series complains:

>$ tg info --series
join: -:2: is not sorted: t/a-a [PATCH] t/a-a
join: input is not in sorted order
t/a-a-a                                 [PATCH] t/a-a-a

Thank you for reporting this!

I've created a simple list of commands to reproduce your report:

git init issue19 && cd issue19 && git config user.name - && git config user.email -
git commit --allow-empty -m initial_commit
tg create --topmsg a-a t/a-a
echo a-a >a-a && git add a-a
git commit -m a-a
tg info --series # okay
tg create --topmsg a-a-a t/a-a-a
tg info --series # fails; stderr msg on linux, only shows t/a-a-a on stdout (all platforms)

At first I was sure you had fallen afoul of this bug:

# the "UTF-8" or "utf8" locale used must be in the `locale -a` output (but NOT C.UTF-8!)
for lcl in C en_US.UTF-8; do
  printf '\nLC_ALL=%s:\n' "$lcl"
  printf '%s\n' 't/aa-b' 't/a-b' | LC_ALL="$lcl" sort
done

But after some head scratching, I determined that's not what's going on here.

Internally, ref names get an implicit trailing "/" added during an early processing phase that later gets removed again.

What's happening is that instead of sorting these two lines:

t/a-a
t/a-a-a

TopGit is actually sorting these two lines:

t/a-a/
t/a-a-a/

And since the "-" (hex 0x2D) comes before the "/" (hex 0x2F) character they end up in this order:

t/a-a-a/
t/a-a/

Before the trailing "/" ultimately gets removed resulting in this list:

t/a-a-a
t/a-a

Which is no longer sorted correctly. The version of join you're using helpfully gives a diagnostic message (join's input must always be properly sorted), but some other platforms' join commands skip the diagnostic message while still producing the incorrect output which is somewhat less helpful in locating the problem.

I'm now looking at the best way to fix this and will post a patch for you as soon as I have one. And I will be adding a new test case to the test suite to check for this particular case.

Turns out that ended up not being quite as messy as I thought to fix.

Here's a patch against the 0.19.12 release:

https://github.com/mackyle/topgit/blob/06fd19262036a015/patch.txt

It will be included in the forthcoming release which is turning out to be primarily a collection of fixes.

Thank you for looking at this issue, giving clear explanations (tricky issue :) ) and the patch!

I just applied the patch locally and it fixes my issue. I also validated it on a public repo I maintain with TopGit and it fixes issues there too! Thanks!

The topgit-0.19.13 release includes the fix for this (and other reported issues).

Thank you for this great new release!