#include "tree.h"
#include "tree-walk.h"
#include "cache-tree.h"
+#include "object-store.h"
#ifndef DEBUG
#define DEBUG 0
down->namelen = pathlen;
if (pos < it->subtree_nr)
- memmove(it->down + pos + 1,
- it->down + pos,
- sizeof(down) * (it->subtree_nr - pos - 1));
+ MOVE_ARRAY(it->down + pos + 1, it->down + pos,
+ it->subtree_nr - pos - 1);
it->down[pos] = down;
return down;
}
struct cache_tree_sub *sub = NULL;
const char *path, *slash;
int pathlen, entlen;
- const unsigned char *sha1;
+ const struct object_id *oid;
unsigned mode;
int expected_missing = 0;
int contains_ita = 0;
die("cache-tree.c: '%.*s' in '%s' not found",
entlen, path + baselen, path);
i += sub->count;
- sha1 = sub->cache_tree->oid.hash;
+ oid = &sub->cache_tree->oid;
mode = S_IFDIR;
contains_ita = sub->cache_tree->entry_count < 0;
if (contains_ita) {
}
}
else {
- sha1 = ce->oid.hash;
+ oid = &ce->oid;
mode = ce->ce_mode;
entlen = pathlen - baselen;
i++;
}
- if (is_null_sha1(sha1) ||
- (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))) {
+ if (is_null_oid(oid) ||
+ (mode != S_IFGITLINK && !missing_ok && !has_object_file(oid))) {
strbuf_release(&buffer);
if (expected_missing)
return -1;
return error("invalid object %06o %s for '%.*s'",
- mode, sha1_to_hex(sha1), entlen+baselen, path);
+ mode, oid_to_hex(oid), entlen+baselen, path);
}
/*
/*
* "sub" can be an empty tree if all subentries are i-t-a.
*/
- if (contains_ita && !hashcmp(sha1, EMPTY_TREE_SHA1_BIN))
+ if (contains_ita && is_empty_tree_oid(oid))
continue;
strbuf_grow(&buffer, entlen + 100);
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
- strbuf_add(&buffer, sha1, 20);
+ strbuf_add(&buffer, oid->hash, the_hash_algo->rawsz);
#if DEBUG
fprintf(stderr, "cache-tree update-one %o %.*s\n",
}
if (repair) {
- unsigned char sha1[20];
- hash_sha1_file(buffer.buf, buffer.len, tree_type, sha1);
- if (has_sha1_file(sha1))
- hashcpy(it->oid.hash, sha1);
+ struct object_id oid;
+ hash_object_file(buffer.buf, buffer.len, tree_type, &oid);
+ if (has_object_file(&oid))
+ oidcpy(&it->oid, &oid);
else
to_invalidate = 1;
- } else if (dryrun)
- hash_sha1_file(buffer.buf, buffer.len, tree_type,
- it->oid.hash);
- else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->oid.hash)) {
+ } else if (dryrun) {
+ hash_object_file(buffer.buf, buffer.len, tree_type, &it->oid);
+ } else if (write_object_file(buffer.buf, buffer.len, tree_type,
+ &it->oid)) {
strbuf_release(&buffer);
return -1;
}
#endif
if (0 <= it->entry_count) {
- strbuf_add(buffer, it->oid.hash, 20);
+ strbuf_add(buffer, it->oid.hash, the_hash_algo->rawsz);
}
for (i = 0; i < it->subtree_nr; i++) {
struct cache_tree_sub *down = it->down[i];
char *ep;
struct cache_tree *it;
int i, subtree_nr;
+ const unsigned rawsz = the_hash_algo->rawsz;
it = NULL;
/* skip name, but make sure name exists */
goto free_return;
buf++; size--;
if (0 <= it->entry_count) {
- if (size < 20)
+ if (size < rawsz)
goto free_return;
- hashcpy(it->oid.hash, (const unsigned char*)buf);
- buf += 20;
- size -= 20;
+ oidread(&it->oid, (const unsigned char *)buf);
+ buf += rawsz;
+ size -= rawsz;
}
#if DEBUG
return it;
}
-int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, const char *index_path, int flags, const char *prefix)
+int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix)
{
int entries, was_valid;
struct lock_file lock_file = LOCK_INIT;
ret = WRITE_TREE_PREFIX_ERROR;
goto out;
}
- hashcpy(sha1, subtree->oid.hash);
+ oidcpy(oid, &subtree->oid);
}
else
- hashcpy(sha1, index_state->cache_tree->oid.hash);
+ oidcpy(oid, &index_state->cache_tree->oid);
out:
rollback_lock_file(&lock_file);
return ret;
}
-int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
-{
- return write_index_as_tree(sha1, &the_index, get_index_file(), flags, prefix);
-}
-
static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
{
struct tree_desc desc;
cnt++;
else {
struct cache_tree_sub *sub;
- struct tree *subtree = lookup_tree(entry.oid);
+ struct tree *subtree = lookup_tree(the_repository,
+ entry.oid);
if (!subtree->object.parsed)
parse_tree(subtree);
sub = cache_tree_sub(it, entry.path);
return it->entry_count;
return 0;
}
-
-int update_main_cache_tree(int flags)
-{
- if (!the_index.cache_tree)
- the_index.cache_tree = cache_tree();
- return cache_tree_update(&the_index, flags);
-}