Skip to content

Commit 3e8e32c

Browse files
Kevin Willfordgitster
authored andcommitted
patch-ids: add flag to create the diff patch id using header only data
This will allow a diff patch id to be created using only the header data so that the contents of the file will not have to be loaded. Signed-off-by: Kevin Willford <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 683f17e commit 3e8e32c

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

diff.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4449,7 +4449,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
44494449
}
44504450

44514451
/* returns 0 upon success, and writes result into sha1 */
4452-
static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
4452+
static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only)
44534453
{
44544454
struct diff_queue_struct *q = &diff_queued_diff;
44554455
int i;
@@ -4484,9 +4484,6 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
44844484

44854485
diff_fill_sha1_info(p->one);
44864486
diff_fill_sha1_info(p->two);
4487-
if (fill_mmfile(&mf1, p->one) < 0 ||
4488-
fill_mmfile(&mf2, p->two) < 0)
4489-
return error("unable to read files to diff");
44904487

44914488
len1 = remove_space(p->one->path, strlen(p->one->path));
44924489
len2 = remove_space(p->two->path, strlen(p->two->path));
@@ -4521,6 +4518,13 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
45214518
len2, p->two->path);
45224519
git_SHA1_Update(&ctx, buffer, len1);
45234520

4521+
if (diff_header_only)
4522+
continue;
4523+
4524+
if (fill_mmfile(&mf1, p->one) < 0 ||
4525+
fill_mmfile(&mf2, p->two) < 0)
4526+
return error("unable to read files to diff");
4527+
45244528
if (diff_filespec_is_binary(p->one) ||
45254529
diff_filespec_is_binary(p->two)) {
45264530
git_SHA1_Update(&ctx, sha1_to_hex(p->one->sha1), 40);
@@ -4541,11 +4545,11 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
45414545
return 0;
45424546
}
45434547

4544-
int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1)
4548+
int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only)
45454549
{
45464550
struct diff_queue_struct *q = &diff_queued_diff;
45474551
int i;
4548-
int result = diff_get_patch_id(options, sha1);
4552+
int result = diff_get_patch_id(options, sha1, diff_header_only);
45494553

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

diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ extern int run_diff_files(struct rev_info *revs, unsigned int option);
342342
extern int run_diff_index(struct rev_info *revs, int cached);
343343

344344
extern int do_diff_cache(const unsigned char *, struct diff_options *);
345-
extern int diff_flush_patch_id(struct diff_options *, unsigned char *);
345+
extern int diff_flush_patch_id(struct diff_options *, unsigned char *, int);
346346

347347
extern int diff_result_code(struct diff_options *, int);
348348

patch-ids.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int commit_patch_id(struct commit *commit, struct diff_options *options,
1313
else
1414
diff_root_tree_sha1(commit->object.oid.hash, "", options);
1515
diffcore_std(options);
16-
return diff_flush_patch_id(options, sha1);
16+
return diff_flush_patch_id(options, sha1, 0);
1717
}
1818

1919
static int patch_id_cmp(struct patch_id *a,

0 commit comments

Comments
 (0)