{"thread":{"id":"13344","subject":"[PATCHv2 0/3] Show author and/or committer in some cases","startedAt":"2008-05-01T12:09:32Z","lastAt":"2008-05-01T12:18:37Z","messageCount":5,"participants":["Santi Béjar"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"75744","messageId":"1209643775-2362-1-git-send-email-sbejar@gmail.com","threadId":"13344","inReplyTo":null,"subject":"[PATCHv2 0/3] Show author and/or committer in some cases","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2008-05-01T12:09:32Z","receivedAt":"2008-05-01T12:09:32Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"Hi *,\n\n  This patch series tries to make more evident the author and committer ident\nused in a commit trying to minimize when it is shown.\n\nChanges since v1:\n\n- Add blank line before and after Author/Committer lines,\n  but not beetween\n- Fix for the initial commit, thanks to Jeff\n- Only show the committer if not set with the user.* configs.\n\nSanti\n\nSanti BÃ©jar (3):\n  Preparation to call determine_author_info from prepare_to_commit\n  commit: Show author if different from committer\n  commit: Show committer if different from the parent and automatic\n\n builtin-commit.c  |  135 +++++++++++++++++++++++++++++++++++++----------------\n cache.h           |    1 +\n config.c          |    4 ++\n environment.c     |    1 +\n t/t7502-commit.sh |   23 +++++++++\n 5 files changed, 124 insertions(+), 40 deletions(-)\n"},{"id":"75746","messageId":"1209643775-2362-2-git-send-email-sbejar@gmail.com","threadId":"13344","inReplyTo":"1209643775-2362-1-git-send-email-sbejar@gmail.com","subject":"[PATCHv2 1/3] Preparation to call determine_author_info from prepare_to_commit","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2008-05-01T12:09:33Z","receivedAt":"2008-05-01T12:09:33Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"From: Santi Béjar <sbjear@gmail.com>\n\nReorder functions definitions such that determine_author_info is\ndefined before prepare_to_commit. No code changes.\n\nSigned-off-by: Santi Béjar <sbejar@gmail.com>\n---\n builtin-commit.c |   78 +++++++++++++++++++++++++++---------------------------\n 1 files changed, 39 insertions(+), 39 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 256181a..a37d8c3 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -395,6 +395,45 @@ static int is_a_merge(const unsigned char *sha1)\n \n static const char sign_off_header[] = \"Signed-off-by: \";\n \n+static void determine_author_info(struct strbuf *sb)\n+{\n+\tchar *name, *email, *date;\n+\n+\tname = getenv(\"GIT_AUTHOR_NAME\");\n+\temail = getenv(\"GIT_AUTHOR_EMAIL\");\n+\tdate = getenv(\"GIT_AUTHOR_DATE\");\n+\n+\tif (use_message) {\n+\t\tconst char *a, *lb, *rb, *eol;\n+\n+\t\ta = strstr(use_message_buffer, \"\\nauthor \");\n+\t\tif (!a)\n+\t\t\tdie(\"invalid commit: %s\", use_message);\n+\n+\t\tlb = strstr(a + 8, \" <\");\n+\t\trb = strstr(a + 8, \"> \");\n+\t\teol = strchr(a + 8, '\\n');\n+\t\tif (!lb || !rb || !eol)\n+\t\t\tdie(\"invalid commit: %s\", use_message);\n+\n+\t\tname = xstrndup(a + 8, lb - (a + 8));\n+\t\temail = xstrndup(lb + 2, rb - (lb + 2));\n+\t\tdate = xstrndup(rb + 2, eol - (rb + 2));\n+\t}\n+\n+\tif (force_author) {\n+\t\tconst char *lb = strstr(force_author, \" <\");\n+\t\tconst char *rb = strchr(force_author, '>');\n+\n+\t\tif (!lb || !rb)\n+\t\t\tdie(\"malformed --author parameter\");\n+\t\tname = xstrndup(force_author, lb - force_author);\n+\t\temail = xstrndup(lb + 2, rb - (lb + 2));\n+\t}\n+\n+\tstrbuf_addf(sb, \"author %s\\n\", fmt_ident(name, email, date, IDENT_ERROR_ON_NO_NAME));\n+}\n+\n static int prepare_to_commit(const char *index_file, const char *prefix)\n {\n \tstruct stat statbuf;\n@@ -622,45 +661,6 @@ static int message_is_empty(struct strbuf *sb, int start)\n \treturn 1;\n }\n \n-static void determine_author_info(struct strbuf *sb)\n-{\n-\tchar *name, *email, *date;\n-\n-\tname = getenv(\"GIT_AUTHOR_NAME\");\n-\temail = getenv(\"GIT_AUTHOR_EMAIL\");\n-\tdate = getenv(\"GIT_AUTHOR_DATE\");\n-\n-\tif (use_message) {\n-\t\tconst char *a, *lb, *rb, *eol;\n-\n-\t\ta = strstr(use_message_buffer, \"\\nauthor \");\n-\t\tif (!a)\n-\t\t\tdie(\"invalid commit: %s\", use_message);\n-\n-\t\tlb = strstr(a + 8, \" <\");\n-\t\trb = strstr(a + 8, \"> \");\n-\t\teol = strchr(a + 8, '\\n');\n-\t\tif (!lb || !rb || !eol)\n-\t\t\tdie(\"invalid commit: %s\", use_message);\n-\n-\t\tname = xstrndup(a + 8, lb - (a + 8));\n-\t\temail = xstrndup(lb + 2, rb - (lb + 2));\n-\t\tdate = xstrndup(rb + 2, eol - (rb + 2));\n-\t}\n-\n-\tif (force_author) {\n-\t\tconst char *lb = strstr(force_author, \" <\");\n-\t\tconst char *rb = strchr(force_author, '>');\n-\n-\t\tif (!lb || !rb)\n-\t\t\tdie(\"malformed --author parameter\");\n-\t\tname = xstrndup(force_author, lb - force_author);\n-\t\temail = xstrndup(lb + 2, rb - (lb + 2));\n-\t}\n-\n-\tstrbuf_addf(sb, \"author %s\\n\", fmt_ident(name, email, date, IDENT_ERROR_ON_NO_NAME));\n-}\n-\n static int parse_and_validate_options(int argc, const char *argv[],\n \t\t\t\t      const char * const usage[])\n {\n-- \n1.5.5.1.102.gfcc7d.dirty\n"},{"id":"75745","messageId":"1209643775-2362-3-git-send-email-sbejar@gmail.com","threadId":"13344","inReplyTo":"1209643775-2362-1-git-send-email-sbejar@gmail.com","subject":"[PATCHv2 2/3] commit: Show author if different from committer","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2008-05-01T12:09:34Z","receivedAt":"2008-05-01T12:09:34Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"That would help reassure anybody while committing other's changes.\n\nSigned-off-by: Santi Béjar <sbejar@gmail.com>\n---\n builtin-commit.c  |   25 ++++++++++++++++++++++---\n t/t7502-commit.sh |   11 +++++++++++\n 2 files changed, 33 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex a37d8c3..057749b 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -47,6 +47,7 @@ static enum {\n \n static char *logfile, *force_author, *template_file;\n static char *edit_message, *use_message;\n+static char *author_name, *author_email, *author_date;\n static int all, edit_flag, also, interactive, only, amend, signoff;\n static int quiet, verbose, untracked_files, no_verify, allow_empty;\n /*\n@@ -395,7 +396,7 @@ static int is_a_merge(const unsigned char *sha1)\n \n static const char sign_off_header[] = \"Signed-off-by: \";\n \n-static void determine_author_info(struct strbuf *sb)\n+static void determine_author_info()\n {\n \tchar *name, *email, *date;\n \n@@ -431,7 +432,9 @@ static void determine_author_info(struct strbuf *sb)\n \t\temail = xstrndup(lb + 2, rb - (lb + 2));\n \t}\n \n-\tstrbuf_addf(sb, \"author %s\\n\", fmt_ident(name, email, date, IDENT_ERROR_ON_NO_NAME));\n+\tauthor_name = name;\n+\tauthor_email = email;\n+\tauthor_date = date;\n }\n \n static int prepare_to_commit(const char *index_file, const char *prefix)\n@@ -443,6 +446,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \tFILE *fp;\n \tconst char *hook_arg1 = NULL;\n \tconst char *hook_arg2 = NULL;\n+\tconst char *author_ident;\n+\tconst char *committer_ident;\n \n \tif (!no_verify && run_hook(index_file, \"pre-commit\", NULL))\n \t\treturn 0;\n@@ -522,6 +527,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \n \tstrbuf_release(&sb);\n \n+\tdetermine_author_info();\n+\n \tif (use_editor) {\n \t\tif (in_merge)\n \t\t\tfprintf(fp,\n@@ -545,6 +552,17 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \t\tif (only_include_assumed)\n \t\t\tfprintf(fp, \"# %s\\n\", only_include_assumed);\n \n+\t\tauthor_ident = xstrdup(fmt_name(author_name, author_email));\n+\t\tcommitter_ident =\n+\t\t\txstrdup(fmt_name(getenv(\"GIT_COMMITTER_NAME\"),\n+\t\t\t\t\t getenv(\"GIT_COMMITTER_EMAIL\")));\n+\t\tif (strcmp(author_ident, committer_ident))\n+\t\t\tfprintf(fp,\n+\t\t\t\t\"#\\n\"\n+\t\t\t\t\"# Author:    %s\\n\"\n+\t\t\t\t\"#\\n\",\n+\t\t\t\tfmt_name(author_name, author_email));\n+\n \t\tsaved_color_setting = wt_status_use_color;\n \t\twt_status_use_color = 0;\n \t\tcommitable = run_status(fp, index_file, prefix, 1);\n@@ -920,7 +938,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tstrbuf_addf(&sb, \"parent %s\\n\", sha1_to_hex(head_sha1));\n \t}\n \n-\tdetermine_author_info(&sb);\n+\tstrbuf_addf(&sb, \"author %s\\n\",\n+\t\t    fmt_ident(author_name, author_email, author_date, IDENT_ERROR_ON_NO_NAME));\n \tstrbuf_addf(&sb, \"committer %s\\n\", git_committer_info(IDENT_ERROR_ON_NO_NAME));\n \tif (!is_encoding_utf8(git_commit_encoding))\n \t\tstrbuf_addf(&sb, \"encoding %s\\n\", git_commit_encoding);\ndiff --git a/t/t7502-commit.sh b/t/t7502-commit.sh\nindex 284c941..11de910 100755\n--- a/t/t7502-commit.sh\n+++ b/t/t7502-commit.sh\n@@ -154,6 +154,17 @@ test_expect_success 'cleanup commit messages (strip,-F,-e)' '\n \n '\n \n+echo \"#\n+# Author:    $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>\" >> expect\n+\n+test_expect_success 'author different from committer' '\n+\n+\techo >>negative &&\n+\tgit commit -e -m \"sample\"\n+\thead -n 6 .git/COMMIT_EDITMSG >actual &&\n+\ttest_cmp expect actual\n+'\n+\n pwd=`pwd`\n cat >> .git/FAKE_EDITOR << EOF\n #! /bin/sh\n-- \n1.5.5.1.102.gfcc7d.dirty\n"},{"id":"75747","messageId":"1209643775-2362-4-git-send-email-sbejar@gmail.com","threadId":"13344","inReplyTo":"1209643775-2362-1-git-send-email-sbejar@gmail.com","subject":"[PATCHv2 3/3] commit: Show committer if different from the parent and automatic","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2008-05-01T12:09:35Z","receivedAt":"2008-05-01T12:09:35Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"To remind the committer ident in case it is not what you want\n(taken from the gecos field, want to use different ident in\ndifferent repositories).\n\n[sb: thanks to Jeff King for the enhancement and fix to this patch]\n\nSigned-off-by: Santi Béjar <sbejar@gmail.com>\n---\n builtin-commit.c  |   42 +++++++++++++++++++++++++++++++++++++++---\n cache.h           |    1 +\n config.c          |    4 ++++\n environment.c     |    1 +\n t/t7502-commit.sh |   12 ++++++++++++\n 5 files changed, 57 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 057749b..3501ba7 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -437,6 +437,29 @@ static void determine_author_info()\n \tauthor_date = date;\n }\n \n+const char *get_parent_ident()\n+{\n+\tunsigned char sha1[20];\n+\tstruct commit *commit;\n+\tconst char *a, *lb, *rb, *eol;\n+\n+\n+\tget_sha1(\"HEAD\", sha1);\n+\tcommit = lookup_commit_reference(sha1);\n+\tif (!commit)\n+\t\treturn NULL;\n+\n+\ta = strstr(commit->buffer, \"\\ncommitter \");\n+\n+\tlb = strstr(a + 11, \" <\");\n+\trb = strstr(a + 11, \"> \");\n+\teol = strchr(a + 11, '\\n');\n+\tif (!lb || !rb || !eol)\n+\t\treturn NULL;\n+\n+\treturn xstrndup(a + 11, rb + 1 - (a + 11));\n+}\n+\n static int prepare_to_commit(const char *index_file, const char *prefix)\n {\n \tstruct stat statbuf;\n@@ -448,6 +471,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \tconst char *hook_arg2 = NULL;\n \tconst char *author_ident;\n \tconst char *committer_ident;\n+\tconst char *parent_ident;\n+\tint showed_ident = 0;\n \n \tif (!no_verify && run_hook(index_file, \"pre-commit\", NULL))\n \t\treturn 0;\n@@ -558,11 +583,22 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \t\t\t\t\t getenv(\"GIT_COMMITTER_EMAIL\")));\n \t\tif (strcmp(author_ident, committer_ident))\n \t\t\tfprintf(fp,\n-\t\t\t\t\"#\\n\"\n-\t\t\t\t\"# Author:    %s\\n\"\n-\t\t\t\t\"#\\n\",\n+\t\t\t\t\"%s\"\n+\t\t\t\t\"# Author:    %s\\n\",\n+\t\t\t\tshowed_ident++ ? \"\" : \"#\\n\",\n \t\t\t\tfmt_name(author_name, author_email));\n \n+\t\tparent_ident = get_parent_ident();\n+\t\tif (!user_explicit &&\n+\t\t    (!parent_ident || strcmp(parent_ident, committer_ident)))\n+\t\t\tfprintf(fp,\n+\t\t\t\t\"%s# Committer: %s\\n\",\n+\t\t\t\tshowed_ident++ ? \"\" : \"#\\n\",\n+\t\t\t\tcommitter_ident);\n+\n+\t\tif (showed_ident)\n+\t\t\tfprintf(fp, \"#\\n\");\n+\n \t\tsaved_color_setting = wt_status_use_color;\n \t\twt_status_use_color = 0;\n \t\tcommitable = run_status(fp, index_file, prefix, 1);\ndiff --git a/cache.h b/cache.h\nindex 3fcc283..941441a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -718,6 +718,7 @@ extern int config_error_nonbool(const char *);\n #define MAX_GITNAME (1000)\n extern char git_default_email[MAX_GITNAME];\n extern char git_default_name[MAX_GITNAME];\n+extern int user_explicit;\n \n extern const char *git_commit_encoding;\n extern const char *git_log_output_encoding;\ndiff --git a/config.c b/config.c\nindex b0ada51..e39df5b 100644\n--- a/config.c\n+++ b/config.c\n@@ -443,6 +443,8 @@ int git_default_config(const char *var, const char *value)\n \t\tif (!value)\n \t\t\treturn config_error_nonbool(var);\n \t\tstrlcpy(git_default_name, value, sizeof(git_default_name));\n+\t\tif (!git_default_email[0])\n+\t\t\tuser_explicit = 1;\n \t\treturn 0;\n \t}\n \n@@ -450,6 +452,8 @@ int git_default_config(const char *var, const char *value)\n \t\tif (!value)\n \t\t\treturn config_error_nonbool(var);\n \t\tstrlcpy(git_default_email, value, sizeof(git_default_email));\n+\t\tif (!git_default_name[0])\n+\t\t\tuser_explicit = 1;\n \t\treturn 0;\n \t}\n \ndiff --git a/environment.c b/environment.c\nindex 6739a3f..b941971 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -11,6 +11,7 @@\n \n char git_default_email[MAX_GITNAME];\n char git_default_name[MAX_GITNAME];\n+int user_explicit = 0;\n int trust_executable_bit = 1;\n int quote_path_fully = 1;\n int has_symlinks = 1;\ndiff --git a/t/t7502-commit.sh b/t/t7502-commit.sh\nindex 11de910..b1509a0 100755\n--- a/t/t7502-commit.sh\n+++ b/t/t7502-commit.sh\n@@ -165,6 +165,18 @@ test_expect_success 'author different from committer' '\n \ttest_cmp expect actual\n '\n \n+GIT_COMMITTER_NAME=\"C. O. Mitter\"\n+export GIT_COMMITTER_NAME\n+echo \"# Committer: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\" >> expect\n+\n+test_expect_success 'committer different from the parent committer' '\n+\n+\techo >>negative &&\n+\tgit commit -e -m \"sample\"\n+\thead -n 7 .git/COMMIT_EDITMSG >actual &&\n+\ttest_cmp expect actual\n+'\n+\n pwd=`pwd`\n cat >> .git/FAKE_EDITOR << EOF\n #! /bin/sh\n-- \n1.5.5.1.102.gfcc7d.dirty\n"},{"id":"75749","messageId":"1209644317-2480-1-git-send-email-sbejar@gmail.com","threadId":"13344","inReplyTo":"1209643775-2362-1-git-send-email-sbejar@gmail.com","subject":"[PATCHv2 1/3] Preparation to call determine_author_info from prepare_to_commit","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2008-05-01T12:18:37Z","receivedAt":"2008-05-01T12:18:37Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"Reorder functions definitions such that determine_author_info is\ndefined before prepare_to_commit. No code changes.\n\nSigned-off-by: Santi Béjar <sbejar@gmail.com>\n---\nHi *\n  somehow my email ended as sbjear instead of sbejar only in this patch.\n\n  Please use this mail.\n\n  Santi\n\n builtin-commit.c |   78 +++++++++++++++++++++++++++---------------------------\n 1 files changed, 39 insertions(+), 39 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 256181a..a37d8c3 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -395,6 +395,45 @@ static int is_a_merge(const unsigned char *sha1)\n \n static const char sign_off_header[] = \"Signed-off-by: \";\n \n+static void determine_author_info(struct strbuf *sb)\n+{\n+\tchar *name, *email, *date;\n+\n+\tname = getenv(\"GIT_AUTHOR_NAME\");\n+\temail = getenv(\"GIT_AUTHOR_EMAIL\");\n+\tdate = getenv(\"GIT_AUTHOR_DATE\");\n+\n+\tif (use_message) {\n+\t\tconst char *a, *lb, *rb, *eol;\n+\n+\t\ta = strstr(use_message_buffer, \"\\nauthor \");\n+\t\tif (!a)\n+\t\t\tdie(\"invalid commit: %s\", use_message);\n+\n+\t\tlb = strstr(a + 8, \" <\");\n+\t\trb = strstr(a + 8, \"> \");\n+\t\teol = strchr(a + 8, '\\n');\n+\t\tif (!lb || !rb || !eol)\n+\t\t\tdie(\"invalid commit: %s\", use_message);\n+\n+\t\tname = xstrndup(a + 8, lb - (a + 8));\n+\t\temail = xstrndup(lb + 2, rb - (lb + 2));\n+\t\tdate = xstrndup(rb + 2, eol - (rb + 2));\n+\t}\n+\n+\tif (force_author) {\n+\t\tconst char *lb = strstr(force_author, \" <\");\n+\t\tconst char *rb = strchr(force_author, '>');\n+\n+\t\tif (!lb || !rb)\n+\t\t\tdie(\"malformed --author parameter\");\n+\t\tname = xstrndup(force_author, lb - force_author);\n+\t\temail = xstrndup(lb + 2, rb - (lb + 2));\n+\t}\n+\n+\tstrbuf_addf(sb, \"author %s\\n\", fmt_ident(name, email, date, IDENT_ERROR_ON_NO_NAME));\n+}\n+\n static int prepare_to_commit(const char *index_file, const char *prefix)\n {\n \tstruct stat statbuf;\n@@ -622,45 +661,6 @@ static int message_is_empty(struct strbuf *sb, int start)\n \treturn 1;\n }\n \n-static void determine_author_info(struct strbuf *sb)\n-{\n-\tchar *name, *email, *date;\n-\n-\tname = getenv(\"GIT_AUTHOR_NAME\");\n-\temail = getenv(\"GIT_AUTHOR_EMAIL\");\n-\tdate = getenv(\"GIT_AUTHOR_DATE\");\n-\n-\tif (use_message) {\n-\t\tconst char *a, *lb, *rb, *eol;\n-\n-\t\ta = strstr(use_message_buffer, \"\\nauthor \");\n-\t\tif (!a)\n-\t\t\tdie(\"invalid commit: %s\", use_message);\n-\n-\t\tlb = strstr(a + 8, \" <\");\n-\t\trb = strstr(a + 8, \"> \");\n-\t\teol = strchr(a + 8, '\\n');\n-\t\tif (!lb || !rb || !eol)\n-\t\t\tdie(\"invalid commit: %s\", use_message);\n-\n-\t\tname = xstrndup(a + 8, lb - (a + 8));\n-\t\temail = xstrndup(lb + 2, rb - (lb + 2));\n-\t\tdate = xstrndup(rb + 2, eol - (rb + 2));\n-\t}\n-\n-\tif (force_author) {\n-\t\tconst char *lb = strstr(force_author, \" <\");\n-\t\tconst char *rb = strchr(force_author, '>');\n-\n-\t\tif (!lb || !rb)\n-\t\t\tdie(\"malformed --author parameter\");\n-\t\tname = xstrndup(force_author, lb - force_author);\n-\t\temail = xstrndup(lb + 2, rb - (lb + 2));\n-\t}\n-\n-\tstrbuf_addf(sb, \"author %s\\n\", fmt_ident(name, email, date, IDENT_ERROR_ON_NO_NAME));\n-}\n-\n static int parse_and_validate_options(int argc, const char *argv[],\n \t\t\t\t      const char * const usage[])\n {\n-- \n1.5.5.1.102.gfcc7d.dirty\n"}]}