git-pickaxe: allow "-L <something>,+N"
[gitweb.git] / blame.c
diff --git a/blame.c b/blame.c
index 76712b5962bcb0f511cc4a18766d1a45dc901675..d0e506c02b2e2d0c8fa834ddc86c6b325ea1a8cb 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -20,7 +20,7 @@
 
 #define DEBUG 0
 
-static const char blame_usage[] = "[-c] [-l] [-t] [-S <revs-file>] [--] file [commit]\n"
+static const char blame_usage[] = "git-blame [-c] [-l] [-t] [-S <revs-file>] [--] file [commit]\n"
        "  -c, --compatibility Use the same output mode as git-annotate (Default: off)\n"
        "  -l, --long          Show long commit SHA1 (Default: off)\n"
        "  -t, --time          Show raw timestamp (Default: off)\n"
@@ -56,9 +56,10 @@ struct patch {
 static void get_blob(struct commit *commit);
 
 /* Only used for statistics */
-static int num_get_patch = 0;
-static int num_commits = 0;
-static int patch_time = 0;
+static int num_get_patch;
+static int num_commits;
+static int patch_time;
+static int num_read_blob;
 
 struct blame_diff_state {
        struct xdiff_emit_state xm;
@@ -165,7 +166,7 @@ static int get_blob_sha1(struct tree *t, const char *pathname,
        blame_file = pathname;
        pathspec[0] = pathname;
        pathspec[1] = NULL;
-       memset(blob_sha1, 0, sizeof(blob_sha1));
+       hashclr(blob_sha1);
        read_tree_recursive(t, "", 0, 0, pathspec, get_blob_sha1_internal);
 
        for (i = 0; i < 20; i++) {
@@ -176,7 +177,7 @@ static int get_blob_sha1(struct tree *t, const char *pathname,
        if (i == 20)
                return -1;
 
-       memcpy(sha1, blob_sha1, 20);
+       hashcpy(sha1, blob_sha1);
        return 0;
 }
 
@@ -191,7 +192,7 @@ static int get_blob_sha1_internal(const unsigned char *sha1, const char *base,
            strcmp(blame_file + baselen, pathname))
                return -1;
 
-       memcpy(blob_sha1, sha1, 20);
+       hashcpy(blob_sha1, sha1);
        return -1;
 }
 
@@ -204,6 +205,7 @@ static void get_blob(struct commit *commit)
                return;
 
        info->buf = read_sha1_file(info->sha1, type, &info->size);
+       num_read_blob++;
 
        assert(!strcmp(type, blob_type));
 }
@@ -351,10 +353,7 @@ static int fill_util_info(struct commit *commit)
        assert(util);
        assert(util->pathname);
 
-       if (get_blob_sha1(commit->tree, util->pathname, util->sha1))
-               return 1;
-       else
-               return 0;
+       return !!get_blob_sha1(commit->tree, util->pathname, util->sha1);
 }
 
 static void alloc_line_map(struct commit *commit)
@@ -620,7 +619,7 @@ static void simplify_commit(struct rev_info *revs, struct commit *commit)
                                if (new_name) {
                                        struct util_info* putil = get_util(p);
                                        if (!putil->pathname)
-                                               putil->pathname = strdup(new_name);
+                                               putil->pathname = xstrdup(new_name);
                                } else {
                                        *pp = parent->next;
                                        continue;
@@ -913,6 +912,7 @@ int main(int argc, const char **argv)
        }
 
        if (DEBUG) {
+               printf("num read blob: %d\n", num_read_blob);
                printf("num get patch: %d\n", num_get_patch);
                printf("num commits: %d\n", num_commits);
                printf("patch time: %f\n", patch_time / 1000000.0);