commit f1417e9f1c817d4e11dba207cf39ae12ffda2138 from: Stefan Sperling via: Thomas Adam date: Tue Oct 12 20:02:46 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 - b6c8e5e0edc57f309ae866114527e614ad0cd76d commit + f1417e9f1c817d4e11dba207cf39ae12ffda2138 blob - 2be25dcb77a5de665eafc583c2cc07ac9f6d4025 blob + 02099e4c91aac5a1e9d1803898d1c74c33234d0d --- 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 - 24e167624a9dff80bfc3ea53ddfcfe092ffd80d6 blob + 4761c1d807aa6e3b17fe877f1423d26a8f7465b2 --- 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 - d8ebff4da2318e250b48af48107b4239b2b982c9 blob + 549ce74297e453fcd8242a38b3d10f6f78fb17d7 --- 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 - 617773180b2eca26860783dcbc63d506914059e2 blob + 1768e16b391b7e17123333e6557cfd1a8ff913a3 --- 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 - 2a7545564f078c5d130856c1ee10bc042b9e44f1 blob + 5d6ef1de516952ff8423025457c87352fb8ed55e --- 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