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 <kcwillford@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kevin Willford committed
Jul 29, 2016 at 12:19 UTC
3e8e32c32ef8e49bcfd715837d51aca30925fdfe
3 files changed
+12
-8
diff.c
+10
-6
@@ -4449,7 +4449,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
4449
}
4450
4451
/* 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)
4453
{
4454
struct diff_queue_struct *q = &diff_queued_diff;
4455
int i;
@@ -4484,9 +4484,6 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
4484
4485
diff_fill_sha1_info(p->one);
4486
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");
4487
4488
len1 = remove_space(p->one->path, strlen(p->one->path));
4489
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)
4518
len2, p->two->path);
4519
git_SHA1_Update(&ctx, buffer, len1);
4520
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
+
4528
if (diff_filespec_is_binary(p->one) ||
4529
diff_filespec_is_binary(p->two)) {
4530
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)
4545
return 0;
4546
}
4547
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)
4549
{
4550
struct diff_queue_struct *q = &diff_queued_diff;
4551
int i;
4548
- int result = diff_get_patch_id(options, sha1);
4552
+ int result = diff_get_patch_id(options, sha1, diff_header_only);
4553
4554
for (i = 0; i < q->nr; i++)
4555
diff_free_filepair(q->queue[i]);
diff.h
+1
-1
@@ -342,7 +342,7 @@ extern int run_diff_files(struct rev_info *revs, unsigned int option);
342
extern int run_diff_index(struct rev_info *revs, int cached);
343
344
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);
346
347
extern int diff_result_code(struct diff_options *, int);
348
patch-ids.c
+1
-1
@@ -13,7 +13,7 @@ int commit_patch_id(struct commit *commit, struct diff_options *options,
13
else
14
diff_root_tree_sha1(commit->object.oid.hash, "", options);
15
diffcore_std(options);
16
- return diff_flush_patch_id(options, sha1);
16
+ return diff_flush_patch_id(options, sha1, 0);
17
}
18
19
static int patch_id_cmp(struct patch_id *a,