@matheusbsbs / matheus-bagliano / commits / 13208572fb
Fork 0

builtin-commit: fix --signoff

The Signed-off-by: line contained a spurious timestamp. The reason was a call to git_committer_info(1), which automatically added the timestamp. Instead, fmt_ident() was taught to interpret an empty string for the date (as opposed to NULL, which still triggers the default behavior) as "do not bother with the timestamp", and builtin-commit.c uses it. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Nov 11, 2007 at 17:35 UTC 13208572fbe8838fd8835548d7502202d1f7b21d
3 files changed +38 -14
builtin-commit.c
+19 -11
@@ -183,21 +183,29 @@ static int prepare_log_message(const char *index_file, const char *prefix)
183 die("could not open %s\n", git_path(commit_editmsg));
184
185 stripspace(&sb, 0);
186 - if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
187 - die("could not write commit template: %s\n",
188 - strerror(errno));
186
187 if (signoff) {
191 - const char *info, *bol;
192 -
193 - info = git_committer_info(1);
194 - strbuf_addch(&sb, '\0');
195 - bol = strrchr(sb.buf + sb.len - 1, '\n');
196 - if (!bol || prefixcmp(bol, sign_off_header))
197 - fprintf(fp, "\n");
198 - fprintf(fp, "%s%s\n", sign_off_header, git_committer_info(1));
188 + struct strbuf sob;
189 + int i;
190 +
191 + strbuf_init(&sob, 0);
192 + strbuf_addstr(&sob, sign_off_header);
193 + strbuf_addstr(&sob, fmt_ident(getenv("GIT_COMMITTER_NAME"),
194 + getenv("GIT_COMMITTER_EMAIL"),
195 + "", 1));
196 + strbuf_addch(&sob, '\n');
197 +
198 + for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
199 + ; /* do nothing */
200 + if (prefixcmp(sb.buf + i, sob.buf))
201 + strbuf_addbuf(&sb, &sob);
202 + strbuf_release(&sob);
203 }
204
205 + if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
206 + die("could not write commit template: %s\n",
207 + strerror(errno));
208 +
209 strbuf_release(&sb);
210
211 if (in_merge && !no_edit)
ident.c
+7 -3
@@ -224,13 +224,17 @@ const char *fmt_ident(const char *name, const char *email,
224 }
225
226 strcpy(date, git_default_date);
227 - if (date_str)
228 - parse_date(date_str, date, sizeof(date));
227 + if (date_str) {
228 + if (*date_str)
229 + parse_date(date_str, date, sizeof(date));
230 + else
231 + date[0] = '\0';
232 + }
233
234 i = copy(buffer, sizeof(buffer), 0, name);
235 i = add_raw(buffer, sizeof(buffer), i, " <");
236 i = copy(buffer, sizeof(buffer), i, email);
233 - i = add_raw(buffer, sizeof(buffer), i, "> ");
237 + i = add_raw(buffer, sizeof(buffer), i, date[0] ? "> " : ">");
238 i = copy(buffer, sizeof(buffer), i, date);
239 if (i >= sizeof(buffer))
240 die("Impossibly long personal identifier");
t/t7500-commit.sh
+12
@@ -122,7 +122,19 @@ test_expect_success 'using alternate GIT_INDEX_FILE (2)' '
122
123 ) &&
124 cmp .git/index saved-index >/dev/null
125 +'
126
127 +cat > expect << EOF
128 +zort
129 +Signed-off-by: C O Mitter <committer@example.com>
130 +EOF
131 +
132 +test_expect_success '--signoff' '
133 + echo "yet another content *narf*" >> foo &&
134 + echo "zort" |
135 + GIT_EDITOR=../t7500/add-content git commit -s -F - foo &&
136 + git cat-file commit HEAD | sed "1,/^$/d" > output &&
137 + diff expect output
138 '
139
140 test_done