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 <gitster@pobox.com>
Junio C Hamano committed
Feb 28, 2009 at 00:00 UTC
03a9683d22eca52bc2b2b9b09258a143e76416f6
5 files changed
+18
-51
builtin-pack-objects.c
+3
-3
@@ -1915,7 +1915,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
1915
const unsigned char *sha1;
1916
struct object *o;
1917
1918
- if (is_kept_pack(p, revs))
1918
+ if (is_kept_pack(p))
1919
continue;
1920
if (open_pack_index(p))
1921
die("cannot open pack index");
@@ -1951,7 +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) {
1954
- if (is_kept_pack(p, revs))
1954
+ if (is_kept_pack(p))
1955
continue;
1956
1957
if (open_pack_index(p))
@@ -2149,7 +2149,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2149
continue;
2150
}
2151
if (!strcmp("--unpacked", arg) ||
2152
- !prefixcmp(arg, "--unpacked=") ||
2152
+ !strcmp("--kept-pack-only", arg) ||
2153
!strcmp("--reflog", arg) ||
2154
!strcmp("--all", arg)) {
2155
use_internal_rev_list = 1;
git-repack.sh
+4
-1
@@ -68,10 +68,13 @@ case ",$all_into_one," in
68
if [ -e "$PACKDIR/$e.keep" ]; then
69
: keep
70
else
71
- args="$args --unpacked=$e.pack"
71
existing="$existing $e"
72
fi
73
done
74
+ if test -n "$existing"
75
+ then
76
+ args="--kept-pack-only"
77
+ fi
78
if test -n "$args" -a -n "$unpack_unreachable" -a \
79
-n "$remove_redundant"
80
then
revision.c
+5
-15
@@ -963,16 +963,6 @@ static void add_message_grep(struct rev_info *revs, const char *pattern)
963
add_grep(revs, pattern, GREP_PATTERN_BODY);
964
}
965
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
-
966
static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
967
int *unkc, const char **unkv)
968
{
@@ -1072,12 +1062,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1062
revs->edge_hint = 1;
1063
} else if (!strcmp(arg, "--unpacked")) {
1064
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")) {
1067
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.");
1071
} else if (!strcmp(arg, "-r")) {
1072
revs->diff = 1;
1073
DIFF_OPT_SET(&revs->diffopt, RECURSIVE);
revision.h
+3
-5
@@ -47,7 +47,8 @@ struct rev_info {
47
blob_objects:1,
48
edge_hint:1,
49
limited:1,
50
- unpacked:1, /* see also ignore_packed below */
50
+ unpacked:1,
51
+ kept_pack_only:1,
52
boundary:2,
53
left_right:1,
54
rewrite_parents:1,
@@ -75,9 +76,6 @@ struct rev_info {
76
missing_newline:1;
77
enum date_mode date_mode;
78
78
- const char **ignore_packed; /* pretend objects in these are unpacked */
79
- int num_ignore_packed;
80
-
79
unsigned int abbrev;
80
enum cmit_fmt commit_format;
81
struct log_info *loginfo;
@@ -159,6 +157,6 @@ enum commit_action {
157
extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
158
159
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 *);
161
162
#endif
sha1_file.c
+3
-27
@@ -1858,33 +1858,9 @@ off_t find_pack_entry_one(const unsigned char *sha1,
1858
return 0;
1859
}
1860
1861
-static int matches_pack_name(const struct packed_git *p, const char *name)
1861
+int is_kept_pack(const struct packed_git *p)
1862
{
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;
1864
}
1865
1866
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,
1876
p = (last_found == (void *)1) ? packed_git : last_found;
1877
1878
do {
1903
- if (revs->ignore_packed && !is_kept_pack(p, revs))
1879
+ if (revs->kept_pack_only && !is_kept_pack(p))
1880
goto next;
1881
if (p->num_bad_objects) {
1882
unsigned i;