commit 10a623dfc23b47f494941e0eac741420c08372a3 from: Stefan Sperling date: Mon Oct 11 18:38:33 2021 UTC sort and de-duplicate work tree path command line arguments This is important in cases like 'got diff file.txt file.txt' which should only show the diff for file.txt once. suggested by kn@ commit - 90de04bc7f1b85b9c491bcd124f6178fad005de1 commit + 10a623dfc23b47f494941e0eac741420c08372a3 blob - 323461bc8c40befe6cb69f4cab726725833fff59 blob + 488cd9f35722bed936af6e7d9e2c6aa77ea2a3d8 --- got/got.c +++ got/got.c @@ -3240,6 +3240,7 @@ get_worktree_paths_from_argv(struct got_pathlist_head { const struct got_error *err = NULL; char *path; + struct got_pathlist_entry *new; int i; if (argc == 0) { @@ -3253,10 +3254,11 @@ get_worktree_paths_from_argv(struct got_pathlist_head err = got_worktree_resolve_path(&path, worktree, argv[i]); if (err) break; - err = got_pathlist_append(paths, path, NULL); - if (err) { + err = got_pathlist_insert(&new, paths, path, NULL); + if (err || new == NULL /* duplicate */) { free(path); - break; + if (err) + break; } } blob - 0b8274bf499788e7fa6712a4346be0ea1a745883 blob + e59e019d01dee6cf8c0d851c8d4b5ed6beb5c176 --- regress/cmdline/add.sh +++ regress/cmdline/add.sh @@ -90,9 +90,9 @@ test_add_multiple() { return 1 fi - echo "A foo" > $testroot/stdout.expected - echo "A bar" >> $testroot/stdout.expected + echo "A bar" > $testroot/stdout.expected echo "A baz" >> $testroot/stdout.expected + echo "A foo" >> $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout ret="$?" blob - 9180f57976107c762edd140fcaa6e736a9fb2f77 blob + 7f88ca162b03984f506ec0612d4004a03f86c25f --- regress/cmdline/diff.sh +++ regress/cmdline/diff.sh @@ -116,12 +116,6 @@ test_diff_basic() { # diff several paths in a work tree echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected - echo 'blob - /dev/null' >> $testroot/stdout.expected - echo 'file + new' >> $testroot/stdout.expected - echo '--- /dev/null' >> $testroot/stdout.expected - echo '+++ new' >> $testroot/stdout.expected - echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected - echo '+new file' >> $testroot/stdout.expected echo -n 'blob - ' >> $testroot/stdout.expected got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \ >> $testroot/stdout.expected @@ -132,6 +126,14 @@ test_diff_basic() { echo '-alpha' >> $testroot/stdout.expected echo '+modified alpha' >> $testroot/stdout.expected echo -n 'blob - ' >> $testroot/stdout.expected + got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \ + >> $testroot/stdout.expected + echo 'file + /dev/null' >> $testroot/stdout.expected + echo '--- beta' >> $testroot/stdout.expected + echo '+++ /dev/null' >> $testroot/stdout.expected + echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected + echo '-beta' >> $testroot/stdout.expected + echo -n 'blob - ' >> $testroot/stdout.expected got tree -r $testroot/repo -i epsilon | grep 'zeta$' | cut -d' ' -f 1 \ >> $testroot/stdout.expected echo 'file + epsilon/zeta' >> $testroot/stdout.expected @@ -140,14 +142,12 @@ test_diff_basic() { echo '@@ -1 +1 @@' >> $testroot/stdout.expected echo '-zeta' >> $testroot/stdout.expected echo '+modified zeta' >> $testroot/stdout.expected - echo -n 'blob - ' >> $testroot/stdout.expected - got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \ - >> $testroot/stdout.expected - echo 'file + /dev/null' >> $testroot/stdout.expected - echo '--- beta' >> $testroot/stdout.expected - echo '+++ /dev/null' >> $testroot/stdout.expected - echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected - echo '-beta' >> $testroot/stdout.expected + echo 'blob - /dev/null' >> $testroot/stdout.expected + echo 'file + new' >> $testroot/stdout.expected + echo '--- /dev/null' >> $testroot/stdout.expected + echo '+++ new' >> $testroot/stdout.expected + echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected + echo '+new file' >> $testroot/stdout.expected (cd $testroot/wt && got diff new alpha epsilon beta > $testroot/stdout) cmp -s $testroot/stdout.expected $testroot/stdout @@ -158,10 +158,8 @@ test_diff_basic() { return 1 fi - # a branch 'new' should not collide with path 'new' if more - # than two arguments are passed - got br -r $testroot/repo -c master new > /dev/null - (cd $testroot/wt && got diff new alpha epsilon beta \ + # different order of arguments results in same output order + (cd $testroot/wt && got diff alpha new epsilon beta \ > $testroot/stdout 2> $testroot/stderr) ret="$?" if [ "$ret" != "0" ]; then @@ -177,41 +175,10 @@ test_diff_basic() { return 1 fi - # different order of arguments results in different output order - echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected - echo -n 'blob - ' >> $testroot/stdout.expected - got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \ - >> $testroot/stdout.expected - echo 'file + alpha' >> $testroot/stdout.expected - echo '--- alpha' >> $testroot/stdout.expected - echo '+++ alpha' >> $testroot/stdout.expected - echo '@@ -1 +1 @@' >> $testroot/stdout.expected - echo '-alpha' >> $testroot/stdout.expected - echo '+modified alpha' >> $testroot/stdout.expected - echo 'blob - /dev/null' >> $testroot/stdout.expected - echo 'file + new' >> $testroot/stdout.expected - echo '--- /dev/null' >> $testroot/stdout.expected - echo '+++ new' >> $testroot/stdout.expected - echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected - echo '+new file' >> $testroot/stdout.expected - echo -n 'blob - ' >> $testroot/stdout.expected - got tree -r $testroot/repo -i epsilon | grep 'zeta$' | cut -d' ' -f 1 \ - >> $testroot/stdout.expected - echo 'file + epsilon/zeta' >> $testroot/stdout.expected - echo '--- epsilon/zeta' >> $testroot/stdout.expected - echo '+++ epsilon/zeta' >> $testroot/stdout.expected - echo '@@ -1 +1 @@' >> $testroot/stdout.expected - echo '-zeta' >> $testroot/stdout.expected - echo '+modified zeta' >> $testroot/stdout.expected - echo -n 'blob - ' >> $testroot/stdout.expected - got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \ - >> $testroot/stdout.expected - echo 'file + /dev/null' >> $testroot/stdout.expected - echo '--- beta' >> $testroot/stdout.expected - echo '+++ /dev/null' >> $testroot/stdout.expected - echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected - echo '-beta' >> $testroot/stdout.expected - (cd $testroot/wt && got diff alpha new epsilon beta \ + # a branch 'new' should not collide with path 'new' if more + # than two arguments are passed + got br -r $testroot/repo -c master new > /dev/null + (cd $testroot/wt && got diff new alpha epsilon beta \ > $testroot/stdout 2> $testroot/stderr) ret="$?" if [ "$ret" != "0" ]; then @@ -289,17 +256,17 @@ test_diff_basic() { fi echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected echo 'blob - /dev/null' >> $testroot/stdout.expected - echo 'file + new' >> $testroot/stdout.expected - echo '--- /dev/null' >> $testroot/stdout.expected - echo '+++ new' >> $testroot/stdout.expected - echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected - echo '+new file' >> $testroot/stdout.expected - echo 'blob - /dev/null' >> $testroot/stdout.expected echo 'file + master' >> $testroot/stdout.expected echo '--- /dev/null' >> $testroot/stdout.expected echo '+++ master' >> $testroot/stdout.expected echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected echo '+master' >> $testroot/stdout.expected + echo 'blob - /dev/null' >> $testroot/stdout.expected + echo 'file + new' >> $testroot/stdout.expected + echo '--- /dev/null' >> $testroot/stdout.expected + echo '+++ new' >> $testroot/stdout.expected + echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected + echo '+new file' >> $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout ret="$?" if [ "$ret" != "0" ]; then @@ -1197,7 +1164,7 @@ test_diff_commits() { fi # three arguments imply use of path filtering (work tree case) - (cd $testroot/wt && got diff $commit_id0 $commit_id1 foo \ + (cd $testroot/wt && got diff $commit_id0 master foo \ 2> $testroot/stderr) ret="$?" if [ "$ret" == "0" ]; then blob - 9766243def1b9ea970812bb138d4d8aeda056a96 blob + 608abc82cbefff93d4d24717552a9b9a1f703761 --- regress/cmdline/revert.sh +++ regress/cmdline/revert.sh @@ -1092,12 +1092,12 @@ test_revert_symlink() { cat > $testroot/stdout.expected < $testroot/stdout.expected - echo 'D epsilon.link' >> $testroot/stdout.expected - echo 'D passwd.link' >> $testroot/stdout.expected echo 'D epsilon/beta.link' >> $testroot/stdout.expected + echo 'D epsilon.link' >> $testroot/stdout.expected echo 'D nonexistent.link' >> $testroot/stdout.expected + echo 'D passwd.link' >> $testroot/stdout.expected (cd $testroot/wt && got rm alpha.link epsilon.link passwd.link \ epsilon/beta.link nonexistent.link > $testroot/stdout) blob - de94a6e129b914a487c98dde2b1cc0d59698c4cd blob + 8b67476fd9377314c10033f7fe555651af4cda1a --- regress/cmdline/status.sh +++ regress/cmdline/status.sh @@ -493,12 +493,12 @@ test_status_many_paths() { mkdir $testroot/wt/newdir (cd $testroot/wt && got add new >/dev/null) - (cd $testroot/wt && got status newdir > $testroot/stdout.expected) - (cd $testroot/wt && got status alpha >> $testroot/stdout.expected) + (cd $testroot/wt && got status alpha > $testroot/stdout.expected) + (cd $testroot/wt && got status beta >> $testroot/stdout.expected) (cd $testroot/wt && got status epsilon >> $testroot/stdout.expected) (cd $testroot/wt && got status foo >> $testroot/stdout.expected) (cd $testroot/wt && got status new >> $testroot/stdout.expected) - (cd $testroot/wt && got status beta >> $testroot/stdout.expected) + (cd $testroot/wt && got status newdir >> $testroot/stdout.expected) (cd $testroot/wt && got status . >> $testroot/stdout.expected) (cd $testroot/wt && got status newdir alpha epsilon foo new beta . \ blob - 946422e07ecfbb970b7b9f9264e7ee67e4b62d55 blob + d064dee9ea07f4c1490ffd37ad9aed281f7f6cb0 --- regress/cmdline/update.sh +++ regress/cmdline/update.sh @@ -1181,8 +1181,8 @@ test_update_partial_add() { (cd $testroot/repo && git add .) git_commit $testroot/repo -m "added two files" - echo "A new" > $testroot/stdout.expected - echo "A epsilon/new2" >> $testroot/stdout.expected + echo "A epsilon/new2" > $testroot/stdout.expected + echo "A new" >> $testroot/stdout.expected echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected git_show_head $testroot/repo >> $testroot/stdout.expected echo >> $testroot/stdout.expected