]> asedeno.scripts.mit.edu Git - git.git/blobdiff - commit.c
connect: display connection progress
[git.git] / commit.c
index 952095faa70dd8f5166f106a83382e50e131897a..bee066fa3227c876022424bd0e6238c1053e1231 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -98,12 +98,8 @@ struct commit *lookup_commit_reference(const unsigned char *sha1)
 struct commit *lookup_commit(const unsigned char *sha1)
 {
        struct object *obj = lookup_object(sha1);
-       if (!obj) {
-               struct commit *ret = alloc_commit_node();
-               created_object(sha1, &ret->object);
-               ret->object.type = OBJ_COMMIT;
-               return ret;
-       }
+       if (!obj)
+               return create_object(sha1, OBJ_COMMIT, alloc_commit_node());
        if (!obj->type)
                obj->type = OBJ_COMMIT;
        return check_commit(obj, sha1, 0);
@@ -530,7 +526,7 @@ static int add_rfc2047(char *buf, const char *line, int len,
 }
 
 static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf,
-                        const char *line, int relative_date,
+                        const char *line, enum date_mode dmode,
                         const char *encoding)
 {
        char *date;
@@ -573,7 +569,7 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf,
        switch (fmt) {
        case CMIT_FMT_MEDIUM:
                ret += sprintf(buf + ret, "Date:   %s\n",
-                              show_date(time, tz, relative_date));
+                              show_date(time, tz, dmode));
                break;
        case CMIT_FMT_EMAIL:
                ret += sprintf(buf + ret, "Date: %s\n",
@@ -581,7 +577,7 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf,
                break;
        case CMIT_FMT_FULLER:
                ret += sprintf(buf + ret, "%sDate: %s\n", what,
-                              show_date(time, tz, relative_date));
+                              show_date(time, tz, dmode));
                break;
        default:
                /* notin' */
@@ -642,7 +638,9 @@ static char *get_header(const struct commit *commit, const char *key)
                        next = NULL;
                } else
                        next = eol + 1;
-               if (!strncmp(line, key, key_len) && line[key_len] == ' ') {
+               if (eol - line > key_len &&
+                   !strncmp(line, key, key_len) &&
+                   line[key_len] == ' ') {
                        int len = eol - line - key_len;
                        char *ret = xmalloc(len);
                        memcpy(ret, line + key_len + 1, len - 1);
@@ -722,14 +720,6 @@ static char *logmsg_reencode(const struct commit *commit,
        return out;
 }
 
-static char *xstrndup(const char *text, int len)
-{
-       char *result = xmalloc(len + 1);
-       memcpy(result, text, len);
-       result[len] = '\0';
-       return result;
-}
-
 static void fill_person(struct interp *table, const char *msg, int len)
 {
        int start, end, tz = 0;
@@ -923,7 +913,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
                                  char *buf, unsigned long space,
                                  int abbrev, const char *subject,
                                  const char *after_subject,
-                                 int relative_date)
+                                 enum date_mode dmode)
 {
        int hdr = 1, body = 0, seen_title = 0;
        unsigned long offset = 0;
@@ -1027,14 +1017,14 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
                                offset += add_user_info("Author", fmt,
                                                        buf + offset,
                                                        line + 7,
-                                                       relative_date,
+                                                       dmode,
                                                        encoding);
                        if (!memcmp(line, "committer ", 10) &&
                            (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER))
                                offset += add_user_info("Commit", fmt,
                                                        buf + offset,
                                                        line + 10,
-                                                       relative_date,
+                                                       dmode,
                                                        encoding);
                        continue;
                }
@@ -1073,6 +1063,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
                        int sz;
                        char header[512];
                        const char *header_fmt =
+                               "MIME-Version: 1.0\n"
                                "Content-Type: text/plain; charset=%s\n"
                                "Content-Transfer-Encoding: 8bit\n";
                        sz = snprintf(header, sizeof(header), header_fmt,