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 <gitster@pobox.com>
Junio C Hamano committed
Feb 27, 2009 at 23:43 UTC
386cb77210cdb09cd808698d21d0e796cd77f26f
4 files changed
+17
-21
builtin-pack-objects.c
+2
-10
@@ -1915,11 +1915,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
1915
const unsigned char *sha1;
1916
struct object *o;
1917
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))
1919
continue;
1920
if (open_pack_index(p))
1921
die("cannot open pack index");
@@ -1955,11 +1951,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
1951
const unsigned char *sha1;
1952
1953
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))
1955
continue;
1956
1957
if (open_pack_index(p))
cache.h
-1
@@ -747,7 +747,6 @@ extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsign
747
extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
748
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
749
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);
750
751
/* Dumb servers support */
752
extern int update_server_info(int);
revision.h
+1
@@ -159,5 +159,6 @@ enum commit_action {
159
extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
160
161
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 *);
163
164
#endif
sha1_file.c
+14
-10
@@ -1858,7 +1858,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
1858
return 0;
1859
}
1860
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)
1862
{
1863
const char *last_c, *c;
1864
@@ -1876,6 +1876,17 @@ int matches_pack_name(struct packed_git *p, const char *name)
1876
return 0;
1877
}
1878
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
+
1890
static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e,
1891
const struct rev_info *revs)
1892
{
@@ -1889,15 +1900,8 @@ static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e,
1900
p = (last_found == (void *)1) ? packed_git : last_found;
1901
1902
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;
1905
if (p->num_bad_objects) {
1906
unsigned i;
1907
for (i = 0; i < p->num_bad_objects; i++)