summaryrefslogtreecommitdiff
path: root/diff-lib.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-02-03 10:23:33 -0800
committerJunio C Hamano <gitster@pobox.com>2025-02-03 10:23:33 -0800
commitc43136d67b7c6a9ecfa988004eb4a87bfbe957a0 (patch)
treecc4c17eed6328f3baa142c811aec4eec7005e690 /diff-lib.c
parentcaf17423d375e97919ace904cd527b4d26cc3e43 (diff)
parent6979bf6f8f5e831ef38214edb158c7fb493540f7 (diff)
Merge branch 'jk/combine-diff-cleanup'
Code clean-up for code paths around combined diff. * jk/combine-diff-cleanup: tree-diff: make list tail-passing more explicit tree-diff: simplify emit_path() list management tree-diff: use the name "tail" to refer to list tail tree-diff: drop list-tail argument to diff_tree_paths() combine-diff: drop public declaration of combine_diff_path_size() tree-diff: inline path_appendnew() tree-diff: pass whole path string to path_appendnew() tree-diff: drop path_appendnew() alloc optimization run_diff_files(): de-mystify the size of combine_diff_path struct diff: add a comment about combine_diff_path.parent.path combine-diff: use pointer for parent paths tree-diff: clear parent array in path_appendnew() combine-diff: add combine_diff_path_new() run_diff_files(): delay allocation of combine_diff_path
Diffstat (limited to 'diff-lib.c')
-rw-r--r--diff-lib.c36
1 files changed, 12 insertions, 24 deletions
diff --git a/diff-lib.c b/diff-lib.c
index c6d3bc4d37..353b473ed5 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -153,21 +153,8 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
struct diff_filepair *pair;
unsigned int wt_mode = 0;
int num_compare_stages = 0;
- size_t path_len;
struct stat st;
- path_len = ce_namelen(ce);
-
- dpath = xmalloc(combine_diff_path_size(5, path_len));
- dpath->path = (char *) &(dpath->parent[5]);
-
- dpath->next = NULL;
- memcpy(dpath->path, ce->name, path_len);
- dpath->path[path_len] = '\0';
- oidclr(&dpath->oid, the_repository->hash_algo);
- memset(&(dpath->parent[0]), 0,
- sizeof(struct combine_diff_parent)*5);
-
changed = check_removed(ce, &st);
if (!changed)
wt_mode = ce_mode_from_stat(ce, st.st_mode);
@@ -178,7 +165,14 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
}
wt_mode = 0;
}
- dpath->mode = wt_mode;
+
+ /*
+ * Allocate space for two parents, which will come from
+ * index stages #2 and #3, if present. Below we'll fill
+ * these from (stage - 2).
+ */
+ dpath = combine_diff_path_new(ce->name, ce_namelen(ce),
+ wt_mode, null_oid(), 2);
while (i < entries) {
struct cache_entry *nce = istate->cache[i];
@@ -405,16 +399,10 @@ static int show_modified(struct rev_info *revs,
if (revs->combine_merges && !cached &&
(!oideq(oid, &old_entry->oid) || !oideq(&old_entry->oid, &new_entry->oid))) {
struct combine_diff_path *p;
- int pathlen = ce_namelen(new_entry);
-
- p = xmalloc(combine_diff_path_size(2, pathlen));
- p->path = (char *) &p->parent[2];
- p->next = NULL;
- memcpy(p->path, new_entry->name, pathlen);
- p->path[pathlen] = 0;
- p->mode = mode;
- oidclr(&p->oid, the_repository->hash_algo);
- memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
+
+ p = combine_diff_path_new(new_entry->name,
+ ce_namelen(new_entry),
+ mode, null_oid(), 2);
p->parent[0].status = DIFF_STATUS_MODIFIED;
p->parent[0].mode = new_entry->ce_mode;
oidcpy(&p->parent[0].oid, &new_entry->oid);