git-diff-tree --stdin: show all parents.
git-diff-tree --stdin ignored second and subsequent parents when fed git-rev-list --parents output. Update diff_tree_commit() function to take a commit object, and pass a fabricated commit object after grafting the fake parents from diff_tree_stdin(). Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Feb 5, 2006 at 23:00 UTC
45392a648d7449d237ecc2507bc92378bf920bf0
1 file changed
+39
-26
diff-tree.c
+39
-26
@@ -100,23 +100,15 @@ static const char *generate_header(const unsigned char *commit_sha1,
100
return this_header;
101
}
102
103
-static int diff_tree_commit(const unsigned char *commit_sha1)
103
+static int diff_tree_commit(struct commit *commit)
104
{
105
- struct commit *commit;
105
struct commit_list *parents;
107
- char name[50];
108
- unsigned char sha1[20];
106
+ unsigned const char *sha1 = commit->object.sha1;
107
110
- sprintf(name, "%s^0", sha1_to_hex(commit_sha1));
111
- if (get_sha1(name, sha1))
112
- return -1;
113
- name[40] = 0;
114
- commit = lookup_commit(sha1);
115
-
108
/* Root commit? */
109
if (show_root_diff && !commit->parents) {
110
header = generate_header(sha1, NULL, commit);
119
- diff_root_tree(commit_sha1, "");
111
+ diff_root_tree(sha1, "");
112
}
113
114
/* More than one parent? */
@@ -133,7 +125,7 @@ static int diff_tree_commit(const unsigned char *commit_sha1)
125
for (parents = commit->parents; parents; parents = parents->next) {
126
struct commit *parent = parents->item;
127
header = generate_header(sha1, parent->object.sha1, commit);
136
- diff_tree_sha1_top(parent->object.sha1, commit_sha1, "");
128
+ diff_tree_sha1_top(parent->object.sha1, sha1, "");
129
if (!header && verbose_header) {
130
header_prefix = "\ndiff-tree ";
131
/*
@@ -145,28 +137,49 @@ static int diff_tree_commit(const unsigned char *commit_sha1)
137
return 0;
138
}
139
140
+static int diff_tree_commit_sha1(const unsigned char *sha1)
141
+{
142
+ struct commit *commit = lookup_commit_reference(sha1);
143
+ if (!commit)
144
+ return -1;
145
+ return diff_tree_commit(commit);
146
+}
147
+
148
static int diff_tree_stdin(char *line)
149
{
150
int len = strlen(line);
151
- unsigned char commit[20], parent[20];
152
- static char this_header[1000];
153
- int abbrev = diff_options.abbrev;
151
+ unsigned char sha1[20];
152
+ struct commit *commit;
153
154
if (!len || line[len-1] != '\n')
155
return -1;
156
line[len-1] = 0;
158
- if (get_sha1_hex(line, commit))
157
+ if (get_sha1_hex(line, sha1))
158
+ return -1;
159
+ commit = lookup_commit(sha1);
160
+ if (!commit || parse_commit(commit))
161
return -1;
160
- if (isspace(line[40]) && !get_sha1_hex(line+41, parent)) {
161
- line[40] = 0;
162
- line[81] = 0;
163
- sprintf(this_header, "%s (from %s)\n",
164
- diff_unique_abbrev(commit, abbrev),
165
- diff_unique_abbrev(parent, abbrev));
166
- header = this_header;
167
- return diff_tree_sha1_top(parent, commit, "");
162
+ if (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {
163
+ /* Graft the fake parents locally to the commit */
164
+ int pos = 41;
165
+ struct commit_list **pptr, *parents;
166
+
167
+ /* Free the real parent list */
168
+ for (parents = commit->parents; parents; ) {
169
+ struct commit_list *tmp = parents->next;
170
+ free(parents);
171
+ parents = tmp;
172
+ }
173
+ commit->parents = NULL;
174
+ pptr = &(commit->parents);
175
+ while (line[pos] && !get_sha1_hex(line + pos, sha1)) {
176
+ struct commit *parent = lookup_commit(sha1);
177
+ if (parent) {
178
+ pptr = &commit_list_insert(parent, pptr)->next;
179
+ }
180
+ pos += 41;
181
+ }
182
}
169
- line[40] = 0;
183
return diff_tree_commit(commit);
184
}
185
@@ -288,7 +301,7 @@ int main(int argc, const char **argv)
301
usage(diff_tree_usage);
302
break;
303
case 1:
291
- diff_tree_commit(sha1[0]);
304
+ diff_tree_commit_sha1(sha1[0]);
305
break;
306
case 2:
307
diff_tree_sha1_top(sha1[0], sha1[1], "");