Skip to content
Snippets Groups Projects
Commit 42c8ce1c authored by Junio C Hamano's avatar Junio C Hamano
Browse files

Merge branch 'bc/object-id'

Conversion from uchar[20] to struct object_id continues.

* bc/object-id: (42 commits)
  merge-one-file: compute empty blob object ID
  add--interactive: compute the empty tree value
  Update shell scripts to compute empty tree object ID
  sha1_file: only expose empty object constants through git_hash_algo
  dir: use the_hash_algo for empty blob object ID
  sequencer: use the_hash_algo for empty tree object ID
  cache-tree: use is_empty_tree_oid
  sha1_file: convert cached object code to struct object_id
  builtin/reset: convert use of EMPTY_TREE_SHA1_BIN
  builtin/receive-pack: convert one use of EMPTY_TREE_SHA1_HEX
  wt-status: convert two uses of EMPTY_TREE_SHA1_HEX
  submodule: convert several uses of EMPTY_TREE_SHA1_HEX
  sequencer: convert one use of EMPTY_TREE_SHA1_HEX
  merge: convert empty tree constant to the_hash_algo
  builtin/merge: switch tree functions to use object_id
  builtin/am: convert uses of EMPTY_TREE_SHA1_BIN to the_hash_algo
  sha1-file: add functions for hex empty tree and blob OIDs
  builtin/receive-pack: avoid hard-coded constants for push certs
  diff: specify abbreviation size in terms of the_hash_algo
  upload-pack: replace use of several hard-coded constants
  ...
parents 3d241297 7882fa22
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -1542,7 +1542,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
char *their_tree_name;
 
if (get_oid("HEAD", &our_tree) < 0)
hashcpy(our_tree.hash, EMPTY_TREE_SHA1_BIN);
oidcpy(&our_tree, the_hash_algo->empty_tree);
 
if (build_fake_ancestor(state, index_path))
return error("could not build fake ancestor");
Loading
Loading
@@ -2042,7 +2042,7 @@ static void am_skip(struct am_state *state)
am_rerere_clear();
 
if (get_oid("HEAD", &head))
hashcpy(head.hash, EMPTY_TREE_SHA1_BIN);
oidcpy(&head, the_hash_algo->empty_tree);
 
if (clean_index(&head, &head))
die(_("failed to clean index"));
Loading
Loading
@@ -2105,11 +2105,11 @@ static void am_abort(struct am_state *state)
curr_branch = resolve_refdup("HEAD", 0, &curr_head, NULL);
has_curr_head = curr_branch && !is_null_oid(&curr_head);
if (!has_curr_head)
hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
oidcpy(&curr_head, the_hash_algo->empty_tree);
 
has_orig_head = !get_oid("ORIG_HEAD", &orig_head);
if (!has_orig_head)
hashcpy(orig_head.hash, EMPTY_TREE_SHA1_BIN);
oidcpy(&orig_head, the_hash_algo->empty_tree);
 
clean_index(&curr_head, &orig_head);
 
