@matheusbsbs / matheus-bagliano / commits / a57114c818
Fork 0

Refactoring: Split up diff_tree_stdin

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 <kha@treskal.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karl Hasselström committed Aug 8, 2008 at 22:48 UTC a57114c81832a70efda4991131b9b99d1b112ea3
1 file changed +19 -12
builtin-diff-tree.c
+19 -12
@@ -14,20 +14,10 @@ static int diff_tree_commit_sha1(const unsigned char *sha1)
14 return log_tree_commit(&log_tree_opt, commit);
15 }
16
17 -static int diff_tree_stdin(char *line)
17 +/* Diff one or more commits. */
18 +static int stdin_diff_commit(struct commit *commit, char *line, int len)
19 {
19 - int len = strlen(line);
20 unsigned char sha1[20];
21 - struct commit *commit;
22 -
23 - if (!len || line[len-1] != '\n')
24 - return -1;
25 - line[len-1] = 0;
26 - if (get_sha1_hex(line, sha1))
27 - return -1;
28 - commit = lookup_commit(sha1);
29 - if (!commit || parse_commit(commit))
30 - return -1;
21 if (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {
22 /* Graft the fake parents locally to the commit */
23 int pos = 41;
@@ -52,6 +42,23 @@ static int diff_tree_stdin(char *line)
42 return log_tree_commit(&log_tree_opt, commit);
43 }
44
45 +static int diff_tree_stdin(char *line)
46 +{
47 + int len = strlen(line);
48 + unsigned char sha1[20];
49 + struct commit *commit;
50 +
51 + if (!len || line[len-1] != '\n')
52 + return -1;
53 + line[len-1] = 0;
54 + if (get_sha1_hex(line, sha1))
55 + return -1;
56 + commit = lookup_commit(sha1);
57 + if (!commit || parse_commit(commit))
58 + return -1;
59 + return stdin_diff_commit(commit, line, len);
60 +}
61 +
62 static const char diff_tree_usage[] =
63 "git diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] "
64 "[<common diff options>] <tree-ish> [<tree-ish>] [<path>...]\n"