Skip to content

Commit 51276c1

Browse files
jerry-skydiogitster
authored andcommitted
patch-id: use stable patch-id for rebases
Git doesn't persist patch-ids during the rebase process, so there is no need to specifically invoke the unstable variant. Use the stable logic for all internal patch-id calculations to minimize the number of code paths and improve test coverage. Signed-off-by: Jerry Zhang <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0570be7 commit 51276c1

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ static void prepare_bases(struct base_tree_info *bases,
16941694
struct object_id *patch_id;
16951695
if (*commit_base_at(&commit_base, commit))
16961696
continue;
1697-
if (commit_patch_id(commit, &diffopt, &oid, 0, 1))
1697+
if (commit_patch_id(commit, &diffopt, &oid, 0))
16981698
die(_("cannot get patch id"));
16991699
ALLOC_GROW(bases->patch_id, bases->nr_patch_id + 1, bases->alloc_patch_id);
17001700
patch_id = bases->patch_id + bases->nr_patch_id;

diff.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6174,7 +6174,7 @@ static void patch_id_add_mode(git_hash_ctx *ctx, unsigned mode)
61746174
}
61756175

61766176
/* returns 0 upon success, and writes result into oid */
6177-
static int diff_get_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only, int stable)
6177+
static int diff_get_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only)
61786178
{
61796179
struct diff_queue_struct *q = &diff_queued_diff;
61806180
int i;
@@ -6261,21 +6261,17 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
62616261
return error("unable to generate patch-id diff for %s",
62626262
p->one->path);
62636263
}
6264-
if (stable)
6265-
flush_one_hunk(oid, &ctx);
6264+
flush_one_hunk(oid, &ctx);
62666265
}
62676266

6268-
if (!stable)
6269-
the_hash_algo->final_oid_fn(oid, &ctx);
6270-
62716267
return 0;
62726268
}
62736269

6274-
int diff_flush_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only, int stable)
6270+
int diff_flush_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only)
62756271
{
62766272
struct diff_queue_struct *q = &diff_queued_diff;
62776273
int i;
6278-
int result = diff_get_patch_id(options, oid, diff_header_only, stable);
6274+
int result = diff_get_patch_id(options, oid, diff_header_only);
62796275

62806276
for (i = 0; i < q->nr; i++)
62816277
diff_free_filepair(q->queue[i]);

diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option);
634634
int run_diff_index(struct rev_info *revs, unsigned int option);
635635

636636
int do_diff_cache(const struct object_id *, struct diff_options *);
637-
int diff_flush_patch_id(struct diff_options *, struct object_id *, int, int);
637+
int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
638638
void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx);
639639

640640
int diff_result_code(struct diff_options *, int);

patch-ids.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static int patch_id_defined(struct commit *commit)
1111
}
1212

1313
int commit_patch_id(struct commit *commit, struct diff_options *options,
14-
struct object_id *oid, int diff_header_only, int stable)
14+
struct object_id *oid, int diff_header_only)
1515
{
1616
if (!patch_id_defined(commit))
1717
return -1;
@@ -22,7 +22,7 @@ int commit_patch_id(struct commit *commit, struct diff_options *options,
2222
else
2323
diff_root_tree_oid(&commit->object.oid, "", options);
2424
diffcore_std(options);
25-
return diff_flush_patch_id(options, oid, diff_header_only, stable);
25+
return diff_flush_patch_id(options, oid, diff_header_only);
2626
}
2727

2828
/*
@@ -48,11 +48,11 @@ static int patch_id_neq(const void *cmpfn_data,
4848
b = container_of(entry_or_key, struct patch_id, ent);
4949

5050
if (is_null_oid(&a->patch_id) &&
51-
commit_patch_id(a->commit, opt, &a->patch_id, 0, 0))
51+
commit_patch_id(a->commit, opt, &a->patch_id, 0))
5252
return error("Could not get patch ID for %s",
5353
oid_to_hex(&a->commit->object.oid));
5454
if (is_null_oid(&b->patch_id) &&
55-
commit_patch_id(b->commit, opt, &b->patch_id, 0, 0))
55+
commit_patch_id(b->commit, opt, &b->patch_id, 0))
5656
return error("Could not get patch ID for %s",
5757
oid_to_hex(&b->commit->object.oid));
5858
return !oideq(&a->patch_id, &b->patch_id);
@@ -82,7 +82,7 @@ static int init_patch_id_entry(struct patch_id *patch,
8282
struct object_id header_only_patch_id;
8383

8484
patch->commit = commit;
85-
if (commit_patch_id(commit, &ids->diffopts, &header_only_patch_id, 1, 0))
85+
if (commit_patch_id(commit, &ids->diffopts, &header_only_patch_id, 1))
8686
return -1;
8787

8888
hashmap_entry_init(&patch->ent, oidhash(&header_only_patch_id));

patch-ids.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct patch_ids {
2020
};
2121

2222
int commit_patch_id(struct commit *commit, struct diff_options *options,
23-
struct object_id *oid, int, int);
23+
struct object_id *oid, int);
2424
int init_patch_ids(struct repository *, struct patch_ids *);
2525
int free_patch_ids(struct patch_ids *);
2626

0 commit comments

Comments
 (0)