Skip to content

Commit 03a9683

Browse files
committed
Simplify is_kept_pack()
This removes --unpacked=<packfile> parameter from the revision parser, and rewrites its use in git-repack to pass a single --kept-pack-only option instead. The new --kept-pack-only option means just that. When this option is given, is_kept_pack() that used to say "not on the --unpacked=<packfile> list" now says "the packfile has corresponding .keep file". Signed-off-by: Junio C Hamano <[email protected]>
1 parent 386cb77 commit 03a9683

File tree

5 files changed

+18
-51
lines changed

5 files changed

+18
-51
lines changed

builtin-pack-objects.c

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

1918-
if (is_kept_pack(p, revs))
1918+
if (is_kept_pack(p))
19191919
continue;
19201920
if (open_pack_index(p))
19211921
die("cannot open pack index");
@@ -1951,7 +1951,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
19511951
const unsigned char *sha1;
19521952

19531953
for (p = packed_git; p; p = p->next) {
1954-
if (is_kept_pack(p, revs))
1954+
if (is_kept_pack(p))
19551955
continue;
19561956

19571957
if (open_pack_index(p))
@@ -2149,7 +2149,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
21492149
continue;
21502150
}
21512151
if (!strcmp("--unpacked", arg) ||
2152-
!prefixcmp(arg, "--unpacked=") ||
2152+
!strcmp("--kept-pack-only", arg) ||
21532153
!strcmp("--reflog", arg) ||
21542154
!strcmp("--all", arg)) {
21552155
use_internal_rev_list = 1;

git-repack.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ case ",$all_into_one," in
6868
if [ -e "$PACKDIR/$e.keep" ]; then
6969
: keep
7070
else
71-
args="$args --unpacked=$e.pack"
7271
existing="$existing $e"
7372
fi
7473
done
74+
if test -n "$existing"
75+
then
76+
args="--kept-pack-only"
77+
fi
7578
if test -n "$args" -a -n "$unpack_unreachable" -a \
7679
-n "$remove_redundant"
7780
then

revision.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -963,16 +963,6 @@ static void add_message_grep(struct rev_info *revs, const char *pattern)
963963
add_grep(revs, pattern, GREP_PATTERN_BODY);
964964
}
965965

966-
static void add_ignore_packed(struct rev_info *revs, const char *name)
967-
{
968-
int num = ++revs->num_ignore_packed;
969-
970-
revs->ignore_packed = xrealloc(revs->ignore_packed,
971-
sizeof(const char *) * (num + 1));
972-
revs->ignore_packed[num-1] = name;
973-
revs->ignore_packed[num] = NULL;
974-
}
975-
976966
static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
977967
int *unkc, const char **unkv)
978968
{
@@ -1072,12 +1062,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
10721062
revs->edge_hint = 1;
10731063
} else if (!strcmp(arg, "--unpacked")) {
10741064
revs->unpacked = 1;
1075-
free(revs->ignore_packed);
1076-
revs->ignore_packed = NULL;
1077-
revs->num_ignore_packed = 0;
1078-
} else if (!prefixcmp(arg, "--unpacked=")) {
1065+
revs->kept_pack_only = 0;
1066+
} else if (!strcmp(arg, "--kept-pack-only")) {
10791067
revs->unpacked = 1;
1080-
add_ignore_packed(revs, arg+11);
1068+
revs->kept_pack_only = 1;
1069+
} else if (!prefixcmp(arg, "--unpacked=")) {
1070+
die("--unpacked=<packfile> no longer supported.");
10811071
} else if (!strcmp(arg, "-r")) {
10821072
revs->diff = 1;
10831073
DIFF_OPT_SET(&revs->diffopt, RECURSIVE);

revision.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ struct rev_info {
4747
blob_objects:1,
4848
edge_hint:1,
4949
limited:1,
50-
unpacked:1, /* see also ignore_packed below */
50+
unpacked:1,
51+
kept_pack_only:1,
5152
boundary:2,
5253
left_right:1,
5354
rewrite_parents:1,
@@ -75,9 +76,6 @@ struct rev_info {
7576
missing_newline:1;
7677
enum date_mode date_mode;
7778

78-
const char **ignore_packed; /* pretend objects in these are unpacked */
79-
int num_ignore_packed;
80-
8179
unsigned int abbrev;
8280
enum cmit_fmt commit_format;
8381
struct log_info *loginfo;
@@ -159,6 +157,6 @@ enum commit_action {
159157
extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
160158

161159
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 *);
160+
extern int is_kept_pack(const struct packed_git *);
163161

164162
#endif

sha1_file.c

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

1861-
static int matches_pack_name(const struct packed_git *p, const char *name)
1861+
int is_kept_pack(const struct packed_git *p)
18621862
{
1863-
const char *last_c, *c;
1864-
1865-
if (!strcmp(p->pack_name, name))
1866-
return 1;
1867-
1868-
for (c = p->pack_name, last_c = c; *c;)
1869-
if (*c == '/')
1870-
last_c = ++c;
1871-
else
1872-
++c;
1873-
if (!strcmp(last_c, name))
1874-
return 1;
1875-
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;
1863+
return p->pack_keep;
18881864
}
18891865

18901866
static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e,
@@ -1900,7 +1876,7 @@ static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e,
19001876
p = (last_found == (void *)1) ? packed_git : last_found;
19011877

19021878
do {
1903-
if (revs->ignore_packed && !is_kept_pack(p, revs))
1879+
if (revs->kept_pack_only && !is_kept_pack(p))
19041880
goto next;
19051881
if (p->num_bad_objects) {
19061882
unsigned i;

0 commit comments

Comments
 (0)