Skip to content

Commit 1c37e86

Browse files
jonathantanmygitster
authored andcommitted
diff: make diff_populate_filespec_options struct
The behavior of diff_populate_filespec() currently can be customized through a bitflag, but a subsequent patch requires it to support a non-boolean option. Replace the bitflag with an options struct. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent db7ed74 commit 1c37e86

File tree

5 files changed

+54
-32
lines changed

5 files changed

+54
-32
lines changed

diff.c

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int fill_mmfile(struct repository *r, mmfile_t *mf,
573573
mf->size = 0;
574574
return 0;
575575
}
576-
else if (diff_populate_filespec(r, one, 0))
576+
else if (diff_populate_filespec(r, one, NULL))
577577
return -1;
578578

579579
mf->ptr = one->data;
@@ -585,9 +585,13 @@ static int fill_mmfile(struct repository *r, mmfile_t *mf,
585585
static unsigned long diff_filespec_size(struct repository *r,
586586
struct diff_filespec *one)
587587
{
588+
struct diff_populate_filespec_options dpf_options = {
589+
.check_size_only = 1,
590+
};
591+
588592
if (!DIFF_FILE_VALID(one))
589593
return 0;
590-
diff_populate_filespec(r, one, CHECK_SIZE_ONLY);
594+
diff_populate_filespec(r, one, &dpf_options);
591595
return one->size;
592596
}
593597

@@ -3020,6 +3024,9 @@ static void show_dirstat(struct diff_options *options)
30203024
struct diff_filepair *p = q->queue[i];
30213025
const char *name;
30223026
unsigned long copied, added, damage;
3027+
struct diff_populate_filespec_options dpf_options = {
3028+
.check_size_only = 1,
3029+
};
30233030

30243031
name = p->two->path ? p->two->path : p->one->path;
30253032

@@ -3047,19 +3054,19 @@ static void show_dirstat(struct diff_options *options)
30473054
}
30483055

