Code

Fix --signoff in builtin-commit differently.
authorJunio C Hamano <gitster@pobox.com>
Sun, 2 Dec 2007 21:43:34 +0000 (13:43 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 3 Dec 2007 07:35:46 +0000 (23:35 -0800)
Introduce fmt_name() specifically meant for formatting the name and
email pair, to add signed-off-by value.  This reverts parts of
13208572fbe8838fd8835548d7502202d1f7b21d (builtin-commit: fix --signoff)
so that an empty datestamp string given to fmt_ident() by mistake will
error out as before.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-commit.c
cache.h
ident.c

index 6c1ace32a432825e4c630f572f0169b82784ecfb..05594f2b1353714e95a0de4cc680e231b58c5e5b 100644 (file)
@@ -346,11 +346,9 @@ static int prepare_log_message(const char *index_file, const char *prefix)
 
                strbuf_init(&sob, 0);
                strbuf_addstr(&sob, sign_off_header);
-               strbuf_addstr(&sob, fmt_ident(getenv("GIT_COMMITTER_NAME"),
-                                             getenv("GIT_COMMITTER_EMAIL"),
-                                             "", 1));
+               strbuf_addstr(&sob, fmt_name(getenv("GIT_COMMITTER_NAME"),
+                                            getenv("GIT_COMMITTER_EMAIL")));
                strbuf_addch(&sob, '\n');
-
                for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
                        ; /* do nothing */
                if (prefixcmp(sb.buf + i, sob.buf)) {
diff --git a/cache.h b/cache.h
index cf0bdc674cc81f0443be3776b01969e8e07d2025..43cfebb0cfd806b406b11d919f9a77607ff3aa2b 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -444,6 +444,7 @@ enum date_mode parse_date_format(const char *format);
 extern const char *git_author_info(int);
 extern const char *git_committer_info(int);
 extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);
+extern const char *fmt_name(const char *name, const char *email);
 
 struct checkout {
        const char *base_dir;
diff --git a/ident.c b/ident.c
index 5be7533ffd061bee4d3e1c184c375b095cfed575..021d79b38ba40af93bd03b39a869be4264e6c426 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -192,12 +192,14 @@ static const char *env_hint =
 "Omit --global to set the identity only in this repository.\n"
 "\n";
 
-const char *fmt_ident(const char *name, const char *email,
-                     const char *date_str, int error_on_no_name)
+static const char *fmt_ident_1(const char *name, const char *email,
+                              const char *date_str, int flag)
 {
        static char buffer[1000];
        char date[50];
        int i;
+       int error_on_no_name = !!(flag & 01);
+       int name_addr_only = !!(flag & 02);
 
        setup_ident();
        if (!name)
@@ -224,24 +226,36 @@ const char *fmt_ident(const char *name, const char *email,
        }
 
        strcpy(date, git_default_date);
-       if (date_str) {
-               if (*date_str)
-                       parse_date(date_str, date, sizeof(date));
-               else
-                       date[0] = '\0';
-       }
+       if (!name_addr_only && date_str)
+               parse_date(date_str, date, sizeof(date));
 
        i = copy(buffer, sizeof(buffer), 0, name);
        i = add_raw(buffer, sizeof(buffer), i, " <");
        i = copy(buffer, sizeof(buffer), i, email);
-       i = add_raw(buffer, sizeof(buffer), i, date[0] ? "> " : ">");
-       i = copy(buffer, sizeof(buffer), i, date);
+       if (!name_addr_only) {
+               i = add_raw(buffer, sizeof(buffer), i,  "> ");
+               i = copy(buffer, sizeof(buffer), i, date);
+       } else {
+               i = add_raw(buffer, sizeof(buffer), i, ">");
+       }
        if (i >= sizeof(buffer))
                die("Impossibly long personal identifier");
        buffer[i] = 0;
        return buffer;
 }
 
+const char *fmt_ident(const char *name, const char *email,
+                     const char *date_str, int error_on_no_name)
+{
+       int flag = (error_on_no_name ? 01 : 0);
+       return fmt_ident_1(name, email, date_str, flag);
+}
+
+const char *fmt_name(const char *name, const char *email)
+{
+       return fmt_ident_1(name, email, NULL, 03);
+}
+
 const char *git_author_info(int error_on_no_name)
 {
        return fmt_ident(getenv("GIT_AUTHOR_NAME"),