@matheusbsbs / matheus-bagliano / commits / 72c69ebc03
Fork 0

git commit: Reformat output somewhat

Previously, we used to print something along the lines of Created commit abc9056 on master: Snib the sprock but that output was sometimes confusing, as many projects use the "subsystem: message" style of commit subjects (just like this commit message does). When such improvements are done on topic-branches, it's not uncommon to name the topic-branch the same as the subsystem, leading to output like this: Created commit abc9056 on i386: i386: Snib the sprock which doesn't look very nice and can be highly confusing. This patch alters the format so that the noise-word "commit" is dropped except when it makes the output read better and the commit subject is put inside parentheses. We also emphasize the detached case so that users do not overlook it in case the commit subject is long enough to extend to the next line. The end result looks thusly: normal case Created abc9056 (i386: Snib the sprock) on i386 detached head Created DETACHED commit abc9056 (i386: Snib the sprock) While we're at it, we rename "initial commit" to "root-commit" to align it with the argument to 'git log', producing this: initial commit Created root-commit abc9056 (i386: Snib the sprock) on i386 Documentation/gittutorial-2.txt is updated accordingly so that new users recognize what they're looking at. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Andreas Ericsson committed Sep 30, 2008 at 11:52 UTC 72c69ebc035efe08aef03866184aa9b344814d93
2 files changed +13 -12
Documentation/gittutorial-2.txt
+8 -5
@@ -32,22 +32,25 @@ Initialized empty Git repository in .git/
32 $ echo 'hello world' > file.txt
33 $ git add .
34 $ git commit -a -m "initial commit"
35 -Created initial commit 54196cc2703dc165cbd373a65a4dcf22d50ae7f7
35 +Created root-commit 54196cc (initial commit) on master
36 create mode 100644 file.txt
37 $ echo 'hello world!' >file.txt
38 $ git commit -a -m "add emphasis"
39 -Created commit c4d59f390b9cfd4318117afde11d601c1085f241
39 +Created c4d59f3 (add emphasis) on master
40 ------------------------------------------------
41
42 -What are the 40 digits of hex that git responded to the commit with?
42 +What are the 7 digits of hex that git responded to the commit with?
43
44 We saw in part one of the tutorial that commits have names like this.
45 It turns out that every object in the git history is stored under
46 -such a 40-digit hex name. That name is the SHA1 hash of the object's
46 +a 40-digit hex name. That name is the SHA1 hash of the object's
47 contents; among other things, this ensures that git will never store
48 the same data twice (since identical data is given an identical SHA1
49 name), and that the contents of a git object will never change (since
50 -that would change the object's name as well).
50 +that would change the object's name as well). The 7 char hex strings
51 +here are simply the abbreviation of such 40 character long strings.
52 +Abbreviations can be used everywhere where the 40 character strings
53 +can be used, so long as they are unambiguous.
54
55 It is expected that the content of the commit object you created while
56 following the example above generates a different SHA1 hash than
builtin-commit.c
+5 -7
@@ -884,12 +884,11 @@ static char *get_commit_format_string(void)
884 const char *head = resolve_ref("HEAD", sha, 0, NULL);
885 struct strbuf buf = STRBUF_INIT;
886
887 - strbuf_addstr(&buf, "format:%h");
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
889 - /* Are we on a detached HEAD? */
890 - if (!strcmp("HEAD", head))
891 - strbuf_addstr(&buf, " on detached HEAD");
892 - else if (!prefixcmp(head, "refs/heads/")) {
891 + if (!prefixcmp(head, "refs/heads/")) {
892 const char *cp;
893 strbuf_addstr(&buf, " on ");
894 for (cp = head + 11; *cp; cp++) {
@@ -899,7 +898,6 @@ static char *get_commit_format_string(void)
898 strbuf_addch(&buf, *cp);
899 }
900 }
902 - strbuf_addstr(&buf, ": %s");
901
902 return strbuf_detach(&buf, NULL);
903 }
@@ -933,7 +931,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
931 rev.diffopt.break_opt = 0;
932 diff_setup_done(&rev.diffopt);
933
936 - printf("Created %scommit ", initial_commit ? "initial " : "");
934 + printf("Created %s", initial_commit ? "root-commit " : "");
935
936 if (!log_tree_commit(&rev, commit)) {
937 struct strbuf buf = STRBUF_INIT;