30493056
if (DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
3050-
diff_populate_filespec(options->repo, p->one, 0);
3051-
diff_populate_filespec(options->repo, p->two, 0);
3057+
diff_populate_filespec(options->repo, p->one, NULL);
3058+
diff_populate_filespec(options->repo, p->two, NULL);
30523059
diffcore_count_changes(options->repo,
30533060
p->one, p->two, NULL, NULL,
30543061
&copied, &added);
30553062
diff_free_filespec_data(p->one);
30563063
diff_free_filespec_data(p->two);
30573064
} else if (DIFF_FILE_VALID(p->one)) {
3058-
diff_populate_filespec(options->repo, p->one, CHECK_SIZE_ONLY);
3065+
diff_populate_filespec(options->repo, p->one, &dpf_options);
30593066
copied = added = 0;
30603067
diff_free_filespec_data(p->one);
30613068
} else if (DIFF_FILE_VALID(p->two)) {
3062-
diff_populate_filespec(options->repo, p->two, CHECK_SIZE_ONLY);
3069+
diff_populate_filespec(options->repo, p->two, &dpf_options);
30633070
copied = 0;
30643071
added = p->two->size;
30653072
diff_free_filespec_data(p->two);
@@ -3339,13 +3346,17 @@ static void emit_binary_diff(struct diff_options *o,
33393346
int diff_filespec_is_binary(struct repository *r,
33403347
struct diff_filespec *one)
33413348
{
3349+
struct diff_populate_filespec_options dpf_options = {
3350+
.check_binary = 1,
3351+
};
3352+
33423353
if (one->is_binary == -1) {
33433354
diff_filespec_load_driver(one, r->index);
33443355
if (one->driver->binary != -1)
33453356
one->is_binary = one->driver->binary;
33463357
else {
33473358
if (!one->data && DIFF_FILE_VALID(one))
3348-
diff_populate_filespec(r, one, CHECK_BINARY);
3359+
diff_populate_filespec(r, one, &dpf_options);
33493360
if (one->is_binary == -1 && one->data)
33503361
one->is_binary = buffer_is_binary(one->data,
33513362
one->size);
@@ -3677,8 +3688,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
36773688
}
36783689

36793690
else if (complete_rewrite) {
3680-
diff_populate_filespec(o->repo, one, 0);
3681-
diff_populate_filespec(o->repo, two, 0);
3691+
diff_populate_filespec(o->repo, one, NULL);
3692+
diff_populate_filespec(o->repo, two, NULL);
36823693
data->deleted = count_lines(one->data, one->size);
36833694
data->added = count_lines(two->data, two->size);
36843695
}
@@ -3914,9 +3925,10 @@ static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
39143925
*/
39153926
int diff_populate_filespec(struct repository *r,
39163927
struct diff_filespec *s,
3917-
unsigned int flags)
3928+
const struct diff_populate_filespec_options *options)
39183929
{
3919-
int size_only = flags & CHECK_SIZE_ONLY;
3930+
int size_only = options ? options->check_size_only : 0;
3931+
int check_binary = options ? options->check_binary : 0;
39203932
int err = 0;
39213933
int conv_flags = global_conv_flags_eol;
39223934
/*
@@ -3986,7 +3998,7 @@ int diff_populate_filespec(struct repository *r,
39863998
* opening the file and inspecting the contents, this
39873999
* is probably fine.
39884000
*/
3989-
if ((flags & CHECK_BINARY) &&
4001+
if (check_binary &&
39904002
s->size > big_file_threshold && s->is_binary == -1) {
39914003
s->is_binary = 1;
39924004
return 0;
@@ -4012,7 +4024,7 @@ int diff_populate_filespec(struct repository *r,
40124024
}
40134025
else {
40144026
enum object_type type;
4015-
if (size_only || (flags & CHECK_BINARY)) {
4027+
if (size_only || check_binary) {
40164028
type = oid_object_info(r, &s->oid, &s->size);
40174029
if (type < 0)
40184030
die("unable to read %s",
@@ -4141,7 +4153,7 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
41414153
return temp;
41424154
}
41434155
else {
4144-
if (diff_populate_filespec(r, one, 0))
4156+
if (diff_populate_filespec(r, one, NULL))
41454157
die("cannot read data blob for %s", one->path);
41464158
prep_temp_blob(r->index, name, temp,
41474159
one->data, one->size,
@@ -6407,16 +6419,20 @@ static int diff_filespec_is_identical(struct repository *r,
64076419
{
64086420
if (S_ISGITLINK(one->mode))
64096421
return 0;
6410-
if (diff_populate_filespec(r, one, 0))
6422+
if (diff_populate_filespec(r, one, NULL))
64116423
return 0;
6412-
if (diff_populate_filespec(r, two, 0))
6424+
if (diff_populate_filespec(r, two, NULL))
64136425
return 0;
64146426
return !memcmp(one->data, two->data, one->size);
64156427
}
64166428

64176429
static int diff_filespec_check_stat_unmatch(struct repository *r,
64186430
struct diff_filepair *p)
64196431
{
6432+
struct diff_populate_filespec_options dpf_options = {
6433+
.check_size_only = 1,
6434+
};
6435+
64206436
if (p->done_skip_stat_unmatch)
64216437
return p->skip_stat_unmatch_result;
64226438

@@ -6439,8 +6455,8 @@ static int diff_filespec_check_stat_unmatch(struct repository *r,
64396455
!DIFF_FILE_VALID(p->two) ||
64406456
(p->one->oid_valid && p->two->oid_valid) ||
64416457
(p->one->mode != p->two->mode) ||
6442-
diff_populate_filespec(r, p->one, CHECK_SIZE_ONLY) ||
6443-
diff_populate_filespec(r, p->two, CHECK_SIZE_ONLY) ||
6458+
diff_populate_filespec(r, p->one, &dpf_options) ||
6459+
diff_populate_filespec(r, p->two, &dpf_options) ||
64446460
(p->one->size != p->two->size) ||
64456461
!diff_filespec_is_identical(r, p->one, p->two)) /* (2) */
64466462
p->skip_stat_unmatch_result = 1;
@@ -6770,7 +6786,7 @@ size_t fill_textconv(struct repository *r,
67706786
*outbuf = "";
67716787
return 0;
67726788
}
6773-
if (diff_populate_filespec(r, df, 0))
6789+
if (diff_populate_filespec(r, df, NULL))
67746790
die("unable to read files to diff");
67756791
*outbuf = df->data;
67766792
return df->size;

diffcore-break.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ static int should_break(struct repository *r,
6262
oideq(&src->oid, &dst->oid))
6363
return 0; /* they are the same */
6464

65-
if (diff_populate_filespec(r, src, 0) ||
66-
diff_populate_filespec(r, dst, 0))
65+
if (diff_populate_filespec(r, src, NULL) ||
66+
diff_populate_filespec(r, dst, NULL))
6767
return 0; /* error but caught downstream */
6868

6969
max_size = ((src->size > dst->size) ? src->size : dst->size);

diffcore-rename.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ static int estimate_similarity(struct repository *r,
148148
*/
149149
unsigned long max_size, delta_size, base_size, src_copied, literal_added;
150150
int score;
151+
struct diff_populate_filespec_options dpf_options = {
152+
.check_size_only = 1
153+
};
151154

152155
/* We deal only with regular files. Symlink renames are handled
153156
* only when they are exact matches --- in other words, no edits
@@ -166,10 +169,10 @@ static int estimate_similarity(struct repository *r,
166169
* say whether the size is valid or not!)
167170
*/
168171
if (!src->cnt_data &&
169-
diff_populate_filespec(r, src, CHECK_SIZE_ONLY))
172+
diff_populate_filespec(r, src, &dpf_options))
170173
return 0;
171174
if (!dst->cnt_data &&
172-
diff_populate_filespec(r, dst, CHECK_SIZE_ONLY))
175+
diff_populate_filespec(r, dst, &dpf_options))
173176
return 0;
174177

175178
max_size = ((src->size > dst->size) ? src->size : dst->size);
@@ -187,9 +190,9 @@ static int estimate_similarity(struct repository *r,
187190
if (max_size * (MAX_SCORE-minimum_score) < delta_size * MAX_SCORE)
188191
return 0;
189192

190-
if (!src->cnt_data && diff_populate_filespec(r, src, 0))
193+
if (!src->cnt_data && diff_populate_filespec(r, src, NULL))
191194
return 0;
192-
if (!dst->cnt_data && diff_populate_filespec(r, dst, 0))
195+
if (!dst->cnt_data && diff_populate_filespec(r, dst, NULL))
193196
return 0;
194197

195198
if (diffcore_count_changes(r, src, dst,
@@ -261,7 +264,7 @@ static unsigned int hash_filespec(struct repository *r,
261264
struct diff_filespec *filespec)
262265
{
263266
if (!filespec->oid_valid) {
264-
if (diff_populate_filespec(r, filespec, 0))
267+
if (diff_populate_filespec(r, filespec, NULL))
265268
return 0;
266269
hash_object_file(r->hash_algo, filespec->data, filespec->size,
267270
"blob", &filespec->oid);

diffcore.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ void free_filespec(struct diff_filespec *);
6565
void fill_filespec(struct diff_filespec *, const struct object_id *,
6666
int, unsigned short);
6767

68-
#define CHECK_SIZE_ONLY 1
69-
#define CHECK_BINARY 2
70-
int diff_populate_filespec(struct repository *, struct diff_filespec *, unsigned int);
68+
struct diff_populate_filespec_options {
69+
unsigned check_size_only : 1;
70+
unsigned check_binary : 1;
71+
};
72+
int diff_populate_filespec(struct repository *, struct diff_filespec *,
73+
const struct diff_populate_filespec_options *);
7174
void diff_free_filespec_data(struct diff_filespec *);
7275
void diff_free_filespec_blob(struct diff_filespec *);
7376
int diff_filespec_is_binary(struct repository *, struct diff_filespec *);

line-log.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static void fill_line_ends(struct repository *r,
519519
unsigned long *ends = NULL;
520520
char *data = NULL;
521521

522-
if (diff_populate_filespec(r, spec, 0))
522+
if (diff_populate_filespec(r, spec, NULL))
523523
die("Cannot read blob %s", oid_to_hex(&spec->oid));
524524

525525
ALLOC_ARRAY(ends, size);
@@ -1045,12 +1045,12 @@ static int process_diff_filepair(struct rev_info *rev,
10451045
return 0;
10461046

10471047
assert(pair->two->oid_valid);
1048-
diff_populate_filespec(rev->diffopt.repo, pair->two, 0);
1048+
diff_populate_filespec(rev->diffopt.repo, pair->two, NULL);
10491049
file_target.ptr = pair->two->data;
10501050
file_target.size = pair->two->size;
10511051

10521052
if (pair->one->oid_valid) {
1053-
diff_populate_filespec(rev->diffopt.repo, pair->one, 0);
1053+
diff_populate_filespec(rev->diffopt.repo, pair->one, NULL);
10541054
file_parent.ptr = pair->one->data;
10551055
file_parent.size = pair->one->size;
10561056
} else {

0 commit comments

Comments
 (0)