@matheusbsbs / matheus-bagliano / commits / c85db254d9
Fork 0

reformat informational commit message

When committing, we print a message like: Created [DETACHED commit] <hash> (<subject>) on <branch> The most useful bit of information there (besides the detached status, if it is present) is which branch you made the commit on. However, it is sometimes hard to see because the subject dominates the line. Instead, let's put the most useful information (detached status and commit branch) on the far left, with the subject (which is least likely to be interesting) on the far right. We'll use brackets to offset the branch name so the line is not mistaken for an error line of the form "program: some sort of error". E.g.,: [jk/bikeshed] created bd8098f: "reformat informational commit message" Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Jeff King committed Oct 1, 2008 at 18:31 UTC c85db254d9d3309bb330444385dbb3b7be5100d3
1 file changed +10 -27
builtin-commit.c
+10 -27
@@ -878,35 +878,13 @@ int cmd_status(int argc, const char **argv, const char *prefix)
878 return commitable ? 0 : 1;
879 }
880
881 -static char *get_commit_format_string(void)
882 -{
883 - unsigned char sha[20];
884 - const char *head = resolve_ref("HEAD", sha, 0, NULL);
885 - struct strbuf buf = STRBUF_INIT;
886 -
887 - /* use shouty-caps if we're on detached HEAD */
888 - strbuf_addf(&buf, "format:%s", strcmp("HEAD", head) ? "" : "DETACHED commit");
889 - strbuf_addstr(&buf, "%h (%s)");
890 -
891 - if (!prefixcmp(head, "refs/heads/")) {
892 - const char *cp;
893 - strbuf_addstr(&buf, " on ");
894 - for (cp = head + 11; *cp; cp++) {
895 - if (*cp == '%')
896 - strbuf_addstr(&buf, "%x25");
897 - else
898 - strbuf_addch(&buf, *cp);
899 - }
900 - }
901 -
902 - return strbuf_detach(&buf, NULL);
903 -}
904 -
881 static void print_summary(const char *prefix, const unsigned char *sha1)
882 {
883 struct rev_info rev;
884 struct commit *commit;
909 - char *format = get_commit_format_string();
885 + static const char *format = "format:%h: \"%s\"";
886 + unsigned char junk_sha1[20];
887 + const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
888
889 commit = lookup_commit(sha1);
890 if (!commit)
@@ -931,7 +909,13 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
909 rev.diffopt.break_opt = 0;
910 diff_setup_done(&rev.diffopt);
911
934 - printf("Created %s", initial_commit ? "root-commit " : "");
912 + printf("[%s%s]: created ",
913 + !prefixcmp(head, "refs/heads/") ?
914 + head + 11 :
915 + !strcmp(head, "HEAD") ?
916 + "detached HEAD" :
917 + head,
918 + initial_commit ? " (root-commit)" : "");
919
920 if (!log_tree_commit(&rev, commit)) {
921 struct strbuf buf = STRBUF_INIT;
@@ -939,7 +923,6 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
923 printf("%s\n", buf.buf);
924 strbuf_release(&buf);
925 }
942 - free(format);
926 }
927
928 static int git_commit_config(const char *k, const char *v, void *cb)