Code

Make path in tree view look nicer
[git.git] / blame.c
diff --git a/blame.c b/blame.c
index c86e2fd4b31fc75adf1c315fda166aabc38f0f43..8cfd5d94c777770a2019e058f1140ecd5a5c9aa2 100644 (file)
--- a/blame.c
+++ b/blame.c
 
 #define DEBUG 0
 
-static const char blame_usage[] = "[-c] [-l] [-t] [-S <revs-file>] [--] file [commit]\n"
-       "  -c, --compability 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"
-       "  -S, --revs-file   Use revisions from revs-file instead of calling git-rev-list\n"
-       "  -h, --help        This message";
+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"
+       "  -S, --revs-file     Use revisions from revs-file instead of calling git-rev-list\n"
+       "  -h, --help          This message";
 
 static struct commit **blame_lines;
 static int num_blame_lines;
@@ -44,8 +44,8 @@ struct util_info {
 };
 
 struct chunk {
-       int off1, len1; // ---
-       int off2, len2; // +++
+       int off1, len1; /* --- */
+       int off2, len2; /* +++ */
 };
 
 struct patch {
@@ -56,9 +56,9 @@ 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;
 
 struct blame_diff_state {
        struct xdiff_emit_state xm;
@@ -165,7 +165,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 +176,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 +191,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;
 }
 
@@ -255,7 +255,7 @@ static void print_map(struct commit *cmit, struct commit *other)
 }
 #endif
 
-// p is a patch from commit to other.
+/* p is a patch from commit to other. */
 static void fill_line_map(struct commit *commit, struct commit *other,
                          struct patch *p)
 {
@@ -351,10 +351,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 +617,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;
@@ -747,7 +744,7 @@ int main(int argc, const char **argv)
        const char *filename = NULL, *commit = NULL;
        char filename_buf[256];
        int sha1_len = 8;
-       int compability = 0;
+       int compatibility = 0;
        int show_raw_time = 0;
        int options = 1;
        struct commit* start_commit;
@@ -774,8 +771,8 @@ int main(int argc, const char **argv)
                                sha1_len = 40;
                                continue;
                        } else if(!strcmp(argv[i], "-c") ||
-                                 !strcmp(argv[i], "--compability")) {
-                               compability = 1;
+                                 !strcmp(argv[i], "--compatibility")) {
+                               compatibility = 1;
                                continue;
                        } else if(!strcmp(argv[i], "-t") ||
                                  !strcmp(argv[i], "--time")) {
@@ -784,7 +781,7 @@ int main(int argc, const char **argv)
                        } else if(!strcmp(argv[i], "-S")) {
                                if (i + 1 < argc &&
                                    !read_ancestry(argv[i + 1], &sha1_p)) {
-                                       compability = 1;
+                                       compatibility = 1;
                                        i++;
                                        continue;
                                }
@@ -834,7 +831,7 @@ int main(int argc, const char **argv)
        }
 
 
-       init_revisions(&rev);
+       init_revisions(&rev, setup_git_directory());
        rev.remove_empty_trees = 1;
        rev.topo_order = 1;
        rev.prune_fn = simplify_commit;
@@ -884,7 +881,7 @@ int main(int argc, const char **argv)
                u = c->util;
                get_commit_info(c, &ci);
                fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
-               if(compability) {
+               if(compatibility) {
                        printf("\t(%10s\t%10s\t%d)", ci.author,
                               format_time(ci.author_time, ci.author_tz,
                                           show_raw_time),