Loading
Loading
Loading
Loading
@@ -66,7 +66,7 @@ static int count_loose(const struct object_id *oid, const char *path, void *data
else {
loose_size += on_disk_bytes(st);
loose++;
if (verbose && has_sha1_pack(oid->hash))
if (verbose && has_object_pack(oid))
packed_loose++;
}
return 0;
Loading
Loading
Loading
Loading
@@ -228,7 +228,7 @@ static void check_reachable_object(struct object *obj)
if (!(obj->flags & HAS_OBJ)) {
if (is_promisor_object(&obj->oid))
return;
if (has_sha1_pack(obj->oid.hash))
if (has_object_pack(&obj->oid))
return; /* it is in pack - forget about it */
printf("missing %s %s\n", printable_type(obj),
describe_object(obj));
Loading
Loading
Loading
Loading
@@ -1549,12 +1549,13 @@ static void read_v2_anomalous_offsets(struct packed_git *p,
{
const uint32_t *idx1, *idx2;
uint32_t i;
const uint32_t hashwords = the_hash_algo->rawsz / sizeof(uint32_t);
 
/* The address of the 4-byte offset table */
idx1 = (((const uint32_t *)p->index_data)
+ 2 /* 8-byte header */
+ 256 /* fan out */
+ 5 * p->num_objects /* 20-byte SHA-1 table */
+ hashwords * p->num_objects /* object ID table */
+ p->num_objects /* CRC32 table */
);
 
Loading
Loading
Loading
Loading
@@ -280,7 +280,7 @@ static int save_state(struct object_id *stash)
return rc;
}
 
static void read_empty(unsigned const char *sha1, int verbose)
static void read_empty(const struct object_id *oid, int verbose)
{
int i = 0;
const char *args[7];
Loading
Loading
@@ -290,15 +290,15 @@ static void read_empty(unsigned const char *sha1, int verbose)
args[i++] = "-v";
args[i++] = "-m";
args[i++] = "-u";
args[i++] = EMPTY_TREE_SHA1_HEX;
args[i++] = sha1_to_hex(sha1);
args[i++] = empty_tree_oid_hex();
args[i++] = oid_to_hex(oid);
args[i] = NULL;
 
if (run_command_v_opt(args, RUN_GIT_CMD))
die(_("read-tree failed"));
}
 
static void reset_hard(unsigned const char *sha1, int verbose)
static void reset_hard(const struct object_id *oid, int verbose)
{
int i = 0;
const char *args[6];
Loading
Loading
@@ -308,7 +308,7 @@ static void reset_hard(unsigned const char *sha1, int verbose)
args[i++] = "-v";
args[i++] = "--reset";
args[i++] = "-u";
args[i++] = sha1_to_hex(sha1);
args[i++] = oid_to_hex(oid);
args[i] = NULL;
 
if (run_command_v_opt(args, RUN_GIT_CMD))
Loading
Loading
@@ -324,7 +324,7 @@ static void restore_state(const struct object_id *head,
if (is_null_oid(stash))
return;
 
reset_hard(head->hash, 1);
reset_hard(head, 1);
 
args[2] = oid_to_hex(stash);
 
Loading
Loading
@@ -1297,7 +1297,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (remoteheads->next)
die(_("Can merge only exactly one commit into empty head"));
remote_head_oid = &remoteheads->item->object.oid;
read_empty(remote_head_oid->hash, 0);
read_empty(remote_head_oid, 0);
update_ref("initial pull", "HEAD", remote_head_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
goto done;
Loading
Loading
Loading
Loading
@@ -279,6 +279,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
enum object_type type;
void *buf;
struct git_istream *st = NULL;
const unsigned hashsz = the_hash_algo->rawsz;
 
if (!usable_delta) {
if (oe_type(entry) == OBJ_BLOB &&
Loading
Loading
@@ -335,7 +336,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
dheader[pos] = ofs & 127;
while (ofs >>= 7)
dheader[--pos] = 128 | (--ofs & 127);
if (limit && hdrlen + sizeof(dheader) - pos + datalen + 20 >= limit) {
if (limit && hdrlen + sizeof(dheader) - pos + datalen + hashsz >= limit) {
if (st)
close_istream(st);
free(buf);
Loading
Loading
@@ -347,19 +348,19 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
} else if (type == OBJ_REF_DELTA) {
/*
* Deltas with a base reference contain
* an additional 20 bytes for the base sha1.
* additional bytes for the base object ID.
*/
if (limit && hdrlen + 20 + datalen + 20 >= limit) {
if (limit && hdrlen + hashsz + datalen + hashsz >= limit) {
if (st)
close_istream(st);
free(buf);
return 0;
}
hashwrite(f, header, hdrlen);
hashwrite(f, DELTA(entry)->idx.oid.hash, 20);
hdrlen += 20;
hashwrite(f, DELTA(entry)->idx.oid.hash, hashsz);
hdrlen += hashsz;
} else {
if (limit && hdrlen + datalen + 20 >= limit) {
if (limit && hdrlen + datalen + hashsz >= limit) {
if (st)
close_istream(st);
free(buf);
Loading
Loading
@@ -391,6 +392,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
unsigned char header[MAX_PACK_OBJECT_HEADER],
dheader[MAX_PACK_OBJECT_HEADER];
unsigned hdrlen;
const unsigned hashsz = the_hash_algo->rawsz;
unsigned long entry_size = SIZE(entry);
 
if (DELTA(entry))
Loading
Loading
@@ -427,7 +429,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
dheader[pos] = ofs & 127;
while (ofs >>= 7)
dheader[--pos] = 128 | (--ofs & 127);
if (limit && hdrlen + sizeof(dheader) - pos + datalen + 20 >= limit) {
if (limit && hdrlen + sizeof(dheader) - pos + datalen + hashsz >= limit) {
unuse_pack(&w_curs);
return 0;
}
Loading
Loading
@@ -436,16 +438,16 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
hdrlen += sizeof(dheader) - pos;
reused_delta++;
} else if (type == OBJ_REF_DELTA) {
if (limit && hdrlen + 20 + datalen + 20 >= limit) {
if (limit && hdrlen + hashsz + datalen + hashsz >= limit) {
unuse_pack(&w_curs);
return 0;
}
hashwrite(f, header, hdrlen);
hashwrite(f, DELTA(entry)->idx.oid.hash, 20);
hdrlen += 20;
hashwrite(f, DELTA(entry)->idx.oid.hash, hashsz);
hdrlen += hashsz;
reused_delta++;
} else {
if (limit && hdrlen + datalen + 20 >= limit) {
if (limit && hdrlen + datalen + hashsz >= limit) {
unuse_pack(&w_curs);
return 0;
}
Loading
Loading
@@ -769,7 +771,7 @@ static off_t write_reused_pack(struct hashfile *f)
die_errno("unable to seek in reused packfile");
 
if (reuse_packfile_offset < 0)
reuse_packfile_offset = reuse_packfile->pack_size - 20;
reuse_packfile_offset = reuse_packfile->pack_size - the_hash_algo->rawsz;
 
total = to_write = reuse_packfile_offset - sizeof(struct pack_header);
 
Loading
Loading
@@ -1033,7 +1035,7 @@ static int want_object_in_pack(const struct object_id *oid,
int want;
struct list_head *pos;
 
if (!exclude && local && has_loose_object_nonlocal(oid->hash))
if (!exclude && local && has_loose_object_nonlocal(oid))
return 0;
 
/*
Loading
Loading
@@ -1467,7 +1469,7 @@ static void check_object(struct object_entry *entry)
if (reuse_delta && !entry->preferred_base)
base_ref = use_pack(p, &w_curs,
entry->in_pack_offset + used, NULL);
entry->in_pack_header_size = used + 20;
entry->in_pack_header_size = used + the_hash_algo->rawsz;
break;
case OBJ_OFS_DELTA:
buf = use_pack(p, &w_curs,
Loading
Loading
@@ -1949,7 +1951,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
/* Now some size filtering heuristics. */
trg_size = SIZE(trg_entry);
if (!DELTA(trg_entry)) {
max_size = trg_size/2 - 20;
max_size = trg_size/2 - the_hash_algo->rawsz;
ref_depth = 1;
} else {
max_size = DELTA_SIZE(trg_entry);
Loading
Loading
Loading
Loading
@@ -20,7 +20,7 @@ static int load_all_packs, verbose, alt_odb;
 
struct llist_item {
struct llist_item *next;
const unsigned char *sha1;
const struct object_id *oid;
};
static struct llist {
struct llist_item *front;
Loading
Loading
@@ -90,14 +90,14 @@ static struct llist * llist_copy(struct llist *list)
return ret;
 
new_item = ret->front = llist_item_get();
new_item->sha1 = list->front->sha1;
new_item->oid = list->front->oid;
 
old_item = list->front->next;
while (old_item) {
prev = new_item;
new_item = llist_item_get();
prev->next = new_item;
new_item->sha1 = old_item->sha1;
new_item->oid = old_item->oid;
old_item = old_item->next;
}
new_item->next = NULL;
Loading
Loading
@@ -108,10 +108,10 @@ static struct llist * llist_copy(struct llist *list)
 
static inline struct llist_item *llist_insert(struct llist *list,
struct llist_item *after,
const unsigned char *sha1)
const struct object_id *oid)
{
struct llist_item *new_item = llist_item_get();
new_item->sha1 = sha1;
new_item->oid = oid;
new_item->next = NULL;
 
if (after != NULL) {
Loading
Loading
@@ -131,21 +131,21 @@ static inline struct llist_item *llist_insert(struct llist *list,
}
 
static inline struct llist_item *llist_insert_back(struct llist *list,
const unsigned char *sha1)
const struct object_id *oid)
{
return llist_insert(list, list->back, sha1);
return llist_insert(list, list->back, oid);
}
 
static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
const unsigned char *sha1, struct llist_item *hint)
const struct object_id *oid, struct llist_item *hint)
{
struct llist_item *prev = NULL, *l;
 
l = (hint == NULL) ? list->front : hint;
while (l) {
int cmp = hashcmp(l->sha1, sha1);
int cmp = oidcmp(l->oid, oid);
if (cmp > 0) { /* we insert before this entry */
return llist_insert(list, prev, sha1);
return llist_insert(list, prev, oid);
}
if (!cmp) { /* already exists */
return l;
Loading
Loading
@@ -154,11 +154,11 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
l = l->next;
}
/* insert at the end */
return llist_insert_back(list, sha1);
return llist_insert_back(list, oid);
}
 
/* returns a pointer to an item in front of sha1 */
static inline struct llist_item * llist_sorted_remove(struct llist *list, const unsigned char *sha1, struct llist_item *hint)
static inline struct llist_item * llist_sorted_remove(struct llist *list, const struct object_id *oid, struct llist_item *hint)
{
struct llist_item *prev, *l;
 
Loading
Loading
@@ -166,7 +166,7 @@ static inline struct llist_item * llist_sorted_remove(struct llist *list, const
l = (hint == NULL) ? list->front : hint;
prev = NULL;
while (l) {
int cmp = hashcmp(l->sha1, sha1);
int cmp = oidcmp(l->oid, oid);
if (cmp > 0) /* not in list, since sorted */
return prev;
if (!cmp) { /* found */
Loading
Loading
@@ -201,7 +201,7 @@ static void llist_sorted_difference_inplace(struct llist *A,
b = B->front;
 
while (b) {
hint = llist_sorted_remove(A, b->sha1, hint);
hint = llist_sorted_remove(A, b->oid, hint);
b = b->next;
}
}
Loading
Loading
@@ -252,13 +252,14 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
const unsigned char *p1_base, *p2_base;
struct llist_item *p1_hint = NULL, *p2_hint = NULL;
const unsigned int hashsz = the_hash_algo->rawsz;
 
p1_base = p1->pack->index_data;
p2_base = p2->pack->index_data;
p1_base += 256 * 4 + ((p1->pack->index_version < 2) ? 4 : 8);
p2_base += 256 * 4 + ((p2->pack->index_version < 2) ? 4 : 8);
p1_step = (p1->pack->index_version < 2) ? 24 : 20;
p2_step = (p2->pack->index_version < 2) ? 24 : 20;
p1_step = hashsz + ((p1->pack->index_version < 2) ? 4 : 0);
p2_step = hashsz + ((p2->pack->index_version < 2) ? 4 : 0);
 
while (p1_off < p1->pack->num_objects * p1_step &&
p2_off < p2->pack->num_objects * p2_step)
Loading
Loading
@@ -267,9 +268,11 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
/* cmp ~ p1 - p2 */
if (cmp == 0) {
p1_hint = llist_sorted_remove(p1->unique_objects,
p1_base + p1_off, p1_hint);
(const struct object_id *)(p1_base + p1_off),
p1_hint);
p2_hint = llist_sorted_remove(p2->unique_objects,
p1_base + p1_off, p2_hint);
(const struct object_id *)(p1_base + p1_off),
p2_hint);
p1_off += p1_step;
p2_off += p2_step;
continue;
Loading
Loading
@@ -359,13 +362,14 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
size_t ret = 0;
unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
const unsigned char *p1_base, *p2_base;
const unsigned int hashsz = the_hash_algo->rawsz;
 
p1_base = p1->index_data;
p2_base = p2->index_data;
p1_base += 256 * 4 + ((p1->index_version < 2) ? 4 : 8);
p2_base += 256 * 4 + ((p2->index_version < 2) ? 4 : 8);
p1_step = (p1->index_version < 2) ? 24 : 20;
p2_step = (p2->index_version < 2) ? 24 : 20;
p1_step = hashsz + ((p1->index_version < 2) ? 4 : 0);
p2_step = hashsz + ((p2->index_version < 2) ? 4 : 0);
 
while (p1_off < p1->num_objects * p1_step &&
p2_off < p2->num_objects * p2_step)
Loading
Loading
@@ -499,7 +503,7 @@ static void load_all_objects(void)
l = pl->all_objects->front;
while (l) {
hint = llist_insert_sorted_unique(all_objects,
l->sha1, hint);
l->oid, hint);
l = l->next;
}
pl = pl->next;
Loading
Loading
@@ -558,9 +562,9 @@ static struct pack_list * add_pack(struct packed_git *p)
 
base = p->index_data;
base += 256 * 4 + ((p->index_version < 2) ? 4 : 8);
step = (p->index_version < 2) ? 24 : 20;
step = the_hash_algo->rawsz + ((p->index_version < 2) ? 4 : 0);
while (off < p->num_objects * step) {
llist_insert_back(l.all_objects, base + off);
llist_insert_back(l.all_objects, (const struct object_id *)(base + off));
off += step;
}
/* this list will be pruned in cmp_two_packs later */
Loading
Loading
@@ -601,8 +605,8 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
int i;
struct pack_list *min, *red, *pl;
struct llist *ignore;
unsigned char *sha1;
char buf[42]; /* 40 byte sha1 + \n + \0 */
struct object_id *oid;
char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */
 
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(pack_redundant_usage);
Loading
Loading
@@ -650,10 +654,10 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
llist_init(&ignore);
if (!isatty(0)) {
while (fgets(buf, sizeof(buf), stdin)) {
sha1 = xmalloc(20);
if (get_sha1_hex(buf, sha1))
die("Bad sha1 on stdin: %s", buf);
llist_insert_sorted_unique(ignore, sha1, NULL);
oid = xmalloc(sizeof(*oid));
if (get_oid_hex(buf, oid))
die("Bad object ID on stdin: %s", buf);
llist_insert_sorted_unique(ignore, oid, NULL);
}
}
llist_sorted_difference_inplace(all_objects, ignore);
Loading
Loading
Loading
Loading
@@ -25,7 +25,7 @@ static int prune_object(const struct object_id *oid, const char *path,
{
int *opts = data;
 
if (!has_sha1_pack(oid->hash))
if (!has_object_pack(oid))
return 0;
 
if (*opts & PRUNE_PACKED_DRY_RUN)
Loading
Loading
Loading
Loading
@@ -454,21 +454,21 @@ static void hmac_sha1(unsigned char *out,
/* RFC 2104 2. (6) & (7) */
git_SHA1_Init(&ctx);
git_SHA1_Update(&ctx, k_opad, sizeof(k_opad));
git_SHA1_Update(&ctx, out, 20);
git_SHA1_Update(&ctx, out, GIT_SHA1_RAWSZ);
git_SHA1_Final(out, &ctx);
}
 
static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)
{
struct strbuf buf = STRBUF_INIT;
unsigned char sha1[20];
unsigned char sha1[GIT_SHA1_RAWSZ];
 
strbuf_addf(&buf, "%s:%"PRItime, path, stamp);
hmac_sha1(sha1, buf.buf, buf.len, cert_nonce_seed, strlen(cert_nonce_seed));;
strbuf_release(&buf);
 
/* RFC 2104 5. HMAC-SHA1-80 */
strbuf_addf(&buf, "%"PRItime"-%.*s", stamp, 20, sha1_to_hex(sha1));
strbuf_addf(&buf, "%"PRItime"-%.*s", stamp, GIT_SHA1_HEXSZ, sha1_to_hex(sha1));
return strbuf_detach(&buf, NULL);
}
 
Loading
Loading
@@ -968,7 +968,7 @@ static const char *push_to_deploy(unsigned char *sha1,
return "Working directory has unstaged changes";
 
/* diff-index with either HEAD or an empty tree */
diff_index[4] = head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX;
diff_index[4] = head_has_history() ? "HEAD" : empty_tree_oid_hex();
 
child_process_init(&child);
child.argv = diff_index;
Loading
Loading
Loading
Loading
@@ -314,7 +314,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
unborn = !strcmp(rev, "HEAD") && get_oid("HEAD", &oid);
if (unborn) {
/* reset on unborn branch: treat as reset to empty tree */
hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN);
oidcpy(&oid, the_hash_algo->empty_tree);
} else if (!pathspec.nr) {
struct commit *commit;
if (get_oid_committish(rev, &oid))
Loading
Loading
Loading
Loading
@@ -887,8 +887,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
if (read_cache() < 0)
die(_("Could not read the index"));
if (the_index.split_index) {
const unsigned char *sha1 = the_index.split_index->base_sha1;
const char *path = git_path("sharedindex.%s", sha1_to_hex(sha1));
const struct object_id *oid = &the_index.split_index->base_oid;
const char *path = git_path("sharedindex.%s", oid_to_hex(oid));
strbuf_reset(&buf);
puts(relative_path(path, prefix, &buf));
}
Loading
Loading
Loading
Loading
@@ -385,7 +385,7 @@ static int update_one(struct cache_tree *it,
/*
* "sub" can be an empty tree if all subentries are i-t-a.
*/
if (contains_ita && !oidcmp(oid, &empty_tree_oid))
if (contains_ita && is_empty_tree_oid(oid))
continue;
 
strbuf_grow(&buffer, entlen + 100);
Loading
Loading
@@ -523,7 +523,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
if (0 <= it->entry_count) {
if (size < rawsz)
goto free_return;
memcpy(it->oid.hash, (const unsigned char*)buf, rawsz);
oidread(&it->oid, (const unsigned char *)buf);
buf += rawsz;
size -= rawsz;
}
Loading
Loading
Loading
Loading
@@ -324,7 +324,7 @@ struct index_state {
drop_cache_tree : 1;
struct hashmap name_hash;
struct hashmap dir_hash;
unsigned char sha1[20];
struct object_id oid;
struct untracked_cache *untracked;
uint64_t fsmonitor_last_update;
struct ewah_bitmap *fsmonitor_dirty;
Loading
Loading
@@ -1017,21 +1017,10 @@ static inline void oidclr(struct object_id *oid)
memset(oid->hash, 0, GIT_MAX_RAWSZ);
}
 
#define EMPTY_TREE_SHA1_HEX \
"4b825dc642cb6eb9a060e54bf8d69288fbee4904"
#define EMPTY_TREE_SHA1_BIN_LITERAL \
"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
"\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
extern const struct object_id empty_tree_oid;
#define EMPTY_TREE_SHA1_BIN (empty_tree_oid.hash)
#define EMPTY_BLOB_SHA1_HEX \
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
#define EMPTY_BLOB_SHA1_BIN_LITERAL \
"\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \
"\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91"
extern const struct object_id empty_blob_oid;
static inline void oidread(struct object_id *oid, const unsigned char *hash)
{
memcpy(oid->hash, hash, the_hash_algo->rawsz);
}
 
static inline int is_empty_blob_sha1(const unsigned char *sha1)
{
Loading
Loading
@@ -1053,6 +1042,9 @@ static inline int is_empty_tree_oid(const struct object_id *oid)
return !oidcmp(oid, the_hash_algo->empty_tree);
}
 
const char *empty_tree_oid_hex(void);
const char *empty_blob_oid_hex(void);
/* set default permissions by passing mode arguments to open(2) */
int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
int git_mkstemp_mode(char *pattern, int mode);
Loading
Loading
@@ -1268,7 +1260,7 @@ extern int has_object_file_with_flags(const struct object_id *oid, int flags);
* with the specified name. This function does not respect replace
* references.
*/
extern int has_loose_object_nonlocal(const unsigned char *sha1);
extern int has_loose_object_nonlocal(const struct object_id *oid);
 
extern void assert_oid_type(const struct object_id *oid, enum object_type expect);
 
Loading
Loading
@@ -1299,7 +1291,6 @@ static inline int hex2chr(const char *s)
#define FALLBACK_DEFAULT_ABBREV 7
 
struct object_context {
unsigned char tree[20];
unsigned mode;
/*
* symlink_path is only used by get_tree_entry_follow_symlinks,
Loading
Loading
@@ -1566,7 +1557,6 @@ struct pack_window {
 
struct pack_entry {
off_t offset;
unsigned char sha1[20];
struct packed_git *p;
};
 
Loading
Loading
Loading
Loading
@@ -358,7 +358,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
if (tail <= bufptr + tree_entry_len + 1 || memcmp(bufptr, "tree ", 5) ||
bufptr[tree_entry_len] != '\n')
return error("bogus commit object %s", oid_to_hex(&item->object.oid));
if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
if (get_oid_hex(bufptr + 5, &parent) < 0)
return error("bad tree pointer in commit %s",
oid_to_hex(&item->object.oid));
item->maybe_tree = lookup_tree(&parent);
Loading
Loading
@@ -370,7 +370,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
struct commit *new_parent;
 
if (tail <= bufptr + parent_entry_len + 1 ||
get_sha1_hex(bufptr + 7, parent.hash) ||
get_oid_hex(bufptr + 7, &parent) ||
bufptr[parent_entry_len] != '\n')
return error("bad parents in commit %s", oid_to_hex(&item->object.oid));
bufptr += parent_entry_len + 1;
Loading
Loading
Loading
Loading
@@ -3472,7 +3472,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in
* objects however would tend to be slower as they need
* to be individually opened and inflated.
*/
if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(oid->hash))
if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))
return 0;
 
/*
Loading
Loading
@@ -3898,13 +3898,14 @@ static void fill_metainfo(struct strbuf *msg,
*must_show_header = 0;
}
if (one && two && oidcmp(&one->oid, &two->oid)) {
int abbrev = o->flags.full_index ? 40 : DEFAULT_ABBREV;
const unsigned hexsz = the_hash_algo->hexsz;
int abbrev = o->flags.full_index ? hexsz : DEFAULT_ABBREV;
 
if (o->flags.binary) {
mmfile_t mf;
if ((!fill_mmfile(&mf, one) && diff_filespec_is_binary(one)) ||
(!fill_mmfile(&mf, two) && diff_filespec_is_binary(two)))
abbrev = 40;
abbrev = hexsz;
}
strbuf_addf(msg, "%s%sindex %s..%s", line_prefix, set,
diff_abbrev_oid(&one->oid, abbrev),
Loading
Loading
@@ -4139,6 +4140,11 @@ void diff_setup_done(struct diff_options *options)
DIFF_FORMAT_NAME_STATUS |
DIFF_FORMAT_CHECKDIFF |
DIFF_FORMAT_NO_OUTPUT;
/*
* This must be signed because we're comparing against a potentially
* negative value.
*/
const int hexsz = the_hash_algo->hexsz;
 
if (options->set_default)
options->set_default(options);
Loading
Loading
@@ -4219,8 +4225,8 @@ void diff_setup_done(struct diff_options *options)
*/
read_cache();
}
if (40 < options->abbrev)
options->abbrev = 40; /* full */
if (hexsz < options->abbrev)
options->abbrev = hexsz; /* full */
 
/*
* It does not make sense to show the first hit we happened
Loading
Loading
@@ -4798,8 +4804,8 @@ int diff_opt_parse(struct diff_options *options,
options->abbrev = strtoul(arg, NULL, 10);
if (options->abbrev < MINIMUM_ABBREV)
options->abbrev = MINIMUM_ABBREV;
else if (40 < options->abbrev)
options->abbrev = 40;
else if (the_hash_algo->hexsz < options->abbrev)
options->abbrev = the_hash_algo->hexsz;
}
else if ((argcount = parse_long_opt("src-prefix", av, &optarg))) {
options->a_prefix = optarg;
Loading
Loading
Loading
Loading
@@ -829,7 +829,7 @@ static int add_excludes(const char *fname, const char *base, int baselen,
if (size == 0) {
if (oid_stat) {
fill_stat_data(&oid_stat->stat, &st);
oidcpy(&oid_stat->oid, &empty_blob_oid);
oidcpy(&oid_stat->oid, the_hash_algo->empty_blob);
oid_stat->valid = 1;
}
close(fd);
Loading
Loading
@@ -1241,11 +1241,11 @@ static void prep_exclude(struct dir_struct *dir,
(!untracked || !untracked->valid ||
/*
* .. and .gitignore does not exist before
* (i.e. null exclude_sha1). Then we can skip
* (i.e. null exclude_oid). Then we can skip
* loading .gitignore, which would result in
* ENOENT anyway.
*/
!is_null_sha1(untracked->exclude_sha1))) {
!is_null_oid(&untracked->exclude_oid))) {
/*
* dir->basebuf gets reused by the traversal, but we
* need fname to remain unchanged to ensure the src
Loading
Loading
@@ -1276,9 +1276,9 @@ static void prep_exclude(struct dir_struct *dir,
* order, though, if you do that.
*/
if (untracked &&
hashcmp(oid_stat.oid.hash, untracked->exclude_sha1)) {
oidcmp(&oid_stat.oid, &untracked->exclude_oid)) {
invalidate_gitignore(dir->untracked, untracked);
hashcpy(untracked->exclude_sha1, oid_stat.oid.hash);
oidcpy(&untracked->exclude_oid, &oid_stat.oid);
}
dir->exclude_stack = stk;
current = stk->baselen;
Loading
Loading
@@ -2623,9 +2623,10 @@ static void write_one_dir(struct untracked_cache_dir *untracked,
stat_data_to_disk(&stat_data, &untracked->stat_data);
strbuf_add(&wd->sb_stat, &stat_data, sizeof(stat_data));
}
if (!is_null_sha1(untracked->exclude_sha1)) {
if (!is_null_oid(&untracked->exclude_oid)) {
ewah_set(wd->sha1_valid, i);
strbuf_add(&wd->sb_sha1, untracked->exclude_sha1, 20);
strbuf_add(&wd->sb_sha1, untracked->exclude_oid.hash,
the_hash_algo->rawsz);
}
 
intlen = encode_varint(untracked->untracked_nr, intbuf);
Loading
Loading
@@ -2826,16 +2827,16 @@ static void read_stat(size_t pos, void *cb)
ud->valid = 1;
}
 
static void read_sha1(size_t pos, void *cb)
static void read_oid(size_t pos, void *cb)
{
struct read_data *rd = cb;
struct untracked_cache_dir *ud = rd->ucd[pos];
if (rd->data + 20 > rd->end) {
if (rd->data + the_hash_algo->rawsz > rd->end) {
rd->data = rd->end + 1;
return;
}
hashcpy(ud->exclude_sha1, rd->data);
rd->data += 20;
hashcpy(ud->exclude_oid.hash, rd->data);
rd->data += the_hash_algo->rawsz;
}
 
static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
Loading
Loading
@@ -2918,7 +2919,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
ewah_each_bit(rd.check_only, set_check_only, &rd);
rd.data = next + len;
ewah_each_bit(rd.valid, read_stat, &rd);
ewah_each_bit(rd.sha1_valid, read_sha1, &rd);
ewah_each_bit(rd.sha1_valid, read_oid, &rd);
next = rd.data;
 
done:
Loading
Loading
Loading
Loading
@@ -3,6 +3,7 @@
 
/* See Documentation/technical/api-directory-listing.txt */
 
#include "cache.h"
#include "strbuf.h"
 
struct dir_entry {
Loading
Loading
@@ -118,8 +119,8 @@ struct untracked_cache_dir {
/* all data except 'dirs' in this struct are good */
unsigned int valid : 1;
unsigned int recurse : 1;
/* null SHA-1 means this directory does not have .gitignore */
unsigned char exclude_sha1[20];
/* null object ID means this directory does not have .gitignore */
struct object_id exclude_oid;
char name[FLEX_ARRAY];
};
 
Loading
Loading
Loading
Loading
@@ -734,30 +734,31 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
static int fsck_commit_buffer(struct commit *commit, const char *buffer,
unsigned long size, struct fsck_options *options)
{
unsigned char tree_sha1[20], sha1[20];
struct object_id tree_oid, oid;
struct commit_graft *graft;
unsigned parent_count, parent_line_count = 0, author_count;
int err;
const char *buffer_begin = buffer;
const char *p;
 
if (verify_headers(buffer, size, &commit->object, options))
return -1;
 
if (!skip_prefix(buffer, "tree ", &buffer))
return report(options, &commit->object, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n') {
if (parse_oid_hex(buffer, &tree_oid, &p) || *p != '\n') {
err = report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
if (err)
return err;
}
buffer += 41;
buffer = p + 1;
while (skip_prefix(buffer, "parent ", &buffer)) {
if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') {
err = report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
if (err)
return err;
}
buffer += 41;
buffer = p + 1;
parent_line_count++;
}
graft = lookup_commit_graft(&commit->object.oid);
Loading
Loading
@@ -796,7 +797,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
if (err)
return err;
if (!get_commit_tree(commit)) {
err = report(options, &commit->object, FSCK_MSG_BAD_TREE, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
err = report(options, &commit->object, FSCK_MSG_BAD_TREE, "could not load commit's tree %s", oid_to_hex(&tree_oid));
if (err)
return err;
}
Loading
Loading
@@ -822,11 +823,12 @@ static int fsck_commit(struct commit *commit, const char *data,
static int fsck_tag_buffer(struct tag *tag, const char *data,
unsigned long size, struct fsck_options *options)
{
unsigned char sha1[20];
struct object_id oid;
int ret = 0;
const char *buffer;
char *to_free = NULL, *eol;
struct strbuf sb = STRBUF_INIT;
const char *p;
 
if (data)
buffer = data;
Loading
Loading
@@ -857,12 +859,12 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
ret = report(options, &tag->object, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
goto done;
}
if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') {
ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
if (ret)
goto done;
}
buffer += 41;
buffer = p + 1;
 
if (!skip_prefix(buffer, "type ", &buffer)) {
ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");
Loading
Loading
Loading
Loading
@@ -205,8 +205,15 @@ my $status_head = sprintf($status_fmt, __('staged'), __('unstaged'), __('path'))
}
}
 
sub get_empty_tree {
return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
{
my $empty_tree;
sub get_empty_tree {
return $empty_tree if defined $empty_tree;
$empty_tree = run_cmd_pipe(qw(git hash-object -t tree /dev/null));
chomp $empty_tree;
return $empty_tree;
}
}
 
sub get_diff_reference {
Loading
Loading
Loading
Loading
@@ -11,6 +11,8 @@
# The following functions will also be available in the commit filter:
 
functions=$(cat << \EOF
EMPTY_TREE=$(git hash-object -t tree /dev/null)
warn () {
echo "$*" >&2
}
Loading
Loading
@@ -46,7 +48,7 @@ git_commit_non_empty_tree()
{
if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
map "$3"
elif test $# = 1 && test "$1" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904; then
elif test $# = 1 && test "$1" = $EMPTY_TREE; then
:
else
git commit-tree "$@"
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment