[PATCH] (resend) show-diff.c off-by-one fix
[gitweb.git] / rev-tree.c
index d3fc93c61a6c0629c32413bb7b64f06facda803d..3c54769258b82a9384248fbf10530e25d8b2dd8f 100644 (file)
@@ -1,4 +1,5 @@
 #define _XOPEN_SOURCE /* glibc2 needs this */
+#define _BSD_SOURCE /* for tm.tm_gmtoff */
 #include <time.h>
 #include <ctype.h>
 
 static int show_edges = 0;
 static int basemask = 0;
 
-static unsigned long parse_time(const char *buf)
-{
-       char c, *p;
-       char buffer[100];
-       struct tm tm;
-       const char *formats[] = {
-               "%c",
-               "%a %b %d %T %y",
-               NULL
-       };
-       const char **fmt = formats;
-
-       p = buffer;
-       while (isspace(c = *buf))
-               buf++;
-       while ((c = *buf++) != '\n')
-               *p++ = c;
-       *p++ = 0;
-       buf = buffer;
-       memset(&tm, 0, sizeof(tm));
-       do {
-               const char *next = strptime(buf, *fmt, &tm);
-               fmt++;
-               if (next) {
-                       if (!*next)
-                               return mktime(&tm);
-                       buf = next;
-               }
-       } while (*buf && *fmt);
-       return mktime(&tm);
-}
-               
-
-static unsigned long parse_commit_date(const char *buf)
-{
-       if (memcmp(buf, "author", 6))
-               return 0;
-       while (*buf++ != '\n')
-               /* nada */;
-       if (memcmp(buf, "committer", 9))
-               return 0;
-       while (*buf++ != '>')
-               /* nada */;
-       return parse_time(buf);
-}
-
-static int parse_commit(unsigned char *sha1)
-{
-       struct revision *rev = lookup_rev(sha1);
-
-       if (!(rev->flags & SEEN)) {
-               void *buffer, *bufptr;
-               unsigned long size;
-               char type[20];
-               unsigned char parent[20];
-
-               rev->flags |= SEEN;
-               buffer = bufptr = read_sha1_file(sha1, type, &size);
-               if (!buffer || strcmp(type, "commit"))
-                       return -1;
-               bufptr += 46; /* "tree " + "hex sha1" + "\n" */
-               while (!memcmp(bufptr, "parent ", 7) && !get_sha1_hex(bufptr+7, parent)) {
-                       add_relationship(rev, parent);
-                       parse_commit(parent);
-                       bufptr += 48;   /* "parent " + "hex sha1" + "\n" */
-               }
-               rev->date = parse_commit_date(bufptr);
-               free(buffer);
-       }
-       return 0;       
-}
-
 static void read_cache_file(const char *path)
 {
        FILE *file = fopen(path, "r");
@@ -108,7 +37,7 @@ static void read_cache_file(const char *path)
                        break;
                if (get_sha1_hex(buf+1, sha1))
                        break;
-               rev = lookup_rev(sha1);
+               rev = lookup_rev(sha1, "commit");
                rev->flags |= SEEN;
                rev->date = date;
 
@@ -117,27 +46,12 @@ static void read_cache_file(const char *path)
                        unsigned char parent[20];
                        if (get_sha1_hex(buf + 1, parent))
                                break;
-                       add_relationship(rev, parent);
+                       add_relationship(rev, parent, "commit");
                }
        }
        fclose(file);
 }
 
-static void mark_sha1_path(struct revision *rev, unsigned int mask)
-{
-       struct parent *p;
-
-       if (rev->flags & mask)
-               return;
-
-       rev->flags |= mask;
-       p = rev->parent;
-       while (p) {
-               mark_sha1_path(p->parent, mask);
-               p = p->next;
-       }
-}
-
 /*
  * Some revisions are less interesting than others.
  *
@@ -213,7 +127,7 @@ int main(int argc, char **argv)
         * Now we have the maximal tree. Walk the different sha files back to the root.
         */
        for (i = 0; i < nr; i++)
-               mark_sha1_path(lookup_rev(sha1[i]), 1 << i);
+               mark_reachable(lookup_rev(sha1[i], "commit"), 1 << i);
 
        /*
         * Now print out the results..