From 8f67f8aefb1b751073f8b36fae8be8f72eb93f4a Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 10 Nov 2007 20:05:14 +0100 Subject: Make the diff_options bitfields be an unsigned with explicit masks. reverse_diff was a bit-value in disguise, it's merged in the flags now. Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- builtin-diff-tree.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'builtin-diff-tree.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index 0b591c871..2e13716ee 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -118,8 +118,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) } if (!read_stdin) - return opt->diffopt.exit_with_status ? - opt->diffopt.has_changes: 0; + return DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS) + && DIFF_OPT_TST(&opt->diffopt, HAS_CHANGES); if (opt->diffopt.detect_rename) opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE | @@ -134,5 +134,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) else diff_tree_stdin(line); } - return opt->diffopt.exit_with_status ? opt->diffopt.has_changes: 0; + return DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS) + && DIFF_OPT_TST(&opt->diffopt, HAS_CHANGES); } -- cgit v1.2.1 From 62c64895cfcf3bbf34969a69fa96a631f7d5b14e Mon Sep 17 00:00:00 2001 From: Wincent Colaiuta Date: Thu, 13 Dec 2007 21:24:52 +0100 Subject: "diff --check" should affect exit status "git diff" has a --check option that can be used to check for whitespace problems but it only reported by printing warnings to the console. Now when the --check option is used we give a non-zero exit status, making "git diff --check" nicer to use in scripts and hooks. Signed-off-by: Wincent Colaiuta Signed-off-by: Junio C Hamano --- builtin-diff-tree.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'builtin-diff-tree.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index 2e13716ee..9ab90cb4c 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -117,23 +117,23 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) break; } - if (!read_stdin) - return DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS) - && DIFF_OPT_TST(&opt->diffopt, HAS_CHANGES); + if (read_stdin) { + if (opt->diffopt.detect_rename) + opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE | + DIFF_SETUP_USE_CACHE); + while (fgets(line, sizeof(line), stdin)) { + unsigned char sha1[20]; - if (opt->diffopt.detect_rename) - opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE | - DIFF_SETUP_USE_CACHE); - while (fgets(line, sizeof(line), stdin)) { - unsigned char sha1[20]; - - if (get_sha1_hex(line, sha1)) { - fputs(line, stdout); - fflush(stdout); + if (get_sha1_hex(line, sha1)) { + fputs(line, stdout); + fflush(stdout); + } + else + diff_tree_stdin(line); } - else - diff_tree_stdin(line); } + if (opt->diffopt.output_format & DIFF_FORMAT_CHECKDIFF) + return DIFF_OPT_TST(&opt->diffopt, CHECK_FAILED) != 0; return DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS) && DIFF_OPT_TST(&opt->diffopt, HAS_CHANGES); } -- cgit v1.2.1 From da31b358fb39b32622c14343ffe157a765f3948b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 13 Dec 2007 23:40:27 -0800 Subject: diff --check: minor fixups There is no reason --exit-code and --check-diff must be mutually exclusive, so assign different bits to different results and allow them to be returned from the command. Introduce diff_result_code() to factor out the common code to decide final status code based on diffopt settings and use it everywhere. Update tests to match the above fix. Turning pager off when "diff --check" is used is a regression. Signed-off-by: Junio C Hamano --- builtin-diff-tree.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'builtin-diff-tree.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index 9ab90cb4c..ebc50efbd 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -132,8 +132,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) diff_tree_stdin(line); } } - if (opt->diffopt.output_format & DIFF_FORMAT_CHECKDIFF) - return DIFF_OPT_TST(&opt->diffopt, CHECK_FAILED) != 0; - return DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS) - && DIFF_OPT_TST(&opt->diffopt, HAS_CHANGES); + + return diff_result_code(&opt->diffopt, 0); } -- cgit v1.2.1 From 9a1805a8726ee41f25be2e0f2d5f38f1150d38e4 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 4 Jan 2008 03:59:34 -0500 Subject: add a "basic" diff config callback The diff porcelain uses git_diff_ui_config to set porcelain-ish config options, like automatically turning on color. The plumbing specifically avoids calling this function, since it doesn't want things like automatic color or rename detection. However, some diff options should be set for both plumbing and porcelain. For example, one can still turn on color in git-diff-files using the --color command line option. This means we want the color config from color.diff.* (so that once color is on, we use the user's preferred scheme), but _not_ the color.diff variable. We split the diff config into "ui" and "basic", where "basic" is suitable for use by plumbing (so _most_ things affecting the output should still go into the "ui" part). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin-diff-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-diff-tree.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index ebc50efbd..832797ff3 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -68,7 +68,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) int read_stdin = 0; init_revisions(opt, prefix); - git_config(git_default_config); /* no "diff" UI options */ + git_config(git_diff_basic_config); /* no "diff" UI options */ nr_sha1 = 0; opt->abbrev = 0; opt->diff = 1; -- cgit v1.2.1 From ef90d6d4208a5130185b04f06e5f90a5f9959fe3 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 May 2008 18:46:53 +0100 Subject: Provide git_config with a callback-data parameter git_config() only had a function parameter, but no callback data parameter. This assumes that all callback functions only modify global variables. With this patch, every callback gets a void * parameter, and it is hoped that this will help the libification effort. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-diff-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-diff-tree.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index 832797ff3..9d2a48fd6 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -68,7 +68,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) int read_stdin = 0; init_revisions(opt, prefix); - git_config(git_diff_basic_config); /* no "diff" UI options */ + git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ nr_sha1 = 0; opt->abbrev = 0; opt->diff = 1; -- cgit v1.2.1 From 1b1dd23f2d6a707b7077cdf6bc6d4055bd0bfb7d Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Sun, 13 Jul 2008 15:36:15 +0200 Subject: Make usage strings dash-less When you misuse a git command, you are shown the usage string. But this is currently shown in the dashed form. So if you just copy what you see, it will not work, when the dashed form is no longer supported. This patch makes git commands show the dash-less version. For shell scripts that do not specify OPTIONS_SPEC, git-sh-setup.sh generates a dash-less usage string now. Signed-off-by: Stephan Beyer Signed-off-by: Junio C Hamano --- builtin-diff-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-diff-tree.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index 9d2a48fd6..415cb1612 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -53,7 +53,7 @@ static int diff_tree_stdin(char *line) } static const char diff_tree_usage[] = -"git-diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] " +"git diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] " "[] [] [...]\n" " -r diff recursively\n" " --root include the initial commit as diff against /dev/null\n" -- cgit v1.2.1 From a57114c81832a70efda4991131b9b99d1b112ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Hasselstr=C3=B6m?= Date: Fri, 8 Aug 2008 22:48:23 +0200 Subject: Refactoring: Split up diff_tree_stdin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Into a first half that determines what operation to do, and a second half that does it. Currently the only operation is diffing one or more commits, but a later patch will add diffing of trees, at which point this refactoring will pay off. Signed-off-by: Karl Hasselström Signed-off-by: Junio C Hamano --- builtin-diff-tree.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'builtin-diff-tree.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index 415cb1612..ebbd6317c 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -14,20 +14,10 @@ static int diff_tree_commit_sha1(const unsigned char *sha1) return log_tree_commit(&log_tree_opt, commit); } -static int diff_tree_stdin(char *line) +/* Diff one or more commits. */ +static int stdin_diff_commit(struct commit *commit, char *line, int len) { - int len = strlen(line); unsigned char sha1[20]; - struct commit *commit; - - if (!len || line[len-1] != '\n') - return -1; - line[len-1] = 0; - if (get_sha1_hex(line, sha1)) - return -1; - commit = lookup_commit(sha1); - if (!commit || parse_commit(commit)) - return -1; if (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) { /* Graft the fake parents locally to the commit */ int pos = 41; @@ -52,6 +42,23 @@ static int diff_tree_stdin(char *line) return log_tree_commit(&log_tree_opt, commit); } +static int diff_tree_stdin(char *line) +{ + int len = strlen(line); + unsigned char sha1[20]; + struct commit *commit; + + if (!len || line[len-1] != '\n') + return -1; + line[len-1] = 0; + if (get_sha1_hex(line, sha1)) + return -1; + commit = lookup_commit(sha1); + if (!commit || parse_commit(commit)) + return -1; + return stdin_diff_commit(commit, line, len); +} + static const char diff_tree_usage[] = "git diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] " "[] [] [...]\n" -- cgit v1.2.1 From 140b378d07229e3bcef0613e11aa0a04e4db3ecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Hasselstr=C3=B6m?= Date: Sun, 10 Aug 2008 18:12:58 +0200 Subject: Teach git diff-tree --stdin to diff trees MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When feeding trees on the command line, you can give exactly two trees, not three nor one; --stdin now supports this "two tree" form on its input, in addition to accepting lines with one or more commits. When diffing trees (either specified on the command line or from the standard input), the -s, -v, --pretty, --abbrev-commit, --encoding, --no-commit-id, and --always options are ignored, since they do not apply to trees; and the -m, -c, and --cc options are ignored since they would be meaningful only with three or more trees, which is not supported (yet). Signed-off-by: Karl Hasselström Signed-off-by: Junio C Hamano --- builtin-diff-tree.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'builtin-diff-tree.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index ebbd6317c..1138c2da7 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -42,21 +42,46 @@ static int stdin_diff_commit(struct commit *commit, char *line, int len) return log_tree_commit(&log_tree_opt, commit); } +/* Diff two trees. */ +static int stdin_diff_trees(struct tree *tree1, char *line, int len) +{ + unsigned char sha1[20]; + struct tree *tree2; + if (len != 82 || !isspace(line[40]) || get_sha1_hex(line + 41, sha1)) + return error("Need exactly two trees, separated by a space"); + tree2 = lookup_tree(sha1); + if (!tree2 || parse_tree(tree2)) + return -1; + printf("%s %s\n", sha1_to_hex(tree1->object.sha1), + sha1_to_hex(tree2->object.sha1)); + diff_tree_sha1(tree1->object.sha1, tree2->object.sha1, + "", &log_tree_opt.diffopt); + log_tree_diff_flush(&log_tree_opt); + return 0; +} + static int diff_tree_stdin(char *line) { int len = strlen(line); unsigned char sha1[20]; - struct commit *commit; + struct object *obj; if (!len || line[len-1] != '\n') return -1; line[len-1] = 0; if (get_sha1_hex(line, sha1)) return -1; - commit = lookup_commit(sha1); - if (!commit || parse_commit(commit)) + obj = lookup_object(sha1); + obj = obj ? obj : parse_object(sha1); + if (!obj) return -1; - return stdin_diff_commit(commit, line, len); + if (obj->type == OBJ_COMMIT) + return stdin_diff_commit((struct commit *)obj, line, len); + if (obj->type == OBJ_TREE) + return stdin_diff_trees((struct tree *)obj, line, len); + error("Object %s is a %s, not a commit or tree", + sha1_to_hex(sha1), typename(obj->type)); + return -1; } static const char diff_tree_usage[] = -- cgit v1.2.1 From 628b06d7d75588bbe37dfb7ecac19d2694884d66 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 10 Sep 2008 12:22:35 -0700 Subject: Fix git-diff-tree --stdin 140b378 (Teach git diff-tree --stdin to diff trees, 2008-08-10) broke the more important case of reading series of commits to filter ones that touch given pathspecs. Noticed by Mark Levedahl, running "gitk ec3a4ba" and trying to focus on commits that touch "t/" directory. Signed-off-by: Junio C Hamano --- builtin-diff-tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'builtin-diff-tree.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index 1138c2da7..8ecefd4f0 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -71,8 +71,9 @@ static int diff_tree_stdin(char *line) line[len-1] = 0; if (get_sha1_hex(line, sha1)) return -1; - obj = lookup_object(sha1); - obj = obj ? obj : parse_object(sha1); + obj = lookup_unknown_object(sha1); + if (!obj || !obj->parsed) + obj = parse_object(sha1); if (!obj) return -1; if (obj->type == OBJ_COMMIT) -- cgit v1.2.1 From 8e76bf3fc915ff9c530842123263e7147df207bb Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 13 Mar 2009 13:51:33 +0100 Subject: Remove unused assignments These variables were always overwritten or the assigned value was unused: builtin-diff-tree.c::cmd_diff_tree(): nr_sha1 builtin-for-each-ref.c::opt_parse_sort(): sort_tail builtin-mailinfo.c::decode_header_bq(): in builtin-shortlog.c::insert_one_record(): len connect.c::git_connect(): path imap-send.c::v_issue_imap_cmd(): n pretty.c::pp_user_info(): filler remote::parse_refspec_internal(): llen Signed-off-by: Benjamin Kramer Signed-off-by: Junio C Hamano --- builtin-diff-tree.c | 1 - 1 file changed, 1 deletion(-) (limited to 'builtin-diff-tree.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index 8ecefd4f0..79cedb72c 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -102,7 +102,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) init_revisions(opt, prefix); git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ - nr_sha1 = 0; opt->abbrev = 0; opt->diff = 1; argc = setup_revisions(argc, argv, opt, NULL); -- cgit v1.2.1