Skip to content

Commit 386cb77

Browse files
committed
Consolidate ignore_packed logic more
This refactors three loops that check if a given packfile is on the ignore_packed list into a function is_kept_pack(). The function returns false for a pack on the list, and true for a pack not on the list, because this list is solely used by "git repack" to pass list of packfiles that do not have corresponding .keep files, i.e. a packfile not on the list is "kept". Signed-off-by: Junio C Hamano <[email protected]>
1 parent b8431b0 commit 386cb77

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

builtin-pack-objects.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,11 +1915,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
19151915
const unsigned char *sha1;
19161916
struct object *o;
19171917

1918-
for (i = 0; i < revs->num_ignore_packed; i++) {
1919-
if (matches_pack_name(p, revs->ignore_packed[i]))
1920-
break;
1921-
}
1922-
if (revs->num_ignore_packed <= i)
1918+
if (is_kept_pack(p, revs))
19231919
continue;
19241920
if (open_pack_index(p))
19251921
die("cannot open pack index");
@@ -1955,11 +1951,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
19551951
const unsigned char *sha1;
19561952

19571953
for (p = packed_git; p; p = p->next) {
1958-
for (i = 0; i < revs->num_ignore_packed; i++) {
1959-
if (matches_pack_name(p, revs->ignore_packed[i]))
1960-
break;
1961-
}
1962-
if (revs->num_ignore_packed <= i)
1954+
if (is_kept_pack(p, revs))
19631955
continue;
19641956

19651957
if (open_pack_index(p))

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,6 @@ extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsign
747747
extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
748748
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
749749
extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
750-
extern int matches_pack_name(struct packed_git *p, const char *name);
751750

752751
/* Dumb servers support */
753752
extern int update_server_info(int);

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,6 @@ enum commit_action {
159159
extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
160160

161161
extern int has_sha1_kept_pack(const unsigned char *sha1, const struct rev_info *);
162+
extern int is_kept_pack(const struct packed_git *, const struct rev_info *);
162163

163164
#endif

sha1_file.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
18581858
return 0;
18591859
}
18601860

1861-
int matches_pack_name(struct packed_git *p, const char *name)
1861+
static int matches_pack_name(const struct packed_git *p, const char *name)
18621862
{
18631863
const char *last_c, *c;
18641864

@@ -1876,6 +1876,17 @@ int matches_pack_name(struct packed_git *p, const char *name)
18761876
return 0;
18771877
}
18781878

1879+
int is_kept_pack(const struct packed_git *p, const struct rev_info *revs)
1880+
{
1881+
int i;
1882+
1883+
for (i = 0; i < revs->num_ignore_packed; i++) {
1884+
if (matches_pack_name(p, revs->ignore_packed[i]))
1885+
return 0;
1886+
}
1887+
return 1;
1888+
}
1889+
18791890
static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e,
18801891
const struct rev_info *revs)
18811892
{
@@ -1889,15 +1900,8 @@ static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e,
18891900
p = (last_found == (void *)1) ? packed_git : last_found;
18901901

18911902
do {
1892-
if (revs->ignore_packed) {
1893-
const char **ig;
1894-
for (ig = revs->ignore_packed; *ig; ig++)
1895-
if (matches_pack_name(p, *ig))
1896-
break;
1897-
if (*ig)
1898-
goto next;
1899-
}
1900-
1903+
if (revs->ignore_packed && !is_kept_pack(p, revs))
1904+
goto next;
19011905
if (p->num_bad_objects) {
19021906
unsigned i;
19031907
for (i = 0; i < p->num_bad_objects; i++)

0 commit comments

Comments
 (0)