Skip to content

Commit c3067cb

Browse files
committed
Merge branch 'jc/maint-1.6.0-keep-pack' into maint
* 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 Conflicts: t/t7700-repack.sh
2 parents 61e6108 + 094085e commit c3067cb

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
@@ -60,7 +60,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
6060
hex[40] = 0;
6161
if (get_sha1_hex(hex, sha1))
6262
die("internal error");
63-
if (has_sha1_pack(sha1, NULL))
63+
if (has_sha1_pack(sha1))
6464
(*packed_loose)++;
6565
}
6666
}

builtin-fsck.c

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

builtin-pack-objects.c

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

1969-
for (i = 0; i < revs->num_ignore_packed; i++) {
1970-
if (matches_pack_name(p, revs->ignore_packed[i]))
1971-
break;
1972-
}
1973-
if (revs->num_ignore_packed <= i)
1969+
if (!p->pack_local || p->pack_keep)
19741970
continue;
19751971
if (open_pack_index(p))
19761972
die("cannot open pack index");
@@ -1999,26 +1995,46 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
19991995
free(in_pack.array);
20001996
}
20011997

1998+
static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1)
1999+
{
2000+
static struct packed_git *last_found = (void *)1;
2001+
struct packed_git *p;
2002+
2003+
p = (last_found != (void *)1) ? last_found : packed_git;
2004+
2005+
while (p) {
2006+
if ((!p->pack_local || p->pack_keep) &&
2007+
find_pack_entry_one(sha1, p)) {
2008+
last_found = p;
2009+
return 1;
2010+
}
2011+
if (p == last_found)
2012+
p = packed_git;
2013+
else
2014+
p = p->next;
2015+
if (p == last_found)
2016+
p = p->next;
2017+
}
2018+
return 0;
2019+
}
2020+
20022021
static void loosen_unused_packed_objects(struct rev_info *revs)
20032022
{
20042023
struct packed_git *p;
20052024
uint32_t i;
20062025
const unsigned char *sha1;
20072026

20082027
for (p = packed_git; p; p = p->next) {
2009-
for (i = 0; i < revs->num_ignore_packed; i++) {
2010-
if (matches_pack_name(p, revs->ignore_packed[i]))
2011-
break;
2012-
}
2013-
if (revs->num_ignore_packed <= i)
2028+
if (!p->pack_local || p->pack_keep)
20142029
continue;
20152030

20162031
if (open_pack_index(p))
20172032
die("cannot open pack index");
20182033

20192034
for (i = 0; i < p->num_objects; i++) {
20202035
sha1 = nth_packed_object_sha1(p, i);
2021-
if (!locate_object_entry(sha1))
2036+
if (!locate_object_entry(sha1) &&
2037+
!has_sha1_pack_kept_or_nonlocal(sha1))
20222038
if (force_object_loose(sha1, p->mtime))
20232039
die("unable to force loose object");
20242040
}
@@ -2208,7 +2224,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
22082224
continue;
22092225
}
22102226
if (!strcmp("--unpacked", arg) ||
2211-
!prefixcmp(arg, "--unpacked=") ||
22122227
!strcmp("--reflog", arg) ||
22132228
!strcmp("--all", arg)) {
22142229
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
@@ -644,7 +644,7 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l
644644

645645
extern int move_temp_to_file(const char *tmpfile, const char *filename);
646646

647-
extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
647+
extern int has_sha1_pack(const unsigned char *sha1);
648648
extern int has_sha1_file(const unsigned char *sha1);
649649
extern int has_loose_object_nonlocal(const unsigned char *sha1);
650650

@@ -839,7 +839,6 @@ extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsign
839839
extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
840840
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
841841
extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
842-
extern int matches_pack_name(struct packed_git *p, const char *name);
843842

844843
/* Dumb servers support */
845844
extern int update_server_info(int);

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
17831783
* objects however would tend to be slower as they need
17841784
* to be individually opened and inflated.
17851785
*/
1786-
if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1, NULL))
1786+
if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1))
17871787
return 0;
17881788

17891789
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
@@ -1919,25 +1919,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
19191919
return 0;
19201920
}
19211921

1922-
int matches_pack_name(struct packed_git *p, const char *name)
1923-
{
1924-
const char *last_c, *c;
1925-
1926-
if (!strcmp(p->pack_name, name))
1927-
return 1;
1928-
1929-
for (c = p->pack_name, last_c = c; *c;)
1930-
if (*c == '/')
1931-
last_c = ++c;
1932-
else
1933-
++c;
1934-
if (!strcmp(last_c, name))
1935-
return 1;
1936-
1937-
return 0;
1938-
}
1939-
1940-
static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
1922+
static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
19411923
{
19421924
static struct packed_git *last_found = (void *)1;
19431925
struct packed_git *p;
@@ -1949,15 +1931,6 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, cons
19491931
p = (last_found == (void *)1) ? packed_git : last_found;
19501932

19511933
do {
1952-
if (ignore_packed) {
1953-
const char **ig;
1954-
for (ig = ignore_packed; *ig; ig++)
1955-
if (matches_pack_name(p, *ig))
1956-
break;
1957-
if (*ig)
1958-
goto next;
1959-
}
1960-
19611934
if (p->num_bad_objects) {
19621935
unsigned i;
19631936
for (i = 0; i < p->num_bad_objects; i++)
@@ -2038,15 +2011,15 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
20382011
struct pack_entry e;
20392012
int status;
20402013

2041-
if (!find_pack_entry(sha1, &e, NULL)) {
2014+
if (!find_pack_entry(sha1, &e)) {
20422015
/* Most likely it's a loose object. */
20432016
status = sha1_loose_object_info(sha1, sizep);
20442017
if (status >= 0)
20452018
return status;
20462019

20472020
/* Not a loose object; someone else may have just packed it. */
20482021
reprepare_packed_git();
2049-
if (!find_pack_entry(sha1, &e, NULL))
2022+
if (!find_pack_entry(sha1, &e))
20502023
return status;
20512024
}
20522025

@@ -2065,7 +2038,7 @@ static void *read_packed_sha1(const unsigned char *sha1,
20652038
struct pack_entry e;
20662039
void *data;
20672040

2068-
if (!find_pack_entry(sha1, &e, NULL))
2041+
if (!find_pack_entry(sha1, &e))
20692042
return NULL;
20702043
data = cache_or_unpack_entry(e.p, e.offset, size, type, 1);
20712044
if (!data) {
@@ -2464,17 +2437,17 @@ int has_pack_file(const unsigned char *sha1)
24642437
return 1;
24652438
}
24662439

2467-
int has_sha1_pack(const unsigned char *sha1, const char **ignore_packed)
2440+
int has_sha1_pack(const unsigned char *sha1)
24682441
{
24692442
struct pack_entry e;
2470-
return find_pack_entry(sha1, &e, ignore_packed);
2443+
return find_pack_entry(sha1, &e);
24712444
}
24722445

24732446
int has_sha1_file(const unsigned char *sha1)
24742447
{
24752448
struct pack_entry e;
24762449

2477-
if (find_pack_entry(sha1, &e, NULL))
2450+
if (find_pack_entry(sha1, &e))
24782451
return 1;
24792452
return has_loose_object(sha1);
24802453
}

0 commit comments

Comments
 (0)