X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-diff.c;h=28b660a780f9f2ae48acf5e8d3dc7c7aee178de2;hb=723024d696a47556baac77700e47fef288691f37;hp=1075855102fdb9d49f923edc4b62ddb75aa8027c;hpb=9673198ee867cea4ed70d2cf54c1a2eb8f27bb46;p=git.git diff --git a/builtin-diff.c b/builtin-diff.c index 107585510..28b660a78 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -25,47 +25,6 @@ struct blobinfo { static const char builtin_diff_usage[] = "git-diff {0,2} -- *"; -static int builtin_diff_files(struct rev_info *revs, - int argc, const char **argv) -{ - int silent = 0; - while (1 < argc) { - const char *arg = argv[1]; - if (!strcmp(arg, "--base")) - revs->max_count = 1; - else if (!strcmp(arg, "--ours")) - revs->max_count = 2; - else if (!strcmp(arg, "--theirs")) - revs->max_count = 3; - else if (!strcmp(arg, "-q")) - silent = 1; - else - usage(builtin_diff_usage); - argv++; argc--; - } - /* - * Make sure there are NO revision (i.e. pending object) parameter, - * specified rev.max_count is reasonable (0 <= n <= 3), and - * there is no other revision filtering parameter. - */ - if (revs->pending.nr || - revs->min_age != -1 || - revs->max_age != -1 || - 3 < revs->max_count) - usage(builtin_diff_usage); - if (revs->max_count < 0 && - (revs->diffopt.output_format & DIFF_FORMAT_PATCH)) - revs->combine_merges = revs->dense_combined_merges = 1; - /* - * Backward compatibility wart - "diff-files -s" used to - * defeat the common diff option "-s" which asked for - * DIFF_FORMAT_NO_OUTPUT. - */ - if (revs->diffopt.output_format == DIFF_FORMAT_NO_OUTPUT) - revs->diffopt.output_format = DIFF_FORMAT_RAW; - return run_diff_files(revs, silent); -} - static void stuff_change(struct diff_options *opt, unsigned old_mode, unsigned new_mode, const unsigned char *old_sha1, @@ -75,9 +34,8 @@ static void stuff_change(struct diff_options *opt, { struct diff_filespec *one, *two; - if (memcmp(null_sha1, old_sha1, 20) && - memcmp(null_sha1, new_sha1, 20) && - !memcmp(old_sha1, new_sha1, 20)) + if (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) && + !hashcmp(old_sha1, new_sha1)) return; if (opt->reverse_diff) { @@ -159,6 +117,10 @@ static int builtin_diff_index(struct rev_info *revs, revs->max_count != -1 || revs->min_age != -1 || revs->max_age != -1) usage(builtin_diff_usage); + if (read_cache() < 0) { + perror("read_cache"); + return -1; + } return run_diff_index(revs, cached); } @@ -200,7 +162,8 @@ static int builtin_diff_combined(struct rev_info *revs, parent = xmalloc(ents * sizeof(*parent)); /* Again, the revs are all reverse */ for (i = 0; i < ents; i++) - memcpy(parent + i, ent[ents - 1 - i].item->sha1, 20); + hashcpy((unsigned char *)(parent + i), + ent[ents - 1 - i].item->sha1); diff_tree_combined(parent[0], parent + 1, ents - 1, revs->dense_combined_merges, revs); return 0; @@ -226,6 +189,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) int ents = 0, blobs = 0, paths = 0; const char *path = NULL; struct blobinfo blob[2]; + int nongit = 0; /* * We could get N tree-ish in the rev.pending_objects list. @@ -247,13 +211,15 @@ int cmd_diff(int argc, const char **argv, const char *prefix) * Other cases are errors. */ + prefix = setup_git_directory_gently(&nongit); git_config(git_diff_ui_config); init_revisions(&rev, prefix); argc = setup_revisions(argc, argv, &rev, NULL); if (!rev.diffopt.output_format) { rev.diffopt.output_format = DIFF_FORMAT_PATCH; - diff_setup_done(&rev.diffopt); + if (diff_setup_done(&rev.diffopt) < 0) + die("diff_setup_done failed"); } /* Do we have --cached and not have a pending object, then @@ -267,6 +233,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix) break; else if (!strcmp(arg, "--cached")) { add_head(&rev); + if (!rev.pending.nr) + die("No HEAD commit to compare with (yet)"); break; } } @@ -297,7 +265,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) if (obj->type == OBJ_BLOB) { if (2 <= blobs) die("more than two blobs given: '%s'", name); - memcpy(blob[blobs].sha1, obj->sha1, 20); + hashcpy(blob[blobs].sha1, obj->sha1); blob[blobs].name = name; blobs++; continue; @@ -321,7 +289,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) if (!ents) { switch (blobs) { case 0: - return builtin_diff_files(&rev, argc, argv); + return run_diff_files_cmd(&rev, argc, argv); break; case 1: if (paths != 1) @@ -348,6 +316,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) * A and B. We have ent[0] == merge-base, ent[1] == A, * and ent[2] == B. Show diff between the base and B. */ + ent[1] = ent[2]; return builtin_diff_tree(&rev, argc, argv, ent); } else