@matheusbsbs / matheus-bagliano / commits / cd673c1f17
Fork 0

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 <gitster@pobox.com>

Junio C Hamano committed Feb 27, 2009 at 23:15 UTC cd673c1f17228d272c4b7f81fbb28bc31cf0cac6
7 files changed +33 -13
builtin-count-objects.c
+1 -1
@@ -61,7 +61,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
61 hex[40] = 0;
62 if (get_sha1_hex(hex, sha1))
63 die("internal error");
64 - if (has_sha1_pack(sha1, NULL))
64 + if (has_sha1_pack(sha1))
65 (*packed_loose)++;
66 }
67 }
builtin-fsck.c
+1 -1
@@ -158,7 +158,7 @@ static void check_reachable_object(struct object *obj)
158 * do a full fsck
159 */
160 if (!obj->parsed) {
161 - if (has_sha1_pack(obj->sha1, NULL))
161 + if (has_sha1_pack(obj->sha1))
162 return; /* it is in pack - forget about it */
163 printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
164 errors_found |= ERROR_REACHABLE;
builtin-prune-packed.c
+1 -1
@@ -23,7 +23,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
23 memcpy(hex+2, de->d_name, 38);
24 if (get_sha1_hex(hex, sha1))
25 continue;
26 - if (!has_sha1_pack(sha1, NULL))
26 + if (!has_sha1_pack(sha1))
27 continue;
28 memcpy(pathname + len, de->d_name, 38);
29 if (opts & DRY_RUN)
cache.h
+2 -1
@@ -565,7 +565,8 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l
565
566 extern int move_temp_to_file(const char *tmpfile, const char *filename);
567
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);
570 extern int has_sha1_file(const unsigned char *sha1);
571 extern int has_loose_object_nonlocal(const unsigned char *sha1);
572
diff.c
+1 -1
@@ -1743,7 +1743,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
1743 * objects however would tend to be slower as they need
1744 * to be individually opened and inflated.
1745 */
1746 - if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1, NULL))
1746 + if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1))
1747 return 0;
1748
1749 len = strlen(name);
revision.c
+2 -1
@@ -1485,7 +1485,8 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
1485 {
1486 if (commit->object.flags & SHOWN)
1487 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))
1490 return commit_ignore;
1491 if (revs->show_all)
1492 return commit_show;
sha1_file.c
+25 -7
@@ -1874,7 +1874,8 @@ int matches_pack_name(struct packed_git *p, const char *name)
1874 return 0;
1875 }
1876
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)
1879 {
1880 static struct packed_git *last_found = (void *)1;
1881 struct packed_git *p;
@@ -1934,6 +1935,17 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, cons
1935 return 0;
1936 }
1937
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 +
1949 struct packed_git *find_sha1_pack(const unsigned char *sha1,
1950 struct packed_git *packs)
1951 {
@@ -1975,7 +1987,7 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
1987 struct pack_entry e;
1988 int status;
1989
1978 - if (!find_pack_entry(sha1, &e, NULL)) {
1990 + if (!find_pack_entry(sha1, &e)) {
1991 /* Most likely it's a loose object. */
1992 status = sha1_loose_object_info(sha1, sizep);
1993 if (status >= 0)
@@ -1983,7 +1995,7 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
1995
1996 /* Not a loose object; someone else may have just packed it. */
1997 reprepare_packed_git();
1986 - if (!find_pack_entry(sha1, &e, NULL))
1998 + if (!find_pack_entry(sha1, &e))
1999 return status;
2000 }
2001 return packed_object_info(e.p, e.offset, sizep);
@@ -1995,7 +2007,7 @@ static void *read_packed_sha1(const unsigned char *sha1,
2007 struct pack_entry e;
2008 void *data;
2009
1998 - if (!find_pack_entry(sha1, &e, NULL))
2010 + if (!find_pack_entry(sha1, &e))
2011 return NULL;
2012 data = cache_or_unpack_entry(e.p, e.offset, size, type, 1);
2013 if (!data) {
@@ -2395,17 +2407,23 @@ int has_pack_file(const unsigned char *sha1)
2407 return 1;
2408 }
2409
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)
2417 {
2418 struct pack_entry e;
2401 - return find_pack_entry(sha1, &e, ignore_packed);
2419 + return find_kept_pack_entry(sha1, &e, ignore_packed);
2420 }
2421
2422 int has_sha1_file(const unsigned char *sha1)
2423 {
2424 struct pack_entry e;
2425
2408 - if (find_pack_entry(sha1, &e, NULL))
2426 + if (find_pack_entry(sha1, &e))
2427 return 1;
2428 return has_loose_object(sha1);
2429 }