Merge branch 'jc/nodelta'

* jc/nodelta:
  builtin-pack-objects: remove unnecessary code for no-delta
  Teach "delta" attribute to pack-objects.
  pack-objects: pass fullname down to add_object_entry()
This commit is contained in:
Junio C Hamano 2007-05-29 00:41:50 -07:00
commit 96cbd573d4

View File

@ -1,5 +1,6 @@
#include "builtin.h" #include "builtin.h"
#include "cache.h" #include "cache.h"
#include "attr.h"
#include "object.h" #include "object.h"
#include "blob.h" #include "blob.h"
#include "commit.h" #include "commit.h"
@ -43,6 +44,7 @@ struct object_entry {
* to be used as the base object to delta * to be used as the base object to delta
* objects against. * objects against.
*/ */
unsigned char no_try_delta;
}; };
/* /*
@ -723,6 +725,9 @@ static unsigned name_hash(const char *name)
unsigned char c; unsigned char c;
unsigned hash = 0; unsigned hash = 0;
if (!name)
return 0;
/* /*
* This effectively just creates a sortable number from the * This effectively just creates a sortable number from the
* last sixteen non-whitespace characters. Last characters * last sixteen non-whitespace characters. Last characters
@ -736,13 +741,36 @@ static unsigned name_hash(const char *name)
return hash; return hash;
} }
static void setup_delta_attr_check(struct git_attr_check *check)
{
static struct git_attr *attr_delta;
if (!attr_delta)
attr_delta = git_attr("delta", 5);
check[0].attr = attr_delta;
}
static int no_try_delta(const char *path)
{
struct git_attr_check check[1];
setup_delta_attr_check(check);
if (git_checkattr(path, ARRAY_SIZE(check), check))
return 0;
if (ATTR_FALSE(check->value))
return 1;
return 0;
}
static int add_object_entry(const unsigned char *sha1, enum object_type type, static int add_object_entry(const unsigned char *sha1, enum object_type type,
unsigned hash, int exclude) const char *name, int exclude)
{ {
struct object_entry *entry; struct object_entry *entry;
struct packed_git *p, *found_pack = NULL; struct packed_git *p, *found_pack = NULL;
off_t found_offset = 0; off_t found_offset = 0;
int ix; int ix;
unsigned hash = name_hash(name);
ix = nr_objects ? locate_object_entry_hash(sha1) : -1; ix = nr_objects ? locate_object_entry_hash(sha1) : -1;
if (ix >= 0) { if (ix >= 0) {
@ -799,6 +827,9 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
if (progress) if (progress)
display_progress(&progress_state, nr_objects); display_progress(&progress_state, nr_objects);
if (name && no_try_delta(name))
entry->no_try_delta = 1;
return 1; return 1;
} }
@ -931,10 +962,9 @@ static void add_pbase_object(struct tree_desc *tree,
if (cmp < 0) if (cmp < 0)
return; return;
if (name[cmplen] != '/') { if (name[cmplen] != '/') {
unsigned hash = name_hash(fullname);
add_object_entry(entry.sha1, add_object_entry(entry.sha1,
S_ISDIR(entry.mode) ? OBJ_TREE : OBJ_BLOB, S_ISDIR(entry.mode) ? OBJ_TREE : OBJ_BLOB,
hash, 1); fullname, 1);
return; return;
} }
if (S_ISDIR(entry.mode)) { if (S_ISDIR(entry.mode)) {
@ -994,10 +1024,11 @@ static int check_pbase_path(unsigned hash)
return 0; return 0;
} }
static void add_preferred_base_object(const char *name, unsigned hash) static void add_preferred_base_object(const char *name)
{ {
struct pbase_tree *it; struct pbase_tree *it;
int cmplen; int cmplen;
unsigned hash = name_hash(name);
if (!num_preferred_base || check_pbase_path(hash)) if (!num_preferred_base || check_pbase_path(hash))
return; return;
@ -1005,7 +1036,7 @@ static void add_preferred_base_object(const char *name, unsigned hash)
cmplen = name_cmp_len(name); cmplen = name_cmp_len(name);
for (it = pbase_tree; it; it = it->next) { for (it = pbase_tree; it; it = it->next) {
if (cmplen == 0) { if (cmplen == 0) {
add_object_entry(it->pcache.sha1, OBJ_TREE, 0, 1); add_object_entry(it->pcache.sha1, OBJ_TREE, NULL, 1);
} }
else { else {
struct tree_desc tree; struct tree_desc tree;
@ -1347,6 +1378,10 @@ static void find_deltas(struct object_entry **list, int window, int depth)
if (entry->size < 50) if (entry->size < 50)
continue; continue;
if (entry->no_try_delta)
continue;
free_delta_index(n->index); free_delta_index(n->index);
n->index = NULL; n->index = NULL;
free(n->data); free(n->data);
@ -1446,7 +1481,6 @@ static void read_object_list_from_stdin(void)
{ {
char line[40 + 1 + PATH_MAX + 2]; char line[40 + 1 + PATH_MAX + 2];
unsigned char sha1[20]; unsigned char sha1[20];
unsigned hash;
for (;;) { for (;;) {
if (!fgets(line, sizeof(line), stdin)) { if (!fgets(line, sizeof(line), stdin)) {
@ -1469,22 +1503,20 @@ static void read_object_list_from_stdin(void)
if (get_sha1_hex(line, sha1)) if (get_sha1_hex(line, sha1))
die("expected sha1, got garbage:\n %s", line); die("expected sha1, got garbage:\n %s", line);
hash = name_hash(line+41); add_preferred_base_object(line+41);
add_preferred_base_object(line+41, hash); add_object_entry(sha1, 0, line+41, 0);
add_object_entry(sha1, 0, hash, 0);
} }
} }
static void show_commit(struct commit *commit) static void show_commit(struct commit *commit)
{ {
add_object_entry(commit->object.sha1, OBJ_COMMIT, 0, 0); add_object_entry(commit->object.sha1, OBJ_COMMIT, NULL, 0);
} }
static void show_object(struct object_array_entry *p) static void show_object(struct object_array_entry *p)
{ {
unsigned hash = name_hash(p->name); add_preferred_base_object(p->name);
add_preferred_base_object(p->name, hash); add_object_entry(p->item->sha1, p->item->type, p->name, 0);
add_object_entry(p->item->sha1, p->item->type, hash, 0);
} }
static void show_edge(struct commit *commit) static void show_edge(struct commit *commit)