All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Ericsson <ae@op5.se>
To: Pieter de Bie <pdebie@ai.rug.nl>, Jeff King <peff@peff.net>,
	Git Mailing List <git@vger.kernel.org>,
	Shawn Pearce <spearce@spearce.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] git commit: Reformat output somewhat
Date: Tue, 30 Sep 2008 11:52:50 +0200	[thread overview]
Message-ID: <48E1F6F2.5080302@op5.se> (raw)
In-Reply-To: <20080930061654.GA14584@sigill.intra.peff.net>

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>
---

According to the few entries in the discussion about showing the
branch we're on, this patch should probably go on top of next
fairly soon.

If the code-change isn't accepted, let me know and I'll fix the
documentation update to match whatever goes in builtin-commit.c.

Feel free to alter shouty-caps for detached when applying. I have
no strong opinion either way, as I never commit on detached head
anyway.

Thanks.

 Documentation/gittutorial-2.txt |   13 ++++++++-----
 builtin-commit.c                |   12 +++++-------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/Documentation/gittutorial-2.txt b/Documentation/gittutorial-2.txt
index 6609046..8484e7a 100644
--- a/Documentation/gittutorial-2.txt
+++ b/Documentation/gittutorial-2.txt
@@ -32,22 +32,25 @@ Initialized empty Git repository in .git/
 $ echo 'hello world' > file.txt
 $ git add .
 $ git commit -a -m "initial commit"
-Created initial commit 54196cc2703dc165cbd373a65a4dcf22d50ae7f7
+Created root-commit 54196cc (initial commit) on master
  create mode 100644 file.txt
 $ echo 'hello world!' >file.txt
 $ git commit -a -m "add emphasis"
-Created commit c4d59f390b9cfd4318117afde11d601c1085f241
+Created c4d59f3 (add emphasis) on master
 ------------------------------------------------
 
-What are the 40 digits of hex that git responded to the commit with?
+What are the 7 digits of hex that git responded to the commit with?
 
 We saw in part one of the tutorial that commits have names like this.
 It turns out that every object in the git history is stored under
