Skip to content

Commit e89c6ea

Browse files
committed
Merge branch 'jc/maint-1.6.0-keep-pack' into maint-1.6.1
* jc/maint-1.6.0-keep-pack: pack-objects: don't loosen objects available in alternate or kept packs t7700: demonstrate repack flaw which may loosen objects unnecessarily Remove --kept-pack-only option and associated infrastructure pack-objects: only repack or loosen objects residing in "local" packs git-repack.sh: don't use --kept-pack-only option to pack-objects t7700-repack: add two new tests demonstrating repacking flaws is_kept_pack(): final clean-up Simplify is_kept_pack() Consolidate ignore_packed logic more has_sha1_kept_pack(): take "struct rev_info" has_sha1_pack(): refactor "pretend these packs do not exist" interface git-repack: resist stray environment variable
2 parents 3f3e2c2 + 094085e commit e89c6ea

11 files changed

+105
-74
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-pack-objects.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,11 +1961,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
19611961
const unsigned char *sha1;
19621962
struct object *o;
19631963

1964-
for (i = 0; i < revs->num_ignore_packed; i++) {
1965-
if (matches_pack_name(p, revs->ignore_packed[i]))
1966-
break;
1967-
}
1968-
if (revs->num_ignore_packed <= i)
1964+
if (!p->pack_local || p->pack_keep)
19691965
continue;
19701966
if (open_pack_index(p))
19711967
die("cannot open pack index");
@@ -1994,26 +1990,46 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
19941990
free(in_pack.array);
19951991
}
19961992

1993+
static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1)
1994+
{
1995+
static struct packed_git *last_found = (void *)1;
1996+
struct packed_git *p;
1997+
1998+
p = (last_found != (void *)1) ? last_found : packed_git;
1999+
2000+
while (p) {
2001+
if ((!p->pack_local || p->pack_keep) &&
2002+
find_pack_entry_one(sha1, p)) {
2003+
last_found = p;
2004+
return 1;
2005+
}
2006+
if (p == last_found)
2007+
p = packed_git;
2008+
else
2009+
p = p->next;
2010+
if (p == last_found)
2011+
p = p->next;
2012+
}
2013+
return 0;
2014+
}
2015+
19972016
static void loosen_unused_packed_objects(struct rev_info *revs)
19982017
{
19992018
struct packed_git *p;
20002019
uint32_t i;
20012020
const unsigned char *sha1;
20022021

20032022
for (p = packed_git; p; p = p->next) {
2004-
for (i = 0; i < revs->num_ignore_packed; i++) {
2005-
if (matches_pack_name(p, revs->ignore_packed[i]))
2006-
break;
2007-
}
2008-
if (revs->num_ignore_packed <= i)
2023+
if (!p->pack_local || p->pack_keep)
20092024
continue;
20102025

20112026
if (open_pack_index(p))
20122027
die("cannot open pack index");
20132028

20142029
for (i = 0; i < p->num_objects; i++) {
20152030
sha1 = nth_packed_object_sha1(p, i);
2016-
if (!locate_object_entry(sha1))
2031+
if (!locate_object_entry(sha1) &&
2032+
!has_sha1_pack_kept_or_nonlocal(sha1))
20172033
if (force_object_loose(sha1, p->mtime))
20182034
die("unable to force loose object");
20192035
}
@@ -2203,7 +2219,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
22032219
continue;
22042220
}
22052221
if (!strcmp("--unpacked", arg) ||
2206-
!prefixcmp(arg, "--unpacked=") ||
22072222
!strcmp("--reflog", arg) ||
22082223
!strcmp("--all", arg)) {
22092224
use_internal_rev_list = 1;

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l
646646

647647
extern int move_temp_to_file(const char *tmpfile, const char *filename);
648648

649-
extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
649+
extern int has_sha1_pack(const unsigned char *sha1);
650650
extern int has_sha1_file(const unsigned char *sha1);
651651
extern int has_loose_object_nonlocal(const unsigned char *sha1);
652652

@@ -835,7 +835,6 @@ extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsign
835835
extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
836836
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
837837
extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
838-
extern int matches_pack_name(struct packed_git *p, const char *name);
839838

840839
/* Dumb servers support */
841840
extern int update_server_info(int);

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
16741674
* objects however would tend to be slower as they need
16751675
* to be individually opened and inflated.
16761676
*/
1677-
if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1, NULL))
1677+
if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1))
16781678
return 0;
16791679

16801680
len = strlen(name);

