Created
September 5, 2008 17:13
-
-
Save pieter/8994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From f5e52704c59ae43f53dace0df063b7c386159aee Mon Sep 17 00:00:00 2001 | |
From: Pieter de Bie <pdebie@ai.rug.nl> | |
Date: Tue, 2 Sep 2008 21:05:48 +0200 | |
Subject: [PATCH] Builtin-commit: show on which branch a commit was added | |
This outputs the current branch on which a commit was created, just for | |
reference. For example: | |
Created commit 6d42875 on master: Fix submodule invalid command error | |
This also reminds the committer when he is on a detached HEAD: | |
Created commit 02a7172 on detached HEAD: Also do this for 'git commit --amend' | |
Signed-off-by: Pieter de Bie <pdebie@ai.rug.nl> | |
--- | |
builtin-commit.c | 26 ++++++++++++++++++++++++-- | |
1 files changed, 24 insertions(+), 2 deletions(-) | |
diff --git a/builtin-commit.c b/builtin-commit.c | |
index 8165bb3..a82483d 100644 | |
--- a/builtin-commit.c | |
+++ b/builtin-commit.c | |
@@ -878,10 +878,31 @@ int cmd_status(int argc, const char **argv, const char *prefix) | |
return commitable ? 0 : 1; | |
} | |
+static char* get_commit_format_string() | |
+{ | |
+ unsigned char sha[20]; | |
+ const char* head = resolve_ref("HEAD", sha, 0, NULL); | |
+ struct strbuf buf = STRBUF_INIT; | |
+ | |
+ strbuf_addstr(&buf, "format:%h"); | |
+ | |
+ /* Are we on a detached HEAD? */ | |
+ if (!strcmp("HEAD", head)) | |
+ strbuf_addstr(&buf, " on detached HEAD"); | |
+ else if (!prefixcmp(head, "refs/heads/")) { | |
+ strbuf_addstr(&buf, " on "); | |
+ strbuf_addstr(&buf, head + 11); | |
+ } | |
+ strbuf_addstr(&buf, ": %s"); | |
+ | |
+ return buf.buf; | |
+} | |
+ | |
static void print_summary(const char *prefix, const unsigned char *sha1) | |
{ | |
struct rev_info rev; | |
struct commit *commit; | |
+ char* format = get_commit_format_string(); | |
commit = lookup_commit(sha1); | |
if (!commit) | |
@@ -899,7 +920,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1) | |
rev.verbose_header = 1; | |
rev.show_root_diff = 1; | |
- get_commit_format("format:%h: %s", &rev); | |
+ get_commit_format(format, &rev); | |
rev.always_show_header = 0; | |
rev.diffopt.detect_rename = 1; | |
rev.diffopt.rename_limit = 100; | |
@@ -910,10 +931,11 @@ static void print_summary(const char *prefix, const unsigned char *sha1) | |
if (!log_tree_commit(&rev, commit)) { | |
struct strbuf buf = STRBUF_INIT; | |
- format_commit_message(commit, "%h: %s", &buf, DATE_NORMAL); | |
+ format_commit_message(commit, format + 7, &buf, DATE_NORMAL); | |
printf("%s\n", buf.buf); | |
strbuf_release(&buf); | |
} | |
+ free(format); | |
} | |
static int git_commit_config(const char *k, const char *v, void *cb) | |
-- | |
1.6.0.1.346.g880d9.dirty | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment