From: Andreas Ericsson <ae@op5.se>
To: Shawn Pearce <spearce@spearce.org>,
Git Mailing List <git@vger.kernel.org>, Jeff King <peff@peff.net>
Subject: [PATCH] git commit: Repaint the output format bikeshed (again)
Date: Wed, 01 Oct 2008 23:06:54 +0200 [thread overview]
Message-ID: <48E3E66E.7020501@op5.se> (raw)
In-Reply-To: <20081001154425.GE21310@spearce.org>
Since we want the most important information furthest
left while at the same time preserving valuable screen
estate, we move the branch-name to the leftmost side
of the commit result output. To make it read properly
we get rid of "Created", which I just can't fit into
a sentence without putting the branch-name last.
Having taken inspiration from the "git reset" command,
output for the three conceivable cases now look thus:
normal commit
<branch> is now at b930c4a (i386: Snib the sprock)
detached commit
DETACHED HEAD is now at b930c4a (i386: Snib the sprock)
initial commit
History has begun anew. Root-commit created.
<branch> is now at bc930c4a (i386: Snib the sprock)
As a nice side-effect, we can get rid of the get_commit_format
helper function and thereby remove more code than we add.
This is a substantial rewrite of a patch originally sent by
Jeff King <peff@peff.net>.
Signed-off-by: Andreas Ericsson <ae@op5.se>
---
"Created" is a problem when one wants to put branch-name before the
subject line, because the subject has to follow the hash (it doesn't
describe the pre-state of the branch/detached head), but the newly
added commit. "Created, on branch, hash (subject)" just looks
stilted and stupid, so I had to change it. Hopefully this can be
accepted. If not, count me out.
I'm not sure if the last "else" case setting branch = head; can
ever happen, but I figured it can't hurt to make sure. Feel free
to modify commentary around it or the entire section when applying.
This is based on current next (798a2a426a).
builtin-commit.c | 47 ++++++++++++++++++-----------------------------
1 files changed, 18 insertions(+), 29 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index e4e1448..3b43344 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -878,35 +878,12 @@ int cmd_status(int argc, const char **argv, const char *prefix)
return commitable ? 0 : 1;
}
-static char *get_commit_format_string(void)
-{
- unsigned char sha[20];
- const char *head = resolve_ref("HEAD", sha, 0, NULL);
- struct strbuf buf = STRBUF_INIT;
-
- /* use shouty-caps if we're on detached HEAD */
- strbuf_addf(&buf, "format:%s", strcmp("HEAD", head) ? "" : "DETACHED commit");
- strbuf_addstr(&buf, "%h (%s)");
-
- if (!prefixcmp(head, "refs/heads/")) {
- const char *cp;
- strbuf_addstr(&buf, " on ");
- for (cp = head + 11; *cp; cp++) {
- if (*cp == '%')
- strbuf_addstr(&buf, "%x25");
- else
- strbuf_addch(&buf, *cp);
- }
- }
-
- return strbuf_detach(&buf, NULL);
-}
-
static void print_summary(const char *prefix, const unsigned char *sha1)
{
struct rev_info rev;
struct commit *commit;
- char *format = get_commit_format_string();
+ unsigned char head_sha1[20];
+ const char *branch, *head, *format = "format:%h (%s)";
commit = lookup_commit(sha1);
if (!commit)
@@ -931,15 +908,27 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
rev.diffopt.break_opt = 0;
diff_setup_done(&rev.diffopt);
- printf("Created %s", initial_commit ? "root-commit " : "");
+ /* a pretty rare occurrance, so let's celebrate it specially */
+ if (initial_commit)
+ printf("History has begun anew. Root-commit created.\n");
+
+ head = resolve_ref("HEAD", head_sha1, 0, NULL);
+ if (!strcmp(head, "HEAD"))
+ branch = "DETACHED HEAD";
+ else if (!prefixcmp(head, "refs/heads/"))
+ branch = &head[strlen("refs/heads/")];
+ else {
+ /* refs/git-svn, fe */
+ branch = head;
+ }
+
+ printf("%s is now at ", branch);
if (!log_tree_commit(&rev, commit)) {
struct strbuf buf = STRBUF_INIT;
format_commit_message(commit, format + 7, &buf, DATE_NORMAL);
- printf("%s\n", buf.buf);
- strbuf_release(&buf);
+ printf("%s\n", strbuf_detach(&buf, NULL));
}
- free(format);
}
static int git_commit_config(const char *k, const char *v, void *cb)
--
1.6.0.2.529.g37dbc.dirty
next prev parent reply other threads:[~2008-10-01 21:08 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 ` [PATCH] git commit: Reformat output somewhat Andreas Ericsson
2008-09-30 6:37 ` [PATCH] Builtin-commit: show on which branch a commit was added 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 ` Andreas Ericsson [this message]
2008-10-01 22:06 ` [PATCH] git commit: Repaint the output format bikeshed (again) 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=48E3E66E.7020501@op5.se \
--to=ae@op5.se \
--cc=git@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).