{"thread":{"id":"4261","subject":"[PATCH 8/8] Builtin git-diff-files, git-diff-index, git-diff-stages, and git-diff-tree.","startedAt":"2006-05-23T08:31:20Z","lastAt":"2006-05-23T08:31:20Z","messageCount":1,"participants":["Peter Eriksen"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"20528","messageId":"10301.3191408992$1148373129@news.gmane.org","threadId":"4261","inReplyTo":"11483730813930-git-send-email-","subject":"[PATCH 8/8] Builtin git-diff-files, git-diff-index, git-diff-stages, and git-diff-tree.","fromName":"Peter Eriksen","fromEmail":"s022018@student.dtu.dk","sentAt":"2006-05-23T08:31:20Z","receivedAt":"2006-05-23T08:31:20Z","isPatch":true,"sender":{"key":"s022018@student.dtu.dk","avatar":null},"body":"From: Peter Eriksen <s022018@student.dtu.dk>\n\nSigned-off-by: Peter Eriksen <s022018@student.dtu.dk>\n\n\n---\n\ne2d2468b8550f2760b46a2eb461b051abfef4dff\n Makefile              |   12 ++--\n builtin-diff-files.c  |   55 ++++++++++++++++++\n builtin-diff-index.c  |   39 +++++++++++++\n builtin-diff-stages.c |  105 +++++++++++++++++++++++++++++++++++\n builtin-diff-tree.c   |  148 +++++++++++++++++++++++++++++++++++++++++++++++++\n builtin.h             |    5 ++\n diff-files.c          |   54 ------------------\n diff-index.c          |   38 -------------\n diff-stages.c         |  104 ----------------------------------\n diff-tree.c           |  147 -------------------------------------------------\n git.c                 |    6 ++\n 11 files changed, 363 insertions(+), 350 deletions(-)\n create mode 100644 builtin-diff-files.c\n create mode 100644 builtin-diff-index.c\n create mode 100644 builtin-diff-stages.c\n create mode 100644 builtin-diff-tree.c\n delete mode 100644 diff-files.c\n delete mode 100644 diff-index.c\n delete mode 100644 diff-stages.c\n delete mode 100644 diff-tree.c\n\ne2d2468b8550f2760b46a2eb461b051abfef4dff\ndiff --git a/Makefile b/Makefile\nindex b438a90..9dc1326 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -151,9 +151,7 @@ # ... and all the rest that could be mov\n PROGRAMS = \\\n \tgit-cat-file$X \\\n \tgit-checkout-index$X git-clone-pack$X \\\n-\tgit-convert-objects$X git-diff-files$X \\\n-\tgit-diff-index$X git-diff-stages$X \\\n-\tgit-diff-tree$X git-fetch-pack$X git-fsck-objects$X \\\n+\tgit-convert-objects$X git-fetch-pack$X git-fsck-objects$X \\\n \tgit-hash-object$X git-index-pack$X git-local-fetch$X \\\n \tgit-mailinfo$X git-merge-base$X \\\n \tgit-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \\\n@@ -173,7 +171,8 @@ BUILT_INS = git-log$X git-whatchanged$X \n \tgit-grep$X git-rev-list$X git-check-ref-format$X \\\n \tgit-init-db$X git-ls-files$X git-ls-tree$X \\\n \tgit-tar-tree$X git-read-tree$X git-commit-tree$X \\\n-\tgit-apply$X git-show-branch$X\n+\tgit-apply$X git-show-branch$X git-diff-files$X \\\n+\tgit-diff-index$X git-diff-stages$X git-diff-tree$X\n \n # what 'all' will build and 'install' will install, in gitexecdir\n ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)\n@@ -223,8 +222,9 @@ BUILTIN_OBJS = \\\n \tbuiltin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \\\n \tbuiltin-grep.o builtin-rev-list.o builtin-check-ref-format.o \\\n \tbuiltin-init-db.o builtin-ls-files.o builtin-ls-tree.o \\\n-        builtin-tar-tree.o builtin-read-tree.o builtin-commit-tree.o \\\n-\tbuiltin-apply.o builtin-show-branch.o\n+\tbuiltin-tar-tree.o builtin-read-tree.o builtin-commit-tree.o \\\n+\tbuiltin-apply.o builtin-show-branch.o builtin-diff-files.o \\\n+\tbuiltin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o\n \n GITLIBS = $(LIB_FILE) $(XDIFF_LIB)\n LIBS = $(GITLIBS) -lz\ndiff --git a/builtin-diff-files.c b/builtin-diff-files.c\nnew file mode 100644\nindex 0000000..cebda82\n--- /dev/null\n+++ b/builtin-diff-files.c\n@@ -0,0 +1,55 @@\n+/*\n+ * GIT - The information manager from hell\n+ *\n+ * Copyright (C) Linus Torvalds, 2005\n+ */\n+#include \"cache.h\"\n+#include \"diff.h\"\n+#include \"commit.h\"\n+#include \"revision.h\"\n+#include \"builtin.h\"\n+\n+static const char diff_files_usage[] =\n+\"git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]\"\n+COMMON_DIFF_OPTIONS_HELP;\n+\n+int cmd_diff_files(int argc, const char **argv, char **envp)\n+{\n+\tstruct rev_info rev;\n+\tint silent = 0;\n+\n+\tgit_config(git_diff_config);\n+\tinit_revisions(&rev);\n+\trev.abbrev = 0;\n+\n+\targc = setup_revisions(argc, argv, &rev, NULL);\n+\twhile (1 < argc && argv[1][0] == '-') {\n+\t\tif (!strcmp(argv[1], \"--base\"))\n+\t\t\trev.max_count = 1;\n+\t\telse if (!strcmp(argv[1], \"--ours\"))\n+\t\t\trev.max_count = 2;\n+\t\telse if (!strcmp(argv[1], \"--theirs\"))\n+\t\t\trev.max_count = 3;\n+\t\telse if (!strcmp(argv[1], \"-q\"))\n+\t\t\tsilent = 1;\n+\t\telse\n+\t\t\tusage(diff_files_usage);\n+\t\targv++; argc--;\n+\t}\n+\t/*\n+\t * Make sure there are NO revision (i.e. pending object) parameter,\n+\t * rev.max_count is reasonable (0 <= n <= 3),\n+\t * there is no other revision filtering parameters.\n+\t */\n+\tif (rev.pending_objects ||\n+\t    rev.min_age != -1 || rev.max_age != -1)\n+\t\tusage(diff_files_usage);\n+\t/*\n+\t * Backward compatibility wart - \"diff-files -s\" used to\n+\t * defeat the common diff option \"-s\" which asked for\n+\t * DIFF_FORMAT_NO_OUTPUT.\n+\t */\n+\tif (rev.diffopt.output_format == DIFF_FORMAT_NO_OUTPUT)\n+\t\trev.diffopt.output_format = DIFF_FORMAT_RAW;\n+\treturn run_diff_files(&rev, silent);\n+}\ndiff --git a/builtin-diff-index.c b/builtin-diff-index.c\nnew file mode 100644\nindex 0000000..1958580\n--- /dev/null\n+++ b/builtin-diff-index.c\n@@ -0,0 +1,39 @@\n+#include \"cache.h\"\n+#include \"diff.h\"\n+#include \"commit.h\"\n+#include \"revision.h\"\n+#include \"builtin.h\"\n+\n+static const char diff_cache_usage[] =\n+\"git-diff-index [-m] [--cached] \"\n+\"[<common diff options>] <tree-ish> [<path>...]\"\n+COMMON_DIFF_OPTIONS_HELP;\n+\n+int cmd_diff_index(int argc, const char **argv, char **envp)\n+{\n+\tstruct rev_info rev;\n+\tint cached = 0;\n+\tint i;\n+\n+\tgit_config(git_diff_config);\n+\tinit_revisions(&rev);\n+\trev.abbrev = 0;\n+\n+\targc = setup_revisions(argc, argv, &rev, NULL);\n+\tfor (i = 1; i < argc; i++) {\n+\t\tconst char *arg = argv[i];\n+\t\t\t\n+\t\tif (!strcmp(arg, \"--cached\"))\n+\t\t\tcached = 1;\n+\t\telse\n+\t\t\tusage(diff_cache_usage);\n+\t}\n+\t/*\n+\t * Make sure there is one revision (i.e. pending object),\n+\t * and there is no revision filtering parameters.\n+\t */\n+\tif (!rev.pending_objects || rev.pending_objects->next ||\n+\t    rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)\n+\t\tusage(diff_cache_usage);\n+\treturn run_diff_index(&rev, cached);\n+}\ndiff --git a/builtin-diff-stages.c b/builtin-diff-stages.c\nnew file mode 100644\nindex 0000000..7c157ca\n--- /dev/null\n+++ b/builtin-diff-stages.c\n@@ -0,0 +1,105 @@\n+/*\n+ * Copyright (c) 2005 Junio C Hamano\n+ */\n+\n+#include \"cache.h\"\n+#include \"diff.h\"\n+#include \"builtin.h\"\n+\n+static struct diff_options diff_options;\n+\n+static const char diff_stages_usage[] =\n+\"git-diff-stages [<common diff options>] <stage1> <stage2> [<path>...]\"\n+COMMON_DIFF_OPTIONS_HELP;\n+\n+static void diff_stages(int stage1, int stage2, const char **pathspec)\n+{\n+\tint i = 0;\n+\twhile (i < active_nr) {\n+\t\tstruct cache_entry *ce, *stages[4] = { NULL, };\n+\t\tstruct cache_entry *one, *two;\n+\t\tconst char *name;\n+\t\tint len, skip;\n+\n+\t\tce = active_cache[i];\n+\t\tskip = !ce_path_match(ce, pathspec);\n+\t\tlen = ce_namelen(ce);\n+\t\tname = ce->name;\n+\t\tfor (;;) {\n+\t\t\tint stage = ce_stage(ce);\n+\t\t\tstages[stage] = ce;\n+\t\t\tif (active_nr <= ++i)\n+\t\t\t\tbreak;\n+\t\t\tce = active_cache[i];\n+\t\t\tif (ce_namelen(ce) != len ||\n+\t\t\t    memcmp(name, ce->name, len))\n+\t\t\t\tbreak;\n+\t\t}\n+\t\tone = stages[stage1];\n+\t\ttwo = stages[stage2];\n+\n+\t\tif (skip || (!one && !two))\n+\t\t\tcontinue;\n+\t\tif (!one)\n+\t\t\tdiff_addremove(&diff_options, '+', ntohl(two->ce_mode),\n+\t\t\t\t       two->sha1, name, NULL);\n+\t\telse if (!two)\n+\t\t\tdiff_addremove(&diff_options, '-', ntohl(one->ce_mode),\n+\t\t\t\t       one->sha1, name, NULL);\n+\t\telse if (memcmp(one->sha1, two->sha1, 20) ||\n+\t\t\t (one->ce_mode != two->ce_mode) ||\n+\t\t\t diff_options.find_copies_harder)\n+\t\t\tdiff_change(&diff_options,\n+\t\t\t\t    ntohl(one->ce_mode), ntohl(two->ce_mode),\n+\t\t\t\t    one->sha1, two->sha1, name, NULL);\n+\t}\n+}\n+\n+int cmd_diff_stages(int ac, const char **av, char **envp)\n+{\n+\tint stage1, stage2;\n+\tconst char *prefix = setup_git_directory();\n+\tconst char **pathspec = NULL;\n+\n+\tgit_config(git_diff_config);\n+\tread_cache();\n+\tdiff_setup(&diff_options);\n+\twhile (1 < ac && av[1][0] == '-') {\n+\t\tconst char *arg = av[1];\n+\t\tif (!strcmp(arg, \"-r\"))\n+\t\t\t; /* as usual */\n+\t\telse {\n+\t\t\tint diff_opt_cnt;\n+\t\t\tdiff_opt_cnt = diff_opt_parse(&diff_options,\n+\t\t\t\t\t\t      av+1, ac-1);\n+\t\t\tif (diff_opt_cnt < 0)\n+\t\t\t\tusage(diff_stages_usage);\n+\t\t\telse if (diff_opt_cnt) {\n+\t\t\t\tav += diff_opt_cnt;\n+\t\t\t\tac -= diff_opt_cnt;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\telse\n+\t\t\t\tusage(diff_stages_usage);\n+\t\t}\n+\t\tac--; av++;\n+\t}\n+\n+\tif (ac < 3 ||\n+\t    sscanf(av[1], \"%d\", &stage1) != 1 ||\n+\t    ! (0 <= stage1 && stage1 <= 3) ||\n+\t    sscanf(av[2], \"%d\", &stage2) != 1 ||\n+\t    ! (0 <= stage2 && stage2 <= 3))\n+\t\tusage(diff_stages_usage);\n+\n+\tav += 3; /* The rest from av[0] are for paths restriction. */\n+\tpathspec = get_pathspec(prefix, av);\n+\n+\tif (diff_setup_done(&diff_options) < 0)\n+\t\tusage(diff_stages_usage);\n+\n+\tdiff_stages(stage1, stage2, pathspec);\n+\tdiffcore_std(&diff_options);\n+\tdiff_flush(&diff_options);\n+\treturn 0;\n+}\ndiff --git a/builtin-diff-tree.c b/builtin-diff-tree.c\nnew file mode 100644\nindex 0000000..cc53b81\n--- /dev/null\n+++ b/builtin-diff-tree.c\n@@ -0,0 +1,148 @@\n+#include \"cache.h\"\n+#include \"diff.h\"\n+#include \"commit.h\"\n+#include \"log-tree.h\"\n+#include \"builtin.h\"\n+\n+static struct rev_info log_tree_opt;\n+\n+static int diff_tree_commit_sha1(const unsigned char *sha1)\n+{\n+\tstruct commit *commit = lookup_commit_reference(sha1);\n+\tif (!commit)\n+\t\treturn -1;\n+\treturn log_tree_commit(&log_tree_opt, commit);\n+}\n+\n+static int diff_tree_stdin(char *line)\n+{\n+\tint len = strlen(line);\n+\tunsigned char sha1[20];\n+\tstruct commit *commit;\n+\n+\tif (!len || line[len-1] != '\\n')\n+\t\treturn -1;\n+\tline[len-1] = 0;\n+\tif (get_sha1_hex(line, sha1))\n+\t\treturn -1;\n+\tcommit = lookup_commit(sha1);\n+\tif (!commit || parse_commit(commit))\n+\t\treturn -1;\n+\tif (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {\n+\t\t/* Graft the fake parents locally to the commit */\n+\t\tint pos = 41;\n+\t\tstruct commit_list **pptr, *parents;\n+\n+\t\t/* Free the real parent list */\n+\t\tfor (parents = commit->parents; parents; ) {\n+\t\t\tstruct commit_list *tmp = parents->next;\n+\t\t\tfree(parents);\n+\t\t\tparents = tmp;\n+\t\t}\n+\t\tcommit->parents = NULL;\n+\t\tpptr = &(commit->parents);\n+\t\twhile (line[pos] && !get_sha1_hex(line + pos, sha1)) {\n+\t\t\tstruct commit *parent = lookup_commit(sha1);\n+\t\t\tif (parent) {\n+\t\t\t\tpptr = &commit_list_insert(parent, pptr)->next;\n+\t\t\t}\n+\t\t\tpos += 41;\n+\t\t}\n+\t}\n+\treturn log_tree_commit(&log_tree_opt, commit);\n+}\n+\n+static const char diff_tree_usage[] =\n+\"git-diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] \"\n+\"[<common diff options>] <tree-ish> [<tree-ish>] [<path>...]\\n\"\n+\"  -r            diff recursively\\n\"\n+\"  --root        include the initial commit as diff against /dev/null\\n\"\n+COMMON_DIFF_OPTIONS_HELP;\n+\n+int cmd_diff_tree(int argc, const char **argv, char **envp)\n+{\n+\tint nr_sha1;\n+\tchar line[1000];\n+\tstruct object *tree1, *tree2;\n+\tstatic struct rev_info *opt = &log_tree_opt;\n+\tstruct object_list *list;\n+\tint read_stdin = 0;\n+\n+\tgit_config(git_diff_config);\n+\tnr_sha1 = 0;\n+\tinit_revisions(opt);\n+\topt->abbrev = 0;\n+\topt->diff = 1;\n+\targc = setup_revisions(argc, argv, opt, NULL);\n+\n+\twhile (--argc > 0) {\n+\t\tconst char *arg = *++argv;\n+\n+\t\tif (!strcmp(arg, \"--stdin\")) {\n+\t\t\tread_stdin = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tusage(diff_tree_usage);\n+\t}\n+\n+\t/*\n+\t * NOTE! \"setup_revisions()\" will have inserted the revisions\n+\t * it parsed in reverse order. So if you do\n+\t *\n+\t *\tgit-diff-tree a b\n+\t *\n+\t * the commit list will be \"b\" -> \"a\" -> NULL, so we reverse\n+\t * the order of the objects if the first one is not marked\n+\t * UNINTERESTING.\n+\t */\n+\tnr_sha1 = 0;\n+\tlist = opt->pending_objects;\n+\tif (list) {\n+\t\tnr_sha1++;\n+\t\ttree1 = list->item;\n+\t\tlist = list->next;\n+\t\tif (list) {\n+\t\t\tnr_sha1++;\n+\t\t\ttree2 = tree1;\n+\t\t\ttree1 = list->item;\n+\t\t\tif (list->next)\n+\t\t\t\tusage(diff_tree_usage);\n+\t\t\t/* Switch them around if the second one was uninteresting.. */\n+\t\t\tif (tree2->flags & UNINTERESTING) {\n+\t\t\t\tstruct object *tmp = tree2;\n+\t\t\t\ttree2 = tree1;\n+\t\t\t\ttree1 = tmp;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tswitch (nr_sha1) {\n+\tcase 0:\n+\t\tif (!read_stdin)\n+\t\t\tusage(diff_tree_usage);\n+\t\tbreak;\n+\tcase 1:\n+\t\tdiff_tree_commit_sha1(tree1->sha1);\n+\t\tbreak;\n+\tcase 2:\n+\t\tdiff_tree_sha1(tree1->sha1,\n+\t\t\t       tree2->sha1,\n+\t\t\t       \"\", &opt->diffopt);\n+\t\tlog_tree_diff_flush(opt);\n+\t\tbreak;\n+\t}\n+\n+\tif (!read_stdin)\n+\t\treturn 0;\n+\n+\tif (opt->diffopt.detect_rename)\n+\t\topt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |\n+\t\t\t\t       DIFF_SETUP_USE_CACHE);\n+\twhile (fgets(line, sizeof(line), stdin))\n+\t\tif (line[0] == '\\n')\n+\t\t\tfflush(stdout);\n+\t\telse\n+\t\t\tdiff_tree_stdin(line);\n+\n+\treturn 0;\n+}\ndiff --git a/builtin.h b/builtin.h\nindex 01882ec..7620984 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -34,5 +34,10 @@ extern int cmd_read_tree(int argc, const\n extern int cmd_commit_tree(int argc, const char **argv, char **envp);\n extern int cmd_apply(int argc, const char **argv, char **envp);\n extern int cmd_show_branch(int argc, const char **argv, char **envp);\n+extern int cmd_diff_files(int argc, const char **argv, char **envp);\n+extern int cmd_diff_index(int argc, const char **argv, char **envp);\n+extern int cmd_diff_stages(int argc, const char **argv, char **envp);\n+extern int cmd_diff_tree(int argc, const char **argv, char **envp);\n+\n \n #endif\ndiff --git a/diff-files.c b/diff-files.c\ndeleted file mode 100644\nindex b9d193d..0000000\n--- a/diff-files.c\n+++ /dev/null\n@@ -1,54 +0,0 @@\n-/*\n- * GIT - The information manager from hell\n- *\n- * Copyright (C) Linus Torvalds, 2005\n- */\n-#include \"cache.h\"\n-#include \"diff.h\"\n-#include \"commit.h\"\n-#include \"revision.h\"\n-\n-static const char diff_files_usage[] =\n-\"git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]\"\n-COMMON_DIFF_OPTIONS_HELP;\n-\n-int main(int argc, const char **argv)\n-{\n-\tstruct rev_info rev;\n-\tint silent = 0;\n-\n-\tgit_config(git_diff_config);\n-\tinit_revisions(&rev);\n-\trev.abbrev = 0;\n-\n-\targc = setup_revisions(argc, argv, &rev, NULL);\n-\twhile (1 < argc && argv[1][0] == '-') {\n-\t\tif (!strcmp(argv[1], \"--base\"))\n-\t\t\trev.max_count = 1;\n-\t\telse if (!strcmp(argv[1], \"--ours\"))\n-\t\t\trev.max_count = 2;\n-\t\telse if (!strcmp(argv[1], \"--theirs\"))\n-\t\t\trev.max_count = 3;\n-\t\telse if (!strcmp(argv[1], \"-q\"))\n-\t\t\tsilent = 1;\n-\t\telse\n-\t\t\tusage(diff_files_usage);\n-\t\targv++; argc--;\n-\t}\n-\t/*\n-\t * Make sure there are NO revision (i.e. pending object) parameter,\n-\t * rev.max_count is reasonable (0 <= n <= 3),\n-\t * there is no other revision filtering parameters.\n-\t */\n-\tif (rev.pending_objects ||\n-\t    rev.min_age != -1 || rev.max_age != -1)\n-\t\tusage(diff_files_usage);\n-\t/*\n-\t * Backward compatibility wart - \"diff-files -s\" used to\n-\t * defeat the common diff option \"-s\" which asked for\n-\t * DIFF_FORMAT_NO_OUTPUT.\n-\t */\n-\tif (rev.diffopt.output_format == DIFF_FORMAT_NO_OUTPUT)\n-\t\trev.diffopt.output_format = DIFF_FORMAT_RAW;\n-\treturn run_diff_files(&rev, silent);\n-}\ndiff --git a/diff-index.c b/diff-index.c\ndeleted file mode 100644\nindex 8c9f601..0000000\n--- a/diff-index.c\n+++ /dev/null\n@@ -1,38 +0,0 @@\n-#include \"cache.h\"\n-#include \"diff.h\"\n-#include \"commit.h\"\n-#include \"revision.h\"\n-\n-static const char diff_cache_usage[] =\n-\"git-diff-index [-m] [--cached] \"\n-\"[<common diff options>] <tree-ish> [<path>...]\"\n-COMMON_DIFF_OPTIONS_HELP;\n-\n-int main(int argc, const char **argv)\n-{\n-\tstruct rev_info rev;\n-\tint cached = 0;\n-\tint i;\n-\n-\tgit_config(git_diff_config);\n-\tinit_revisions(&rev);\n-\trev.abbrev = 0;\n-\n-\targc = setup_revisions(argc, argv, &rev, NULL);\n-\tfor (i = 1; i < argc; i++) {\n-\t\tconst char *arg = argv[i];\n-\t\t\t\n-\t\tif (!strcmp(arg, \"--cached\"))\n-\t\t\tcached = 1;\n-\t\telse\n-\t\t\tusage(diff_cache_usage);\n-\t}\n-\t/*\n-\t * Make sure there is one revision (i.e. pending object),\n-\t * and there is no revision filtering parameters.\n-\t */\n-\tif (!rev.pending_objects || rev.pending_objects->next ||\n-\t    rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)\n-\t\tusage(diff_cache_usage);\n-\treturn run_diff_index(&rev, cached);\n-}\ndiff --git a/diff-stages.c b/diff-stages.c\ndeleted file mode 100644\nindex dcd20e7..0000000\n--- a/diff-stages.c\n+++ /dev/null\n@@ -1,104 +0,0 @@\n-/*\n- * Copyright (c) 2005 Junio C Hamano\n- */\n-\n-#include \"cache.h\"\n-#include \"diff.h\"\n-\n-static struct diff_options diff_options;\n-\n-static const char diff_stages_usage[] =\n-\"git-diff-stages [<common diff options>] <stage1> <stage2> [<path>...]\"\n-COMMON_DIFF_OPTIONS_HELP;\n-\n-static void diff_stages(int stage1, int stage2, const char **pathspec)\n-{\n-\tint i = 0;\n-\twhile (i < active_nr) {\n-\t\tstruct cache_entry *ce, *stages[4] = { NULL, };\n-\t\tstruct cache_entry *one, *two;\n-\t\tconst char *name;\n-\t\tint len, skip;\n-\n-\t\tce = active_cache[i];\n-\t\tskip = !ce_path_match(ce, pathspec);\n-\t\tlen = ce_namelen(ce);\n-\t\tname = ce->name;\n-\t\tfor (;;) {\n-\t\t\tint stage = ce_stage(ce);\n-\t\t\tstages[stage] = ce;\n-\t\t\tif (active_nr <= ++i)\n-\t\t\t\tbreak;\n-\t\t\tce = active_cache[i];\n-\t\t\tif (ce_namelen(ce) != len ||\n-\t\t\t    memcmp(name, ce->name, len))\n-\t\t\t\tbreak;\n-\t\t}\n-\t\tone = stages[stage1];\n-\t\ttwo = stages[stage2];\n-\n-\t\tif (skip || (!one && !two))\n-\t\t\tcontinue;\n-\t\tif (!one)\n-\t\t\tdiff_addremove(&diff_options, '+', ntohl(two->ce_mode),\n-\t\t\t\t       two->sha1, name, NULL);\n-\t\telse if (!two)\n-\t\t\tdiff_addremove(&diff_options, '-', ntohl(one->ce_mode),\n-\t\t\t\t       one->sha1, name, NULL);\n-\t\telse if (memcmp(one->sha1, two->sha1, 20) ||\n-\t\t\t (one->ce_mode != two->ce_mode) ||\n-\t\t\t diff_options.find_copies_harder)\n-\t\t\tdiff_change(&diff_options,\n-\t\t\t\t    ntohl(one->ce_mode), ntohl(two->ce_mode),\n-\t\t\t\t    one->sha1, two->sha1, name, NULL);\n-\t}\n-}\n-\n-int main(int ac, const char **av)\n-{\n-\tint stage1, stage2;\n-\tconst char *prefix = setup_git_directory();\n-\tconst char **pathspec = NULL;\n-\n-\tgit_config(git_diff_config);\n-\tread_cache();\n-\tdiff_setup(&diff_options);\n-\twhile (1 < ac && av[1][0] == '-') {\n-\t\tconst char *arg = av[1];\n-\t\tif (!strcmp(arg, \"-r\"))\n-\t\t\t; /* as usual */\n-\t\telse {\n-\t\t\tint diff_opt_cnt;\n-\t\t\tdiff_opt_cnt = diff_opt_parse(&diff_options,\n-\t\t\t\t\t\t      av+1, ac-1);\n-\t\t\tif (diff_opt_cnt < 0)\n-\t\t\t\tusage(diff_stages_usage);\n-\t\t\telse if (diff_opt_cnt) {\n-\t\t\t\tav += diff_opt_cnt;\n-\t\t\t\tac -= diff_opt_cnt;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\t\t\telse\n-\t\t\t\tusage(diff_stages_usage);\n-\t\t}\n-\t\tac--; av++;\n-\t}\n-\n-\tif (ac < 3 ||\n-\t    sscanf(av[1], \"%d\", &stage1) != 1 ||\n-\t    ! (0 <= stage1 && stage1 <= 3) ||\n-\t    sscanf(av[2], \"%d\", &stage2) != 1 ||\n-\t    ! (0 <= stage2 && stage2 <= 3))\n-\t\tusage(diff_stages_usage);\n-\n-\tav += 3; /* The rest from av[0] are for paths restriction. */\n-\tpathspec = get_pathspec(prefix, av);\n-\n-\tif (diff_setup_done(&diff_options) < 0)\n-\t\tusage(diff_stages_usage);\n-\n-\tdiff_stages(stage1, stage2, pathspec);\n-\tdiffcore_std(&diff_options);\n-\tdiff_flush(&diff_options);\n-\treturn 0;\n-}\ndiff --git a/diff-tree.c b/diff-tree.c\ndeleted file mode 100644\nindex 69bb74b..0000000\n--- a/diff-tree.c\n+++ /dev/null\n@@ -1,147 +0,0 @@\n-#include \"cache.h\"\n-#include \"diff.h\"\n-#include \"commit.h\"\n-#include \"log-tree.h\"\n-\n-static struct rev_info log_tree_opt;\n-\n-static int diff_tree_commit_sha1(const unsigned char *sha1)\n-{\n-\tstruct commit *commit = lookup_commit_reference(sha1);\n-\tif (!commit)\n-\t\treturn -1;\n-\treturn log_tree_commit(&log_tree_opt, commit);\n-}\n-\n-static int diff_tree_stdin(char *line)\n-{\n-\tint len = strlen(line);\n-\tunsigned char sha1[20];\n-\tstruct commit *commit;\n-\n-\tif (!len || line[len-1] != '\\n')\n-\t\treturn -1;\n-\tline[len-1] = 0;\n-\tif (get_sha1_hex(line, sha1))\n-\t\treturn -1;\n-\tcommit = lookup_commit(sha1);\n-\tif (!commit || parse_commit(commit))\n-\t\treturn -1;\n-\tif (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {\n-\t\t/* Graft the fake parents locally to the commit */\n-\t\tint pos = 41;\n-\t\tstruct commit_list **pptr, *parents;\n-\n-\t\t/* Free the real parent list */\n-\t\tfor (parents = commit->parents; parents; ) {\n-\t\t\tstruct commit_list *tmp = parents->next;\n-\t\t\tfree(parents);\n-\t\t\tparents = tmp;\n-\t\t}\n-\t\tcommit->parents = NULL;\n-\t\tpptr = &(commit->parents);\n-\t\twhile (line[pos] && !get_sha1_hex(line + pos, sha1)) {\n-\t\t\tstruct commit *parent = lookup_commit(sha1);\n-\t\t\tif (parent) {\n-\t\t\t\tpptr = &commit_list_insert(parent, pptr)->next;\n-\t\t\t}\n-\t\t\tpos += 41;\n-\t\t}\n-\t}\n-\treturn log_tree_commit(&log_tree_opt, commit);\n-}\n-\n-static const char diff_tree_usage[] =\n-\"git-diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] \"\n-\"[<common diff options>] <tree-ish> [<tree-ish>] [<path>...]\\n\"\n-\"  -r            diff recursively\\n\"\n-\"  --root        include the initial commit as diff against /dev/null\\n\"\n-COMMON_DIFF_OPTIONS_HELP;\n-\n-int main(int argc, const char **argv)\n-{\n-\tint nr_sha1;\n-\tchar line[1000];\n-\tstruct object *tree1, *tree2;\n-\tstatic struct rev_info *opt = &log_tree_opt;\n-\tstruct object_list *list;\n-\tint read_stdin = 0;\n-\n-\tgit_config(git_diff_config);\n-\tnr_sha1 = 0;\n-\tinit_revisions(opt);\n-\topt->abbrev = 0;\n-\topt->diff = 1;\n-\targc = setup_revisions(argc, argv, opt, NULL);\n-\n-\twhile (--argc > 0) {\n-\t\tconst char *arg = *++argv;\n-\n-\t\tif (!strcmp(arg, \"--stdin\")) {\n-\t\t\tread_stdin = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tusage(diff_tree_usage);\n-\t}\n-\n-\t/*\n-\t * NOTE! \"setup_revisions()\" will have inserted the revisions\n-\t * it parsed in reverse order. So if you do\n-\t *\n-\t *\tgit-diff-tree a b\n-\t *\n-\t * the commit list will be \"b\" -> \"a\" -> NULL, so we reverse\n-\t * the order of the objects if the first one is not marked\n-\t * UNINTERESTING.\n-\t */\n-\tnr_sha1 = 0;\n-\tlist = opt->pending_objects;\n-\tif (list) {\n-\t\tnr_sha1++;\n-\t\ttree1 = list->item;\n-\t\tlist = list->next;\n-\t\tif (list) {\n-\t\t\tnr_sha1++;\n-\t\t\ttree2 = tree1;\n-\t\t\ttree1 = list->item;\n-\t\t\tif (list->next)\n-\t\t\t\tusage(diff_tree_usage);\n-\t\t\t/* Switch them around if the second one was uninteresting.. */\n-\t\t\tif (tree2->flags & UNINTERESTING) {\n-\t\t\t\tstruct object *tmp = tree2;\n-\t\t\t\ttree2 = tree1;\n-\t\t\t\ttree1 = tmp;\n-\t\t\t}\n-\t\t}\n-\t}\n-\n-\tswitch (nr_sha1) {\n-\tcase 0:\n-\t\tif (!read_stdin)\n-\t\t\tusage(diff_tree_usage);\n-\t\tbreak;\n-\tcase 1:\n-\t\tdiff_tree_commit_sha1(tree1->sha1);\n-\t\tbreak;\n-\tcase 2:\n-\t\tdiff_tree_sha1(tree1->sha1,\n-\t\t\t       tree2->sha1,\n-\t\t\t       \"\", &opt->diffopt);\n-\t\tlog_tree_diff_flush(opt);\n-\t\tbreak;\n-\t}\n-\n-\tif (!read_stdin)\n-\t\treturn 0;\n-\n-\tif (opt->diffopt.detect_rename)\n-\t\topt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |\n-\t\t\t\t       DIFF_SETUP_USE_CACHE);\n-\twhile (fgets(line, sizeof(line), stdin))\n-\t\tif (line[0] == '\\n')\n-\t\t\tfflush(stdout);\n-\t\telse\n-\t\t\tdiff_tree_stdin(line);\n-\n-\treturn 0;\n-}\ndiff --git a/git.c b/git.c\nindex d29505c..8749748 100644\n--- a/git.c\n+++ b/git.c\n@@ -59,7 +59,11 @@ static void handle_internal_command(int \n \t\t{ \"read-tree\", cmd_read_tree },\n \t\t{ \"commit-tree\", cmd_commit_tree },\n \t\t{ \"apply\", cmd_apply },\n-\t\t{ \"show-branch\", cmd_show_branch }\n+\t\t{ \"show-branch\", cmd_show_branch },\n+\t\t{ \"diff-files\", cmd_diff_files },\n+\t\t{ \"diff-index\", cmd_diff_index },\n+\t\t{ \"diff-stages\", cmd_diff_stages },\n+\t\t{ \"diff-tree\", cmd_diff_tree }\n \t};\n \tint i;\n \n-- \n1.3.3.g288c\n"}]}