builtin-commit.c: 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pieter de Bie committed
Sep 8, 2008 at 01:05 UTC
e502f9e7e6ceb8dfbdb94e2675355847740fc28f
1 file changed
+30
-2
builtin-commit.c
+30
-2
@@ -878,10 +878,37 @@ 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
+ strbuf_addstr(&buf, "format:%h");
888
+
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/")) {
893
+ const char *cp;
894
+ strbuf_addstr(&buf, " on ");
895
+ for (cp = head + 11; *cp; cp++) {
896
+ if (*cp == '%')
897
+ strbuf_addstr(&buf, "%x25");
898
+ else
899
+ strbuf_addch(&buf, *cp);
900
+ }
901
+ }
902
+ strbuf_addstr(&buf, ": %s");
903
+
904
+ return strbuf_detach(&buf, NULL);
905
+}
906
+
907
static void print_summary(const char *prefix, const unsigned char *sha1)
908
{
909
struct rev_info rev;
910
struct commit *commit;
911
+ char *format = get_commit_format_string();
912
913
commit = lookup_commit(sha1);
914
if (!commit)
@@ -899,7 +926,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
926
927
rev.verbose_header = 1;
928
rev.show_root_diff = 1;
902
- get_commit_format("format:%h: %s", &rev);
929
+ get_commit_format(format, &rev);
930
rev.always_show_header = 0;
931
rev.diffopt.detect_rename = 1;
932
rev.diffopt.rename_limit = 100;
@@ -910,10 +937,11 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
937
938
if (!log_tree_commit(&rev, commit)) {
939
struct strbuf buf = STRBUF_INIT;
913
- format_commit_message(commit, "%h: %s", &buf, DATE_NORMAL);
940
+ format_commit_message(commit, format + 7, &buf, DATE_NORMAL);
941
printf("%s\n", buf.buf);
942
strbuf_release(&buf);
943
}
944
+ free(format);
945
}
946
947
static int git_commit_config(const char *k, const char *v, void *cb)