commit f35e52a986659efbb797f46df9798c4ad4f36381 from: Mark Jamsek via: Thomas Adam date: Tue Jan 31 15:41:39 2023 UTC show worktree UUID in backout/cherrypick -l output When run from the repository, display the UUID to help the user know which logmsg refs belong to which work tree. Also, use "backout" or "cherrypick" in the log message header to distinguish output from 'got log'. Suggested by stsp on irc. ok stsp@ commit - 54fdcaee61b11a4ba039fce945d3a7e59ef477fc commit + f35e52a986659efbb797f46df9798c4ad4f36381 blob - a251edd8ab6b000c9ac3692077d7af1f3d54bbd8 blob + 49d3d67e1875e281a9eaa73a164a6fa090250833 --- got/got.c +++ got/got.c @@ -4198,7 +4198,8 @@ print_commit(struct got_commit_object *commit, struct struct got_repository *repo, const char *path, struct got_pathlist_head *changed_paths, struct got_diffstat_cb_arg *diffstat, int show_patch, int diff_context, - struct got_reflist_object_id_map *refs_idmap, const char *custom_refs_str) + struct got_reflist_object_id_map *refs_idmap, const char *custom_refs_str, + const char *prefix) { const struct got_error *err = NULL; FILE *f = NULL; @@ -4224,10 +4225,12 @@ print_commit(struct got_commit_object *commit, struct printf(GOT_COMMIT_SEP_STR); if (custom_refs_str) - printf("commit %s (%s)\n", id_str, custom_refs_str); + printf("%s %s (%s)\n", prefix ? prefix : "commit", id_str, + custom_refs_str); else - printf("commit %s%s%s%s\n", id_str, refs_str ? " (" : "", - refs_str ? refs_str : "", refs_str ? ")" : ""); + printf("%s %s%s%s%s\n", prefix ? prefix : "commit", id_str, + refs_str ? " (" : "", refs_str ? refs_str : "", + refs_str ? ")" : ""); free(id_str); id_str = NULL; free(refs_str); @@ -4412,7 +4415,7 @@ print_commits(struct got_object_id *root_id, struct go (show_changed_paths || show_diffstat) ? &changed_paths : NULL, show_diffstat ? &dsa : NULL, show_patch, - diff_context, refs_idmap, NULL); + diff_context, refs_idmap, NULL, NULL); got_object_commit_close(commit); if (err) break; @@ -4447,7 +4450,7 @@ print_commits(struct got_object_id *root_id, struct go (show_changed_paths || show_diffstat) ? &changed_paths : NULL, show_diffstat ? &dsa : NULL, show_patch, - diff_context, refs_idmap, NULL); + diff_context, refs_idmap, NULL, NULL); got_object_commit_close(commit); if (err) break; @@ -9815,6 +9818,7 @@ process_logmsg_refs(const char *ref_prefix, size_t pre struct got_reflist_object_id_map *refs_idmap = NULL; struct got_commit_object *commit = NULL; struct got_object_id *id = NULL; + const char *header_prefix; char *uuidstr = NULL; int found = 0; @@ -9839,9 +9843,14 @@ process_logmsg_refs(const char *ref_prefix, size_t pre if (strncmp(wanted_ref, "refs/heads/", 11) == 0) wanted_ref += 11; } + + if (strcmp(ref_prefix, GOT_WORKTREE_BACKOUT_REF_PREFIX) == 0) + header_prefix = "backout"; + else + header_prefix = "cherrypick"; TAILQ_FOREACH(re, &refs, entry) { - const char *refname; + const char *refname, *wt; refname = got_ref_get_name(re->ref); @@ -9854,6 +9863,8 @@ process_logmsg_refs(const char *ref_prefix, size_t pre else continue; + wt = refname; + if (worktree == NULL || strncmp(refname, uuidstr, GOT_WORKTREE_UUID_STRLEN) == 0) refname += GOT_WORKTREE_UUID_STRLEN + 1; /* skip '-' */ @@ -9921,9 +9932,14 @@ process_logmsg_refs(const char *ref_prefix, size_t pre goto done; err = print_commit(commit, id, repo, NULL, - &paths, NULL, 0, 0, refs_idmap, NULL); + &paths, NULL, 0, 0, refs_idmap, NULL, + header_prefix); got_pathlist_free(&paths, GOT_PATHLIST_FREE_ALL); + + if (worktree == NULL) + printf("work tree: %.*s\n\n", + GOT_WORKTREE_UUID_STRLEN, wt); } if (err || found) goto done; @@ -10657,7 +10673,7 @@ print_backup_ref(const char *branch_name, const char * return got_error_from_errno("asprintf"); err = print_commit(old_commit, old_commit_id, repo, NULL, NULL, NULL, - 0, 0, refs_idmap, custom_refs_str); + 0, 0, refs_idmap, custom_refs_str, NULL); if (err) goto done; blob - bf66824996f21369543f644f760e178198b0d78a blob + 1a217d6ed3b9754e118aea878d1450e35c34790d --- regress/cmdline/backout.sh +++ regress/cmdline/backout.sh @@ -290,7 +290,7 @@ test_backout_logmsg_ref() { for r in $sorted; do echo $sep >> $testroot/stdout.expected if [ $r == $branch_rev ]; then - echo "commit $r" >> $testroot/stdout.expected + echo "backout $r" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date" >> $testroot/stdout.expected printf " \n $logmsg\n \n" >> $testroot/stdout.expected @@ -300,7 +300,7 @@ test_backout_logmsg_ref() { echo "Deleted: $ymd $short_id $logmsg" >> \ $testroot/stdout.wt_deleted else - echo "commit $r (newbranch)" \ + echo "backout $r (newbranch)" \ >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date2" >> $testroot/stdout.expected @@ -325,7 +325,7 @@ test_backout_logmsg_ref() { # only show log message ref of the specified commit id echo $sep > $testroot/stdout.expected - echo "commit $branch_rev" >> $testroot/stdout.expected + echo "backout $branch_rev" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date" >> $testroot/stdout.expected printf " \n $logmsg\n \n" >> $testroot/stdout.expected @@ -343,7 +343,7 @@ test_backout_logmsg_ref() { # only show log message ref of the specified symref echo $sep > $testroot/stdout.expected - echo "commit $branch_rev2 (newbranch)" >> $testroot/stdout.expected + echo "backout $branch_rev2 (newbranch)" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date2" >> $testroot/stdout.expected printf " \n $logmsg2\n \n" >> $testroot/stdout.expected @@ -400,7 +400,7 @@ test_backout_logmsg_ref() { for r in $sorted; do echo $sep >> $testroot/stdout.expected if [ $r == $branch2_rev ]; then - echo "commit $r" >> $testroot/stdout.expected + echo "backout $r" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date" >> $testroot/stdout.expected printf " \n $b2_logmsg\n \n" >> \ @@ -408,7 +408,7 @@ test_backout_logmsg_ref() { printf "$b2_changeset\n\n" >> \ $testroot/stdout.expected else - echo "commit $r (newbranch2)" \ + echo "backout $r (newbranch2)" \ >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date2" >> $testroot/stdout.expected @@ -435,10 +435,10 @@ test_backout_logmsg_ref() { echo -n > $testroot/stdout.expected for r in $sorted; do - echo "commit $r" >> $testroot/stdout.expected + echo "backout $r" >> $testroot/stdout.expected done - (cd $testroot/repo && got backout -l | grep ^commit | \ + (cd $testroot/repo && got backout -l | grep ^backout | \ sort | cut -f1,2 -d' ' > $testroot/stdout) cmp -s $testroot/stdout.expected $testroot/stdout @@ -490,7 +490,7 @@ test_backout_logmsg_ref() { # make sure the remaining ref in work tree 2 was not also deleted echo $sep > $testroot/stdout.expected - echo "commit $branch2_rev2 (newbranch2)" >> $testroot/stdout.expected + echo "backout $branch2_rev2 (newbranch2)" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date2" >> $testroot/stdout.expected printf " \n $b2_logmsg2\n \n" >> $testroot/stdout.expected blob - 1ebdbbbe9c9da6b114aecf7543f38a54648be240 blob + 7ce30882e48e407037b62ad30b23c7a28138d709 --- regress/cmdline/cherrypick.sh +++ regress/cmdline/cherrypick.sh @@ -1773,7 +1773,7 @@ test_cherrypick_logmsg_ref() { for r in $sorted; do echo $sep >> $testroot/stdout.expected if [ $r == $branch_rev ]; then - echo "commit $r" >> $testroot/stdout.expected + echo "cherrypick $r" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date" >> $testroot/stdout.expected printf " \n $logmsg\n \n" >> $testroot/stdout.expected @@ -1783,7 +1783,7 @@ test_cherrypick_logmsg_ref() { echo "Deleted: $ymd $short_id $logmsg" >> \ $testroot/stdout.wt_deleted else - echo "commit $r (newbranch)" \ + echo "cherrypick $r (newbranch)" \ >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date2" >> $testroot/stdout.expected @@ -1808,7 +1808,7 @@ test_cherrypick_logmsg_ref() { # only show log message ref of the specified commit id echo $sep > $testroot/stdout.expected - echo "commit $branch_rev" >> $testroot/stdout.expected + echo "cherrypick $branch_rev" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date" >> $testroot/stdout.expected printf " \n $logmsg\n \n" >> $testroot/stdout.expected @@ -1826,7 +1826,7 @@ test_cherrypick_logmsg_ref() { # only show log message ref of the specified symref echo $sep > $testroot/stdout.expected - echo "commit $branch_rev2 (newbranch)" >> $testroot/stdout.expected + echo "cherrypick $branch_rev2 (newbranch)" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date2" >> $testroot/stdout.expected printf " \n $logmsg2\n \n" >> $testroot/stdout.expected @@ -1883,7 +1883,7 @@ test_cherrypick_logmsg_ref() { for r in $sorted; do echo $sep >> $testroot/stdout.expected if [ $r == $branch2_rev ]; then - echo "commit $r" >> $testroot/stdout.expected + echo "cherrypick $r" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date" >> $testroot/stdout.expected printf " \n $b2_logmsg\n \n" >> \ @@ -1891,7 +1891,7 @@ test_cherrypick_logmsg_ref() { printf "$b2_changeset\n\n" >> \ $testroot/stdout.expected else - echo "commit $r (newbranch2)" \ + echo "cherrypick $r (newbranch2)" \ >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date2" >> $testroot/stdout.expected @@ -1918,10 +1918,10 @@ test_cherrypick_logmsg_ref() { echo -n > $testroot/stdout.expected for r in $sorted; do - echo "commit $r" >> $testroot/stdout.expected + echo "cherrypick $r" >> $testroot/stdout.expected done - (cd $testroot/repo && got cherrypick -l | grep ^commit | \ + (cd $testroot/repo && got cherrypick -l | grep ^cherrypick | \ sort | cut -f1,2 -d' ' > $testroot/stdout) cmp -s $testroot/stdout.expected $testroot/stdout @@ -1973,7 +1973,8 @@ test_cherrypick_logmsg_ref() { # make sure the remaining ref in work tree 2 was not also deleted echo $sep > $testroot/stdout.expected - echo "commit $branch2_rev2 (newbranch2)" >> $testroot/stdout.expected + echo "cherrypick $branch2_rev2 (newbranch2)" \ + >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $date2" >> $testroot/stdout.expected printf " \n $b2_logmsg2\n \n" >> $testroot/stdout.expected blob - 24876c31156bd39c9ccd57d65af7994f9fcf4d75 blob + f3efa2956540364485d477c0e81fdc4c4fc43de6 --- regress/cmdline/commit.sh +++ regress/cmdline/commit.sh @@ -1915,7 +1915,7 @@ EOF # confirm logmsg ref was not deleted with got cherrypick -l echo "-----------------------------------------------" \ > $testroot/stdout.expected - echo "commit $branch_rev (newbranch)" >> $testroot/stdout.expected + echo "cherrypick $branch_rev (newbranch)" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected echo "date: $d" >> $testroot/stdout.expected echo " " >> $testroot/stdout.expected