Skip to content

Commit cd673c1

Browse files
committed
has_sha1_pack(): refactor "pretend these packs do not exist" interface
Most of the callers of this function except only one pass NULL to its last parameter, ignore_packed. Introduce has_sha1_kept_pack() function that has the function signature and the semantics of this function, and convert the sole caller that does not pass NULL to call this new function. All other callers and has_sha1_pack() lose the ignore_packed parameter. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2478dc8 commit cd673c1

File tree

7 files changed

+33
-13
lines changed

7 files changed

+33
-13
lines changed

builtin-count-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
6161
hex[40] = 0;
6262
if (get_sha1_hex(hex, sha1))
6363
die("internal error");
64-
if (has_sha1_pack(sha1, NULL))
64+
if (has_sha1_pack(sha1))
6565
(*packed_loose)++;
6666
}
6767
}

builtin-fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static void check_reachable_object(struct object *obj)
158158
* do a full fsck
159159
*/
160160
if (!obj->parsed) {
161-
if (has_sha1_pack(obj->sha1, NULL))
161+
if (has_sha1_pack(obj->sha1))
162162
return; /* it is in pack - forget about it */
163163
printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
164164
errors_found |= ERROR_REACHABLE;

builtin-prune-packed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
2323
memcpy(hex+2, de->d_name, 38);
2424
if (get_sha1_hex(hex, sha1))
2525
continue;
26-
if (!has_sha1_pack(sha1, NULL))
26+
if (!has_sha1_pack(sha1))
2727
continue;
2828
memcpy(pathname + len, de->d_name, 38);
2929
if (opts & DRY_RUN)

cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l
565565

566566
extern int move_temp_to_file(const char *tmpfile, const char *filename);
567567

568-
extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
568+
extern int has_sha1_pack(const unsigned char *sha1);
569+
extern int has_sha1_kept_pack(const unsigned char *sha1, const char **ignore);
569570
extern int has_sha1_file(const unsigned char *sha1);
570571
extern int has_loose_object_nonlocal(const unsigned char *sha1);
571572

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
17431743
* objects however would tend to be slower as they need
17441744
* to be individually opened and inflated.
17451745
*/
1746-
if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1, NULL))
1746+
if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1))
17471747
return 0;
17481748

17491749
len = strlen(name);

revision.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,8 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
14851485
{
14861486
if (commit->object.flags & SHOWN)
14871487
return commit_ignore;
1488-
if (revs->unpacked && has_sha1_pack(commit->object.sha1, revs->ignore_packed))
1488+
if (revs->unpacked &&
1489+
has_sha1_kept_pack(commit->object.sha1, revs->ignore_packed))
14891490
return commit_ignore;
14901491
if (revs->show_all)
14911492
return commit_show;

sha1_file.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,8 @@ int matches_pack_name(struct packed_git *p, const char *name)
18741874
return 0;
18751875
}
18761876

1877-
static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
1877+
static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e,
1878+
const char **ignore_packed)
18781879
{
18791880
static struct packed_git *last_found = (void *)1;
18801881
struct packed_git *p;
@@ -1934,6 +1935,17 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, cons
19341935
return 0;
19351936
}
19361937

1938+
static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
1939+
{
1940+
return find_pack_ent(sha1, e, NULL);
1941+
}
1942+
1943+
static int find_kept_pack_entry(const unsigned char *sha1, struct pack_entry *e,
1944+
const char **ignore_packed)
1945+
{
1946+
return find_pack_ent(sha1, e, ignore_packed);
1947+
}
1948+
19371949
struct packed_git *find_sha1_pack(const unsigned char *sha1,
19381950
struct packed_git *packs)
19391951
{
@@ -1975,15 +1987,15 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
19751987
struct pack_entry e;
19761988
int status;
19771989

1978-
if (!find_pack_entry(sha1, &e, NULL)) {
1990+
if (!find_pack_entry(sha1, &e)) {
19791991
/* Most likely it's a loose object. */
19801992
status = sha1_loose_object_info(sha1, sizep);
19811993
if (status >= 0)
19821994
return status;
19831995

19841996
/* Not a loose object; someone else may have just packed it. */
19851997
reprepare_packed_git();
1986-
if (!find_pack_entry(sha1, &e, NULL))
1998+
if (!find_pack_entry(sha1, &e))
19871999
return status;
19882000
}
19892001
return packed_object_info(e.p, e.offset, sizep);
@@ -1995,7 +2007,7 @@ static void *read_packed_sha1(const unsigned char *sha1,
19952007
struct pack_entry e;
19962008
void *data;
19972009

1998-
if (!find_pack_entry(sha1, &e, NULL))
2010+
if (!find_pack_entry(sha1, &e))
19992011
return NULL;
20002012
data = cache_or_unpack_entry(e.p, e.offset, size, type, 1);
20012013
if (!data) {
@@ -2395,17 +2407,23 @@ int has_pack_file(const unsigned char *sha1)
23952407
return 1;
23962408
}
23972409

2398-
int has_sha1_pack(const unsigned char *sha1, const char **ignore_packed)
2410+
int has_sha1_pack(const unsigned char *sha1)
2411+
{
2412+
struct pack_entry e;
2413+
return find_pack_entry(sha1, &e);
2414+
}
2415+
2416+
int has_sha1_kept_pack(const unsigned char *sha1, const char **ignore_packed)
23992417
{
24002418
struct pack_entry e;
2401-
return find_pack_entry(sha1, &e, ignore_packed);
2419+
return find_kept_pack_entry(sha1, &e, ignore_packed);
24022420
}
24032421

24042422
int has_sha1_file(const unsigned char *sha1)
24052423
{
24062424
struct pack_entry e;
24072425

2408-
if (find_pack_entry(sha1, &e, NULL))
2426+
if (find_pack_entry(sha1, &e))
24092427
return 1;
24102428
return has_loose_object(sha1);
24112429
}

0 commit comments

Comments
 (0)