git-repack.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ case ",$all_into_one," in
6060
args='--unpacked --incremental'
6161
;;
6262
,t,)
63+
args= existing=
6364
if [ -d "$PACKDIR" ]; then
6465
for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
6566
| sed -e 's/^\.\///' -e 's/\.pack$//'`
6667
do
6768
if [ -e "$PACKDIR/$e.keep" ]; then
6869
: keep
6970
else
70-
args="$args --unpacked=$e.pack"
7171
existing="$existing $e"
7272
fi
7373
done
74-
if test -n "$args" -a -n "$unpack_unreachable" -a \
74+
if test -n "$existing" -a -n "$unpack_unreachable" -a \
7575
-n "$remove_redundant"
7676
then
7777
args="$args $unpack_unreachable"

revision.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -994,16 +994,6 @@ static void add_message_grep(struct rev_info *revs, const char *pattern)
994994
add_grep(revs, pattern, GREP_PATTERN_BODY);
995995
}
996996

997-
static void add_ignore_packed(struct rev_info *revs, const char *name)
998-
{
999-
int num = ++revs->num_ignore_packed;
1000-
1001-
revs->ignore_packed = xrealloc(revs->ignore_packed,
1002-
sizeof(const char *) * (num + 1));
1003-
revs->ignore_packed[num-1] = name;
1004-
revs->ignore_packed[num] = NULL;
1005-
}
1006-
1007997
static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
1008998
int *unkc, const char **unkv)
1009999
{
@@ -1116,12 +1106,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
11161106
revs->edge_hint = 1;
11171107
} else if (!strcmp(arg, "--unpacked")) {
11181108
revs->unpacked = 1;
1119-
free(revs->ignore_packed);
1120-
revs->ignore_packed = NULL;
1121-
revs->num_ignore_packed = 0;
11221109
} else if (!prefixcmp(arg, "--unpacked=")) {
1123-
revs->unpacked = 1;
1124-
add_ignore_packed(revs, arg+11);
1110+
die("--unpacked=<packfile> no longer supported.");
11251111
} else if (!strcmp(arg, "-r")) {
11261112
revs->diff = 1;
11271113
DIFF_OPT_SET(&revs->diffopt, RECURSIVE);
@@ -1685,7 +1671,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
16851671
{
16861672
if (commit->object.flags & SHOWN)
16871673
return commit_ignore;
1688-
if (revs->unpacked && has_sha1_pack(commit->object.sha1, revs->ignore_packed))
1674+
if (revs->unpacked && has_sha1_pack(commit->object.sha1))
16891675
return commit_ignore;
16901676
if (revs->show_all)
16911677
return commit_show;

revision.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct rev_info {
4949
blob_objects:1,
5050
edge_hint:1,
5151
limited:1,
52-
unpacked:1, /* see also ignore_packed below */
52+
unpacked:1,
5353
boundary:2,
5454
left_right:1,
5555
rewrite_parents:1,
@@ -80,9 +80,6 @@ struct rev_info {
8080
missing_newline:1;
8181
enum date_mode date_mode;
8282

83-
const char **ignore_packed; /* pretend objects in these are unpacked */
84-
int num_ignore_packed;
85-
8683
unsigned int abbrev;
8784
enum cmit_fmt commit_format;
8885
struct log_info *loginfo;

sha1_file.c

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,25 +1916,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
19161916
return 0;
19171917
}
19181918

1919-
int matches_pack_name(struct packed_git *p, const char *name)
1920-
{
1921-
const char *last_c, *c;
1922-
1923-
if (!strcmp(p->pack_name, name))
1924-
return 1;
1925-
1926-
for (c = p->pack_name, last_c = c; *c;)
1927-
if (*c == '/')
1928-
last_c = ++c;
1929-
else
1930-
++c;
1931-
if (!strcmp(last_c, name))
1932-
return 1;
1933-
1934-
return 0;
1935-
}
1936-
1937-
static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
1919+
static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
19381920
{
19391921
static struct packed_git *last_found = (void *)1;
19401922
struct packed_git *p;
@@ -1946,15 +1928,6 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, cons
19461928
p = (last_found == (void *)1) ? packed_git : last_found;
19471929

19481930
do {
1949-
if (ignore_packed) {
1950-
const char **ig;
1951-
for (ig = ignore_packed; *ig; ig++)
1952-
if (matches_pack_name(p, *ig))
1953-
break;
1954-
if (*ig)
1955-
goto next;
1956-
}
1957-
19581931
if (p->num_bad_objects) {
19591932
unsigned i;
19601933
for (i = 0; i < p->num_bad_objects; i++)
@@ -2035,15 +2008,15 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
20352008
struct pack_entry e;
20362009
int status;
20372010

2038-
if (!find_pack_entry(sha1, &e, NULL)) {
2011+
if (!find_pack_entry(sha1, &e)) {
20392012
/* Most likely it's a loose object. */
20402013
status = sha1_loose_object_info(sha1, sizep);
20412014
if (status >= 0)
20422015
return status;
20432016

20442017
/* Not a loose object; someone else may have just packed it. */
20452018
reprepare_packed_git();
2046-
if (!find_pack_entry(sha1, &e, NULL))
2019+
if (!find_pack_entry(sha1, &e))
20472020
return status;
20482021
}
20492022

@@ -2062,7 +2035,7 @@ static void *read_packed_sha1(const unsigned char *sha1,
20622035
struct pack_entry e;
20632036
void *data;
20642037

2065-
if (!find_pack_entry(sha1, &e, NULL))
2038+
if (!find_pack_entry(sha1, &e))
20662039
return NULL;
20672040
data = cache_or_unpack_entry(e.p, e.offset, size, type, 1);
20682041
if (!data) {
@@ -2461,17 +2434,17 @@ int has_pack_file(const unsigned char *sha1)
24612434
return 1;
24622435
}
24632436

2464-
int has_sha1_pack(const unsigned char *sha1, const char **ignore_packed)
2437+
int has_sha1_pack(const unsigned char *sha1)
24652438
{
24662439
struct pack_entry e;
2467-
return find_pack_entry(sha1, &e, ignore_packed);
2440+
return find_pack_entry(sha1, &e);
24682441
}
24692442

24702443
int has_sha1_file(const unsigned char *sha1)
24712444
{
24722445
struct pack_entry e;
24732446

2474-
if (find_pack_entry(sha1, &e, NULL))
2447+
if (find_pack_entry(sha1, &e))
24752448
return 1;
24762449
return has_loose_object(sha1);
24772450
}

0 commit comments

Comments
 (0)