summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ee22802)
raw | patch | inline | side by side (parent: ee22802)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Sat, 17 Dec 2011 10:15:48 +0000 (11:15 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 18 Dec 2011 02:21:37 +0000 (18:21 -0800) |
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>
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>
builtin/diff.c | patch | blob | history | |
combine-diff.c | patch | blob | history | |
diff.h | patch | blob | history | |
submodule.c | patch | blob | history |
diff --git a/builtin/diff.c b/builtin/diff.c
index 0fe638fc45c780e53901b8be22d3b4d715be3c30..387afa75680d813bccd5493e5946600c08679890 100644 (file)
--- a/builtin/diff.c
+++ b/builtin/diff.c
#include "log-tree.h"
#include "builtin.h"
#include "submodule.h"
+#include "sha1-array.h"
struct blobinfo {
unsigned char sha1[20];
struct object_array_entry *ent,
int ents)
{
- const unsigned char (*parent)[20];
+ struct sha1_array parents = SHA1_ARRAY_INIT;
int i;
if (argc > 1)
if (!revs->dense_combined_merges && !revs->combine_merges)
revs->dense_combined_merges = revs->combine_merges = 1;
- parent = xmalloc(ents * sizeof(*parent));
- for (i = 0; i < ents; i++)
- hashcpy((unsigned char *)(parent + i), ent[i].item->sha1);
- diff_tree_combined(parent[0], parent + 1, ents - 1,
+ for (i = 1; i < ents; i++)
+ sha1_array_append(&parents, ent[i].item->sha1);
+ diff_tree_combined(ent[0].item->sha1, &parents,
revs->dense_combined_merges, revs);
- free((void *)parent);
+ sha1_array_clear(&parents);
return 0;
}
diff --git a/combine-diff.c b/combine-diff.c
index 214014dc645e43ae257e46f1046c8ca0d21d3472..cfe62303a8634cb68c5f671c147efe97a5aca273 100644 (file)
--- a/combine-diff.c
+++ b/combine-diff.c
#include "log-tree.h"
#include "refs.h"
#include "userdiff.h"
+#include "sha1-array.h"
static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr, int n, int num_parent)
{
}
void diff_tree_combined(const unsigned char *sha1,
- const unsigned char parent[][20],
- int num_parent,
+ const struct sha1_array *parents,
int dense,
struct rev_info *rev)
{
struct diff_options *opt = &rev->diffopt;
struct diff_options diffopts;
struct combine_diff_path *p, *paths = NULL;
- int i, num_paths, needsep, show_log_first;
+ int i, num_paths, needsep, show_log_first, num_parent = parents->nr;
diffopts = *opt;
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
diffopts.output_format = stat_opt;
else
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
- diff_tree_sha1(parent[i], sha1, "", &diffopts);
+ diff_tree_sha1(parents->sha1[i], sha1, "", &diffopts);
diffcore_std(&diffopts);
paths = intersect_paths(paths, i, num_parent);
void diff_tree_combined_merge(const unsigned char *sha1,
int dense, struct rev_info *rev)
{
- int num_parent;
- const unsigned char (*parent)[20];
struct commit *commit = lookup_commit(sha1);
- struct commit_list *parents;
-
- /* count parents */
- for (parents = commit->parents, num_parent = 0;
- parents;
- parents = parents->next, num_parent++)
- ; /* nothing */
-
- parent = xmalloc(num_parent * sizeof(*parent));
- for (parents = commit->parents, num_parent = 0;
- parents;
- parents = parents->next, num_parent++)
- hashcpy((unsigned char *)(parent + num_parent),
- parents->item->object.sha1);
- diff_tree_combined(sha1, parent, num_parent, dense, rev);
+ struct commit_list *parent = commit->parents;
+ struct sha1_array parents = SHA1_ARRAY_INIT;
+
+ while (parent) {
+ sha1_array_append(&parents, parent->item->object.sha1);
+ parent = parent->next;
+ }
+ diff_tree_combined(sha1, &parents, dense, rev);
+ sha1_array_clear(&parents);
}
index 0c51724493f76461b67d6ef8f5556852819ad809..96085cbb0f71cdc8e21940130db95ebf5366683f 100644 (file)
--- a/diff.h
+++ b/diff.h
struct strbuf;
struct diff_filespec;
struct userdiff_driver;
+struct sha1_array;
typedef void (*change_fn_t)(struct diff_options *options,
unsigned old_mode, unsigned new_mode,
extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
int dense, struct rev_info *);
-extern void diff_tree_combined(const unsigned char *sha1, const unsigned char parent[][20], int num_parent, int dense, struct rev_info *rev);
+extern void diff_tree_combined(const unsigned char *sha1, const struct sha1_array *parents, int dense, struct rev_info *rev);
extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_info *);
diff --git a/submodule.c b/submodule.c
index 68c1ba90b9e746b869830ec66a6f23437a4d7d08..788d5327ac09f967e874626c7a077fec7eb29e11 100644 (file)
--- a/submodule.c
+++ b/submodule.c
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)