Skip to content

Commit f19d513

Browse files
Kevin Willforddscho
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 4bcb864 commit f19d513

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
@@ -4456,7 +4456,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
44564456
}
44574457

44584458
/* returns 0 upon success, and writes result into sha1 */
4459-
static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
4459+
static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only)
44604460
{
44614461
struct diff_queue_struct *q = &diff_queued_diff;
44624462
int i;
@@ -4491,9 +4491,6 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
44914491

44924492
diff_fill_sha1_info(p->one);
44934493
diff_fill_sha1_info(p->two);
4494-
if (fill_mmfile(&mf1, p->one) < 0 ||
4495-
fill_mmfile(&mf2, p->two) < 0)
4496-
return error("unable to read files to diff");
44974494

44984495
len1 = remove_space(p->one->path, strlen(p->one->path));
44994496
len2 = remove_space(p->two->path, strlen(p->two->path));
@@ -4528,6 +4525,13 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
45284525
len2, p->two->path);
45294526
git_SHA1_Update(&ctx, buffer, len1);
45304527

4528+
if (diff_header_only)
4529+
continue;
4530+
4531+
if (fill_mmfile(&mf1, p->one) < 0 ||
4532+
fill_mmfile(&mf2, p->two) < 0)
4533+
return error("unable to read files to diff");
4534+
45314535
if (diff_filespec_is_binary(p->one) ||
45324536
diff_filespec_is_binary(p->two)) {
45334537
git_SHA1_Update(&ctx, sha1_to_hex(p->one->sha1), 40);
@@ -4548,11 +4552,11 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
45484552
return 0;
45494553
}
45504554

4551-
int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1)
4555+
int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only)
45524556
{
45534557
struct diff_queue_struct *q = &diff_queued_diff;
45544558
int i;
4555-
int result = diff_get_patch_id(options, sha1);
4559+
int result = diff_get_patch_id(options, sha1, diff_header_only);
45564560

45574561
for (i = 0; i < q->nr; i++)
45584562
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)