@matheusbsbs / matheus-bagliano / commits / 106d710bc1
Fork 0

pack-objects --unpacked=<existing pack> option.

Incremental repack without -a essentially boils down to: rev-list --objects --unpacked --all | pack-objects $new_pack which picks up all loose objects that are still live and creates a new pack. This implements --unpacked=<existing pack> option to tell the revision walking machinery to pretend as if objects in such a pack are unpacked for the purpose of object listing. With this, we could say: rev-list --objects --unpacked=$active_pack --all | pack-objects $new_pack instead, to mean "all live loose objects but pretend as if objects that are in this pack are also unpacked". The newly created pack would be perfect for updating $active_pack by replacing it. Since pack-objects now knows how to do the rev-list's work itself internally, you can also write the above example by: pack-objects --unpacked=$active_pack --all $new_pack </dev/null Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Sep 6, 2006 at 02:12 UTC 106d710bc13f34aec1a15c4cff80f062f384edf6
6 files changed +47 -15
builtin-count-objects.c
+1 -1
@@ -62,7 +62,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
62 hex[40] = 0;
63 if (get_sha1_hex(hex, sha1))
64 die("internal error");
65 - if (has_sha1_pack(sha1))
65 + if (has_sha1_pack(sha1, NULL))
66 (*packed_loose)++;
67 }
68 }
builtin-prune-packed.c
+1 -1
@@ -19,7 +19,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len)
19 memcpy(hex+2, de->d_name, 38);
20 if (get_sha1_hex(hex, sha1))
21 continue;
22 - if (!has_sha1_pack(sha1))
22 + if (!has_sha1_pack(sha1, NULL))
23 continue;
24 memcpy(pathname + len, de->d_name, 38);
25 if (dryrun)
cache.h
+1 -1
@@ -259,7 +259,7 @@ extern int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
259 extern int write_sha1_to_fd(int fd, const unsigned char *sha1);
260 extern int move_temp_to_file(const char *tmpfile, const char *filename);
261
262 -extern int has_sha1_pack(const unsigned char *sha1);
262 +extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
263 extern int has_sha1_file(const unsigned char *sha1);
264 extern void *map_sha1_file(const unsigned char *sha1, unsigned long *);
265 extern int legacy_loose_object(unsigned char *);
revision.c
+22 -2
@@ -416,7 +416,8 @@ static void limit_list(struct rev_info *revs)
416
417 if (revs->max_age != -1 && (commit->date < revs->max_age))
418 obj->flags |= UNINTERESTING;
419 - if (revs->unpacked && has_sha1_pack(obj->sha1))
419 + if (revs->unpacked &&
420 + has_sha1_pack(obj->sha1, revs->ignore_packed))
421 obj->flags |= UNINTERESTING;
422 add_parents_to_list(revs, commit, &list);
423 if (obj->flags & UNINTERESTING) {
@@ -671,6 +672,16 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
672 return 0;
673 }
674
675 +static void add_ignore_packed(struct rev_info *revs, const char *name)
676 +{
677 + int num = ++revs->num_ignore_packed;
678 +
679 + revs->ignore_packed = xrealloc(revs->ignore_packed,
680 + sizeof(const char **) * (num + 1));
681 + revs->ignore_packed[num-1] = name;
682 + revs->ignore_packed[num] = NULL;
683 +}
684 +
685 /*
686 * Parse revision information, filling in the "rev_info" structure,
687 * and removing the used arguments from the argument list.
@@ -811,6 +822,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
822 }
823 if (!strcmp(arg, "--unpacked")) {
824 revs->unpacked = 1;
825 + free(revs->ignore_packed);
826 + revs->ignore_packed = NULL;
827 + revs->num_ignore_packed = 0;
828 + continue;
829 + }
830 + if (!strncmp(arg, "--unpacked=", 11)) {
831 + revs->unpacked = 1;
832 + add_ignore_packed(revs, arg+11);
833 continue;
834 }
835 if (!strcmp(arg, "-r")) {
@@ -1057,7 +1076,8 @@ struct commit *get_revision(struct rev_info *revs)
1076 */
1077 if (!revs->limited) {
1078 if ((revs->unpacked &&
1060 - has_sha1_pack(commit->object.sha1)) ||
1079 + has_sha1_pack(commit->object.sha1,
1080 + revs->ignore_packed)) ||
1081 (revs->max_age != -1 &&
1082 (commit->date < revs->max_age)))
1083 continue;
revision.h
+5 -1
@@ -38,7 +38,7 @@ struct rev_info {
38 blob_objects:1,
39 edge_hint:1,
40 limited:1,
41 - unpacked:1,
41 + unpacked:1, /* see also ignore_packed below */
42 boundary:1,
43 parents:1;
44
@@ -57,6 +57,10 @@ struct rev_info {
57 unsigned int shown_one:1,
58 abbrev_commit:1,
59 relative_date:1;
60 +
61 + const char **ignore_packed; /* pretend objects in these are unpacked */
62 + int num_ignore_packed;
63 +
64 unsigned int abbrev;
65 enum cmit_fmt commit_format;
66 struct log_info *loginfo;
sha1_file.c
+17 -9
@@ -1189,12 +1189,20 @@ int find_pack_entry_one(const unsigned char *sha1,
1189 return 0;
1190 }
1191
1192 -static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
1192 +static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
1193 {
1194 struct packed_git *p;
1195 prepare_packed_git();
1196
1197 for (p = packed_git; p; p = p->next) {
1198 + if (ignore_packed) {
1199 + const char **ig;
1200 + for (ig = ignore_packed; *ig; ig++)
1201 + if (!strcmp(p->pack_name, *ig))
1202 + break;
1203 + if (*ig)
1204 + continue;
1205 + }
1206 if (find_pack_entry_one(sha1, e, p))
1207 return 1;
1208 }
@@ -1227,10 +1235,10 @@ int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep
1235 if (!map) {
1236 struct pack_entry e;
1237
1230 - if (find_pack_entry(sha1, &e))
1238 + if (find_pack_entry(sha1, &e, NULL))
1239 return packed_object_info(&e, type, sizep);
1240 reprepare_packed_git();
1233 - if (find_pack_entry(sha1, &e))
1241 + if (find_pack_entry(sha1, &e, NULL))
1242 return packed_object_info(&e, type, sizep);
1243 return error("unable to find %s", sha1_to_hex(sha1));
1244 }
@@ -1253,7 +1261,7 @@ static void *read_packed_sha1(const unsigned char *sha1, char *type, unsigned lo
1261 {
1262 struct pack_entry e;
1263
1256 - if (!find_pack_entry(sha1, &e)) {
1264 + if (!find_pack_entry(sha1, &e, NULL)) {
1265 error("cannot read sha1_file for %s", sha1_to_hex(sha1));
1266 return NULL;
1267 }
@@ -1266,7 +1274,7 @@ void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size
1274 void *map, *buf;
1275 struct pack_entry e;
1276
1269 - if (find_pack_entry(sha1, &e))
1277 + if (find_pack_entry(sha1, &e, NULL))
1278 return read_packed_sha1(sha1, type, size);
1279 map = map_sha1_file(sha1, &mapsize);
1280 if (map) {
@@ -1275,7 +1283,7 @@ void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size
1283 return buf;
1284 }
1285 reprepare_packed_git();
1278 - if (find_pack_entry(sha1, &e))
1286 + if (find_pack_entry(sha1, &e, NULL))
1287 return read_packed_sha1(sha1, type, size);
1288 return NULL;
1289 }
@@ -1707,10 +1715,10 @@ int has_pack_file(const unsigned char *sha1)
1715 return 1;
1716 }
1717
1710 -int has_sha1_pack(const unsigned char *sha1)
1718 +int has_sha1_pack(const unsigned char *sha1, const char **ignore_packed)
1719 {
1720 struct pack_entry e;
1713 - return find_pack_entry(sha1, &e);
1721 + return find_pack_entry(sha1, &e, ignore_packed);
1722 }
1723
1724 int has_sha1_file(const unsigned char *sha1)
@@ -1718,7 +1726,7 @@ int has_sha1_file(const unsigned char *sha1)
1726 struct stat st;
1727 struct pack_entry e;
1728
1721 - if (find_pack_entry(sha1, &e))
1729 + if (find_pack_entry(sha1, &e, NULL))
1730 return 1;
1731 return find_sha1_file(sha1, &st) ? 1 : 0;
1732 }