зеркало из https://github.com/microsoft/git.git
Add "--depth=N" parameter to git-pack-objects to limit maximum delta depth
It too defaults to 10. A nice round random number.
This commit is contained in:
Родитель
f846bbff15
Коммит
d116a45a9a
|
@ -2,7 +2,7 @@
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "delta.h"
|
#include "delta.h"
|
||||||
|
|
||||||
static const char pack_usage[] = "git-pack-objects [--window=N] base-name < object-list";
|
static const char pack_usage[] = "git-pack-objects [--window=N] [--depth=N] base-name < object-list";
|
||||||
|
|
||||||
enum object_type {
|
enum object_type {
|
||||||
OBJ_NONE,
|
OBJ_NONE,
|
||||||
|
@ -286,7 +286,7 @@ struct unpacked {
|
||||||
* going to be even smaller or of a different type. So return -1
|
* going to be even smaller or of a different type. So return -1
|
||||||
* once we determine that there's no point even trying.
|
* once we determine that there's no point even trying.
|
||||||
*/
|
*/
|
||||||
static int try_delta(struct unpacked *cur, struct unpacked *old)
|
static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_depth)
|
||||||
{
|
{
|
||||||
struct object_entry *cur_entry = cur->entry;
|
struct object_entry *cur_entry = cur->entry;
|
||||||
struct object_entry *old_entry = old->entry;
|
struct object_entry *old_entry = old->entry;
|
||||||
|
@ -305,6 +305,8 @@ static int try_delta(struct unpacked *cur, struct unpacked *old)
|
||||||
oldsize = old_entry->size;
|
oldsize = old_entry->size;
|
||||||
if (size - oldsize > oldsize / 4)
|
if (size - oldsize > oldsize / 4)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (old_entry->depth >= max_depth)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE!
|
* NOTE!
|
||||||
|
@ -321,11 +323,12 @@ static int try_delta(struct unpacked *cur, struct unpacked *old)
|
||||||
return 0;
|
return 0;
|
||||||
cur_entry->delta = old_entry;
|
cur_entry->delta = old_entry;
|
||||||
cur_entry->delta_size = delta_size;
|
cur_entry->delta_size = delta_size;
|
||||||
|
cur_entry->depth = old_entry->depth + 1;
|
||||||
free(delta_buf);
|
free(delta_buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void find_deltas(struct object_entry **list, int window)
|
static void find_deltas(struct object_entry **list, int window, int depth)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int array_size = window * sizeof(struct unpacked);
|
unsigned int array_size = window * sizeof(struct unpacked);
|
||||||
|
@ -354,7 +357,7 @@ static void find_deltas(struct object_entry **list, int window)
|
||||||
m = array + other_idx;
|
m = array + other_idx;
|
||||||
if (!m->entry)
|
if (!m->entry)
|
||||||
break;
|
break;
|
||||||
if (try_delta(n, m) < 0)
|
if (try_delta(n, m, depth) < 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,7 +366,7 @@ static void find_deltas(struct object_entry **list, int window)
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char line[128];
|
char line[128];
|
||||||
int window = 10;
|
int window = 10, depth = 10;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
|
@ -377,6 +380,13 @@ int main(int argc, char **argv)
|
||||||
usage(pack_usage);
|
usage(pack_usage);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!strncmp("--depth=", arg, 8)) {
|
||||||
|
char *end;
|
||||||
|
depth = strtoul(arg+8, &end, 0);
|
||||||
|
if (!arg[8] || *end)
|
||||||
|
usage(pack_usage);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
usage(pack_usage);
|
usage(pack_usage);
|
||||||
}
|
}
|
||||||
if (base_name)
|
if (base_name)
|
||||||
|
@ -399,8 +409,8 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
sorted_by_sha = create_sorted_list(sha1_sort);
|
sorted_by_sha = create_sorted_list(sha1_sort);
|
||||||
sorted_by_type = create_sorted_list(type_size_sort);
|
sorted_by_type = create_sorted_list(type_size_sort);
|
||||||
if (window)
|
if (window && depth)
|
||||||
find_deltas(sorted_by_type, window+1);
|
find_deltas(sorted_by_type, window+1, depth);
|
||||||
|
|
||||||
write_pack_file();
|
write_pack_file();
|
||||||
write_index_file();
|
write_index_file();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче