Skip to content

Commit e927c16

Browse files
committed
Merge branch 'rs/diff-tree-combined-clean-up'
* rs/diff-tree-combined-clean-up: submodule: use diff_tree_combined_merge() instead of diff_tree_combined() pass struct commit to diff_tree_combined_merge() use struct sha1_array in diff_tree_combined()
2 parents c735ce4 + 78e98ea commit e927c16

File tree

5 files changed

+29
-50
lines changed

5 files changed

+29
-50
lines changed

builtin/diff.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "log-tree.h"
1515
#include "builtin.h"
1616
#include "submodule.h"
17+
#include "sha1-array.h"
1718

1819
struct blobinfo {
1920
unsigned char sha1[20];
@@ -169,20 +170,19 @@ static int builtin_diff_combined(struct rev_info *revs,
169170
struct object_array_entry *ent,
170171
int ents)
171172
{
172-
const unsigned char (*parent)[20];
173+
struct sha1_array parents = SHA1_ARRAY_INIT;
173174
int i;
174175

175176
if (argc > 1)
176177
usage(builtin_diff_usage);
177178

178179
if (!revs->dense_combined_merges && !revs->combine_merges)
179180
revs->dense_combined_merges = revs->combine_merges = 1;
180-
parent = xmalloc(ents * sizeof(*parent));
181-
for (i = 0; i < ents; i++)
182-
hashcpy((unsigned char *)(parent + i), ent[i].item->sha1);
183-
diff_tree_combined(parent[0], parent + 1, ents - 1,
181+
for (i = 1; i < ents; i++)
182+
sha1_array_append(&parents, ent[i].item->sha1);
183+
diff_tree_combined(ent[0].item->sha1, &parents,
184184
revs->dense_combined_merges, revs);
185-
free((void *)parent);
185+
sha1_array_clear(&parents);
186186
return 0;
187187
}
188188

combine-diff.c

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "log-tree.h"
99
#include "refs.h"
1010
#include "userdiff.h"
11+
#include "sha1-array.h"
1112

1213
static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr, int n, int num_parent)
1314
{
@@ -1116,15 +1117,14 @@ static void handle_combined_callback(struct diff_options *opt,
11161117
}
11171118

11181119
void diff_tree_combined(const unsigned char *sha1,
1119-
const unsigned char parent[][20],
1120-
int num_parent,
1120+
const struct sha1_array *parents,
11211121
int dense,
11221122
struct rev_info *rev)
11231123
{
11241124
struct diff_options *opt = &rev->diffopt;
11251125
struct diff_options diffopts;
11261126
struct combine_diff_path *p, *paths = NULL;
1127-
int i, num_paths, needsep, show_log_first;
1127+
int i, num_paths, needsep, show_log_first, num_parent = parents->nr;
11281128

11291129
diffopts = *opt;
11301130
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -1144,7 +1144,7 @@ void diff_tree_combined(const unsigned char *sha1,
11441144
diffopts.output_format = stat_opt;
11451145
else
11461146
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
1147-
diff_tree_sha1(parent[i], sha1, "", &diffopts);
1147+
diff_tree_sha1(parents->sha1[i], sha1, "", &diffopts);
11481148
diffcore_std(&diffopts);
11491149
paths = intersect_paths(paths, i, num_parent);
11501150

@@ -1196,25 +1196,16 @@ void diff_tree_combined(const unsigned char *sha1,
11961196
}
11971197
}
11981198

1199-
void diff_tree_combined_merge(const unsigned char *sha1,
1200-
int dense, struct rev_info *rev)
1199+
void diff_tree_combined_merge(const struct commit *commit, int dense,
1200+
struct rev_info *rev)
12011201
{
1202-
int num_parent;
1203-
const unsigned char (*parent)[20];
1204-
struct commit *commit = lookup_commit(sha1);
1205-
struct commit_list *parents;
1206-
1207-
/* count parents */
1208-
for (parents = commit->parents, num_parent = 0;
1209-
parents;
1210-
parents = parents->next, num_parent++)
1211-
; /* nothing */
1212-
1213-
parent = xmalloc(num_parent * sizeof(*parent));
1214-
for (parents = commit->parents, num_parent = 0;
1215-
parents;
1216-
parents = parents->next, num_parent++)
1217-
hashcpy((unsigned char *)(parent + num_parent),
1218-
parents->item->object.sha1);
1219-
diff_tree_combined(sha1, parent, num_parent, dense, rev);
1202+
struct commit_list *parent = commit->parents;
1203+
struct sha1_array parents = SHA1_ARRAY_INIT;
1204+
1205+
while (parent) {
1206+
sha1_array_append(&parents, parent->item->object.sha1);
1207+
parent = parent->next;
1208+
}
1209+
diff_tree_combined(commit->object.sha1, &parents, dense, rev);
1210+
sha1_array_clear(&parents);
12201211
}

diff.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ struct diff_queue_struct;
1212
struct strbuf;
1313
struct diff_filespec;
1414
struct userdiff_driver;
15+
struct sha1_array;
16+
struct commit;
1517

1618
typedef void (*change_fn_t)(struct diff_options *options,
1719
unsigned old_mode, unsigned new_mode,
@@ -195,9 +197,9 @@ struct combine_diff_path {
195197
extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
196198
int dense, struct rev_info *);
197199

198-
extern void diff_tree_combined(const unsigned char *sha1, const unsigned char parent[][20], int num_parent, int dense, struct rev_info *rev);
200+
extern void diff_tree_combined(const unsigned char *sha1, const struct sha1_array *parents, int dense, struct rev_info *rev);
199201

200-
extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_info *);
202+
extern void diff_tree_combined_merge(const struct commit *commit, int dense, struct rev_info *rev);
201203

202204
void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
203205

log-tree.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,7 @@ int log_tree_diff_flush(struct rev_info *opt)
599599

600600
static int do_diff_combined(struct rev_info *opt, struct commit *commit)
601601
{
602-
unsigned const char *sha1 = commit->object.sha1;
603-
604-
diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt);
602+
diff_tree_combined_merge(commit, opt->dense_combined_merges, opt);
605603
return !opt->loginfo;
606604
}
607605

submodule.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -371,27 +371,15 @@ static void collect_submodules_from_diff(struct diff_queue_struct *q,
371371
}
372372

373373

374-
static void commit_need_pushing(struct commit *commit, struct commit_list *parent, int *needs_pushing)
374+
static void commit_need_pushing(struct commit *commit, int *needs_pushing)
375375
{
376-
const unsigned char (*parents)[20];
377-
unsigned int i, n;
378376
struct rev_info rev;
379377

380-
n = commit_list_count(parent);
381-
parents = xmalloc(n * sizeof(*parents));
382-
383-
for (i = 0; i < n; i++) {
384-
hashcpy((unsigned char *)(parents + i), parent->item->object.sha1);
385-
parent = parent->next;
386-
}
387-
388378
init_revisions(&rev, NULL);
389379
rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
390380
rev.diffopt.format_callback = collect_submodules_from_diff;
391381
rev.diffopt.format_callback_data = needs_pushing;
392-
diff_tree_combined(commit->object.sha1, parents, n, 1, &rev);
393-
394-
free((void *)parents);
382+
diff_tree_combined_merge(commit, 1, &rev);
395383
}
396384

397385
int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name)
@@ -414,7 +402,7 @@ int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remote
414402
die("revision walk setup failed");
415403

416404
while ((commit = get_revision(&rev)) && !needs_pushing)
417-
commit_need_pushing(commit, commit->parents, &needs_pushing);
405+
commit_need_pushing(commit, &needs_pushing);
418406

419407
free(sha1_copy);
420408
strbuf_release(&remotes_arg);

0 commit comments

Comments
 (0)