aboutsummaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2011-12-17 11:15:48 +0100
committerJunio C Hamano <gitster@pobox.com>2011-12-17 18:21:37 -0800
commit0041f09de6e62efc31c860487f04e8b08bce68c8 (patch)
tree85d855657c9a8a94ab39a82773362e5b1abd66f6 /submodule.c
parentee228024933069b93ce23a1bd5eeb7ae12c792f2 (diff)
downloadgit-0041f09de6e62efc31c860487f04e8b08bce68c8.tar.gz
git-0041f09de6e62efc31c860487f04e8b08bce68c8.tar.xz
use struct sha1_array in diff_tree_combined()
Maintaining an array of hashes is easier using sha1_array than open-coding it. This patch also fixes a leak of the SHA1 array in diff_tree_combined_merge(). Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/submodule.c b/submodule.c
index 68c1ba90b..788d5327a 100644
--- a/submodule.c
+++ b/submodule.c
@@ -373,15 +373,11 @@ static void collect_submodules_from_diff(struct diff_queue_struct *q,
static void commit_need_pushing(struct commit *commit, struct commit_list *parent, int *needs_pushing)
{
- const unsigned char (*parents)[20];
- unsigned int i, n;
+ struct sha1_array parents = SHA1_ARRAY_INIT;
struct rev_info rev;
- n = commit_list_count(parent);
- parents = xmalloc(n * sizeof(*parents));
-
- for (i = 0; i < n; i++) {
- hashcpy((unsigned char *)(parents + i), parent->item->object.sha1);
+ while (parent) {
+ sha1_array_append(&parents, parent->item->object.sha1);
parent = parent->next;
}
@@ -389,9 +385,9 @@ static void commit_need_pushing(struct commit *commit, struct commit_list *paren
rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = collect_submodules_from_diff;
rev.diffopt.format_callback_data = needs_pushing;
- diff_tree_combined(commit->object.sha1, parents, n, 1, &rev);
+ diff_tree_combined(commit->object.sha1, &parents, 1, &rev);
- free((void *)parents);
+ sha1_array_clear(&parents);
}
int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name)