-such a 40-digit hex name.  That name is the SHA1 hash of the object's
+a 40-digit hex name.  That name is the SHA1 hash of the object's
 contents; among other things, this ensures that git will never store
 the same data twice (since identical data is given an identical SHA1
 name), and that the contents of a git object will never change (since
-that would change the object's name as well).
+that would change the object's name as well). The 7 char hex strings
+here are simply the abbreviation of such 40 character long strings.
+Abbreviations can be used everywhere where the 40 character strings
+can be used, so long as they are unambiguous.
 
 It is expected that the content of the commit object you created while
 following the example above generates a different SHA1 hash than
diff --git a/builtin-commit.c b/builtin-commit.c
index 161128b..f0765cc 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -884,12 +884,11 @@ static char *get_commit_format_string(void)
 	const char *head = resolve_ref("HEAD", sha, 0, NULL);
 	struct strbuf buf = STRBUF_INIT;
 
-	strbuf_addstr(&buf, "format:%h");
+	/* use shouty-caps if we're on detached HEAD */
+	strbuf_addf(&buf, "format:%s", strcmp("HEAD", head) ? "" : "DETACHED commit");
+	strbuf_addstr(&buf, "%h (%s)");
 
-	/* Are we on a detached HEAD? */
-	if (!strcmp("HEAD", head))
-		strbuf_addstr(&buf, " on detached HEAD");
-	else if (!prefixcmp(head, "refs/heads/")) {
+	if (!prefixcmp(head, "refs/heads/")) {
 		const char *cp;
 		strbuf_addstr(&buf, " on ");
 		for (cp = head + 11; *cp; cp++) {
@@ -899,7 +898,6 @@ static char *get_commit_format_string(void)
 				strbuf_addch(&buf, *cp);
 		}
 	}
-	strbuf_addstr(&buf, ": %s");
 
 	return strbuf_detach(&buf, NULL);
 }
@@ -933,7 +931,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
 	rev.diffopt.break_opt = 0;
 	diff_setup_done(&rev.diffopt);
 
-	printf("Created %scommit ", initial_commit ? "initial " : "");
+	printf("Created %s", initial_commit ? "root-commit " : "");
 
 	if (!log_tree_commit(&rev, commit)) {
 		struct strbuf buf = STRBUF_INIT;
-- 
1.6.0.2.529.g37dbc.dirty

  parent reply	other threads:[~2008-09-30  9:54 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-02 19:31 [RFC] Detached-HEAD reminder on commit? Pieter de Bie
2008-09-02 19:43 ` Robin Rosenberg
2008-09-02 20:24 ` Nicolas Pitre
2008-09-02 20:26 ` Matthieu Moy
2008-09-02 20:35   ` Nicolas Pitre
2008-09-02 20:39 ` Junio C Hamano
2008-09-02 21:05   ` Stephan Beyer
2008-09-02 21:39     ` Johan Herland
2008-09-02 21:44       ` Jeff King
2008-09-02 21:51         ` Jeff King
2008-09-03  7:45         ` Johan Herland
2008-09-03  8:07           ` Junio C Hamano
2008-09-03  9:47             ` Johan Herland
2008-09-03 13:15           ` Jeff King
2008-09-03 13:34             ` Jeff King
2008-09-03 13:46               ` Andreas Ericsson
2008-09-03 16:49               ` Daniel Barkalow
2008-09-03 18:07                 ` Jeff King
2008-09-03 19:36                   ` Junio C Hamano
2008-09-03 19:41                     ` Jeff King
2008-09-03 14:11             ` Wincent Colaiuta
2008-09-03 18:08               ` Jeff King
2008-09-03 15:16           ` Nicolas Pitre
2008-09-02 21:58       ` Junio C Hamano
2008-09-02 22:53       ` Nicolas Pitre
2008-09-04  4:50         ` Avery Pennarun
2008-09-04  5:31           ` Junio C Hamano
2008-09-05 23:43             ` Junio C Hamano
2008-09-02 21:51     ` Pieter de Bie
2008-09-02 22:11       ` Jakub Narebski
2008-09-02 22:50         ` Junio C Hamano
2008-09-02 22:58           ` Nicolas Pitre
2008-09-03 11:27       ` Pieter de Bie
2008-09-05 17:13         ` [PATCH] Builtin-commit: show on which branch a commit was added Pieter de Bie
2008-09-07  5:27           ` Junio C Hamano
2008-09-07  5:59             ` Junio C Hamano
2008-09-07 23:05               ` [PATCH 1/2] pretty.c: add %% format specifier Pieter de Bie
2008-09-07 23:05                 ` [PATCH 2/2] builtin-commit: show on which branch a commit was added Pieter de Bie
2008-09-21 10:42             ` [PATCH] Builtin-commit: " Jeff King
2008-09-29 20:09               ` Pieter de Bie
2008-09-29 22:44                 ` Jeff King
2008-09-30  6:13                   ` Andreas Ericsson
2008-09-30  6:16                     ` Jeff King
2008-09-30  9:45                       ` Andreas Ericsson
2008-09-30  9:52                       ` Andreas Ericsson [this message]
2008-09-30  6:37                     ` Wincent Colaiuta
2008-09-30  7:09                       ` Jeff King
2008-09-30  9:59                         ` Andreas Ericsson
2008-10-01  3:14                           ` Jeff King
2008-10-01  8:13                             ` Andreas Ericsson
2008-10-01 15:10                               ` Shawn O. Pearce
2008-10-01 15:22                                 ` Andreas Ericsson
2008-10-01 15:25                                 ` Jeff King
2008-10-01 15:36                                   ` Shawn O. Pearce
2008-10-01 15:42                                     ` Jeff King
2008-10-01 15:44                                       ` Shawn O. Pearce
2008-10-01 21:06                                         ` [PATCH] git commit: Repaint the output format bikeshed (again) Andreas Ericsson
2008-10-01 22:06                                           ` Jeff King
2008-10-01 22:31                                             ` Jeff King
2008-10-02  5:40                                               ` Andreas Ericsson
2008-10-02 21:13                                                 ` Jeff King
2008-10-03  0:15                                                   ` Shawn O. Pearce
2008-10-03  4:24                                                     ` Jeff King
2008-10-03 14:09                                                       ` Shawn O. Pearce
2008-10-04  2:13                                                         ` Jeff King
2008-10-02  8:36                                             ` Wincent Colaiuta
2008-10-01 15:18                               ` [PATCH] Builtin-commit: show on which branch a commit was added Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48E1F6F2.5080302@op5.se \
    --to=ae@op5.se \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pdebie@ai.rug.nl \
    --cc=peff@peff.net \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.