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>
This commit is contained in:
parent
8d1d8f83b5
commit
106d710bc1
@ -62,7 +62,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
|
|||||||
hex[40] = 0;
|
hex[40] = 0;
|
||||||
if (get_sha1_hex(hex, sha1))
|
if (get_sha1_hex(hex, sha1))
|
||||||
die("internal error");
|
die("internal error");
|
||||||
if (has_sha1_pack(sha1))
|
if (has_sha1_pack(sha1, NULL))
|
||||||
(*packed_loose)++;
|
(*packed_loose)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len)
|
|||||||
memcpy(hex+2, de->d_name, 38);
|
memcpy(hex+2, de->d_name, 38);
|
||||||
if (get_sha1_hex(hex, sha1))
|
if (get_sha1_hex(hex, sha1))
|
||||||
continue;
|
continue;
|
||||||
if (!has_sha1_pack(sha1))
|
if (!has_sha1_pack(sha1, NULL))
|
||||||
continue;
|
continue;
|
||||||
memcpy(pathname + len, de->d_name, 38);
|
memcpy(pathname + len, de->d_name, 38);
|
||||||
if (dryrun)
|
if (dryrun)
|
||||||
|
2
cache.h
2
cache.h
@ -259,7 +259,7 @@ extern int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
|
|||||||
extern int write_sha1_to_fd(int fd, const unsigned char *sha1);
|
extern int write_sha1_to_fd(int fd, const unsigned char *sha1);
|
||||||
extern int move_temp_to_file(const char *tmpfile, const char *filename);
|
extern int move_temp_to_file(const char *tmpfile, const char *filename);
|
||||||
|
|
||||||
extern int has_sha1_pack(const unsigned char *sha1);
|
extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
|
||||||
extern int has_sha1_file(const unsigned char *sha1);
|
extern int has_sha1_file(const unsigned char *sha1);
|
||||||
extern void *map_sha1_file(const unsigned char *sha1, unsigned long *);
|
extern void *map_sha1_file(const unsigned char *sha1, unsigned long *);
|
||||||
extern int legacy_loose_object(unsigned char *);
|
extern int legacy_loose_object(unsigned char *);
|
||||||
|
24
revision.c
24
revision.c
@ -416,7 +416,8 @@ static void limit_list(struct rev_info *revs)
|
|||||||
|
|
||||||
if (revs->max_age != -1 && (commit->date < revs->max_age))
|
if (revs->max_age != -1 && (commit->date < revs->max_age))
|
||||||
obj->flags |= UNINTERESTING;
|
obj->flags |= UNINTERESTING;
|
||||||
if (revs->unpacked && has_sha1_pack(obj->sha1))
|
if (revs->unpacked &&
|
||||||
|
has_sha1_pack(obj->sha1, revs->ignore_packed))
|
||||||
obj->flags |= UNINTERESTING;
|
obj->flags |= UNINTERESTING;
|
||||||
add_parents_to_list(revs, commit, &list);
|
add_parents_to_list(revs, commit, &list);
|
||||||
if (obj->flags & UNINTERESTING) {
|
if (obj->flags & UNINTERESTING) {
|
||||||
@ -671,6 +672,16 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void add_ignore_packed(struct rev_info *revs, const char *name)
|
||||||
|
{
|
||||||
|
int num = ++revs->num_ignore_packed;
|
||||||
|
|
||||||
|
revs->ignore_packed = xrealloc(revs->ignore_packed,
|
||||||
|
sizeof(const char **) * (num + 1));
|
||||||
|
revs->ignore_packed[num-1] = name;
|
||||||
|
revs->ignore_packed[num] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse revision information, filling in the "rev_info" structure,
|
* Parse revision information, filling in the "rev_info" structure,
|
||||||
* and removing the used arguments from the argument list.
|
* 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
|
|||||||
}
|
}
|
||||||
if (!strcmp(arg, "--unpacked")) {
|
if (!strcmp(arg, "--unpacked")) {
|
||||||
revs->unpacked = 1;
|
revs->unpacked = 1;
|
||||||
|
free(revs->ignore_packed);
|
||||||
|
revs->ignore_packed = NULL;
|
||||||
|
revs->num_ignore_packed = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!strncmp(arg, "--unpacked=", 11)) {
|
||||||
|
revs->unpacked = 1;
|
||||||
|
add_ignore_packed(revs, arg+11);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "-r")) {
|
if (!strcmp(arg, "-r")) {
|
||||||
@ -1057,7 +1076,8 @@ struct commit *get_revision(struct rev_info *revs)
|
|||||||
*/
|
*/
|
||||||
if (!revs->limited) {
|
if (!revs->limited) {
|
||||||
if ((revs->unpacked &&
|
if ((revs->unpacked &&
|
||||||
has_sha1_pack(commit->object.sha1)) ||
|
has_sha1_pack(commit->object.sha1,
|
||||||
|
revs->ignore_packed)) ||
|
||||||
(revs->max_age != -1 &&
|
(revs->max_age != -1 &&
|
||||||
(commit->date < revs->max_age)))
|
(commit->date < revs->max_age)))
|
||||||
continue;
|
continue;
|
||||||
|
@ -38,7 +38,7 @@ struct rev_info {
|
|||||||
blob_objects:1,
|
blob_objects:1,
|
||||||
edge_hint:1,
|
edge_hint:1,
|
||||||
limited:1,
|
limited:1,
|
||||||
unpacked:1,
|
unpacked:1, /* see also ignore_packed below */
|
||||||
boundary:1,
|
boundary:1,
|
||||||
parents:1;
|
parents:1;
|
||||||
|
|
||||||
@ -57,6 +57,10 @@ struct rev_info {
|
|||||||
unsigned int shown_one:1,
|
unsigned int shown_one:1,
|
||||||
abbrev_commit:1,
|
abbrev_commit:1,
|
||||||
relative_date:1;
|
relative_date:1;
|
||||||
|
|
||||||
|
const char **ignore_packed; /* pretend objects in these are unpacked */
|
||||||
|
int num_ignore_packed;
|
||||||
|
|
||||||
unsigned int abbrev;
|
unsigned int abbrev;
|
||||||
enum cmit_fmt commit_format;
|
enum cmit_fmt commit_format;
|
||||||
struct log_info *loginfo;
|
struct log_info *loginfo;
|
||||||
|
26
sha1_file.c
26
sha1_file.c
@ -1189,12 +1189,20 @@ int find_pack_entry_one(const unsigned char *sha1,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
|
static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
|
||||||
{
|
{
|
||||||
struct packed_git *p;
|
struct packed_git *p;
|
||||||
prepare_packed_git();
|
prepare_packed_git();
|
||||||
|
|
||||||
for (p = packed_git; p; p = p->next) {
|
for (p = packed_git; p; p = p->next) {
|
||||||
|
if (ignore_packed) {
|
||||||
|
const char **ig;
|
||||||
|
for (ig = ignore_packed; *ig; ig++)
|
||||||
|
if (!strcmp(p->pack_name, *ig))
|
||||||
|
break;
|
||||||
|
if (*ig)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (find_pack_entry_one(sha1, e, p))
|
if (find_pack_entry_one(sha1, e, p))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1227,10 +1235,10 @@ int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep
|
|||||||
if (!map) {
|
if (!map) {
|
||||||
struct pack_entry e;
|
struct pack_entry e;
|
||||||
|
|
||||||
if (find_pack_entry(sha1, &e))
|
if (find_pack_entry(sha1, &e, NULL))
|
||||||
return packed_object_info(&e, type, sizep);
|
return packed_object_info(&e, type, sizep);
|
||||||
reprepare_packed_git();
|
reprepare_packed_git();
|
||||||
if (find_pack_entry(sha1, &e))
|
if (find_pack_entry(sha1, &e, NULL))
|
||||||
return packed_object_info(&e, type, sizep);
|
return packed_object_info(&e, type, sizep);
|
||||||
return error("unable to find %s", sha1_to_hex(sha1));
|
return error("unable to find %s", sha1_to_hex(sha1));
|
||||||
}
|
}
|
||||||
@ -1253,7 +1261,7 @@ static void *read_packed_sha1(const unsigned char *sha1, char *type, unsigned lo
|
|||||||
{
|
{
|
||||||
struct pack_entry e;
|
struct pack_entry e;
|
||||||
|
|
||||||
if (!find_pack_entry(sha1, &e)) {
|
if (!find_pack_entry(sha1, &e, NULL)) {
|
||||||
error("cannot read sha1_file for %s", sha1_to_hex(sha1));
|
error("cannot read sha1_file for %s", sha1_to_hex(sha1));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1266,7 +1274,7 @@ void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size
|
|||||||
void *map, *buf;
|
void *map, *buf;
|
||||||
struct pack_entry e;
|
struct pack_entry e;
|
||||||
|
|
||||||
if (find_pack_entry(sha1, &e))
|
if (find_pack_entry(sha1, &e, NULL))
|
||||||
return read_packed_sha1(sha1, type, size);
|
return read_packed_sha1(sha1, type, size);
|
||||||
map = map_sha1_file(sha1, &mapsize);
|
map = map_sha1_file(sha1, &mapsize);
|
||||||
if (map) {
|
if (map) {
|
||||||
@ -1275,7 +1283,7 @@ void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
reprepare_packed_git();
|
reprepare_packed_git();
|
||||||
if (find_pack_entry(sha1, &e))
|
if (find_pack_entry(sha1, &e, NULL))
|
||||||
return read_packed_sha1(sha1, type, size);
|
return read_packed_sha1(sha1, type, size);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1707,10 +1715,10 @@ int has_pack_file(const unsigned char *sha1)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int has_sha1_pack(const unsigned char *sha1)
|
int has_sha1_pack(const unsigned char *sha1, const char **ignore_packed)
|
||||||
{
|
{
|
||||||
struct pack_entry e;
|
struct pack_entry e;
|
||||||
return find_pack_entry(sha1, &e);
|
return find_pack_entry(sha1, &e, ignore_packed);
|
||||||
}
|
}
|
||||||
|
|
||||||
int has_sha1_file(const unsigned char *sha1)
|
int has_sha1_file(const unsigned char *sha1)
|
||||||
@ -1718,7 +1726,7 @@ int has_sha1_file(const unsigned char *sha1)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
struct pack_entry e;
|
struct pack_entry e;
|
||||||
|
|
||||||
if (find_pack_entry(sha1, &e))
|
if (find_pack_entry(sha1, &e, NULL))
|
||||||
return 1;
|
return 1;
|
||||||
return find_sha1_file(sha1, &st) ? 1 : 0;
|
return find_sha1_file(sha1, &st) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user