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
  ...
This commit is contained in:
Junio C Hamano
2018-05-30 14:04:10 +09:00
46 changed files with 348 additions and 306 deletions

View File

@ -1831,7 +1831,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
if (verify_hdr(hdr, mmap_size) < 0)
goto unmap;
hashcpy(istate->sha1, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz);
hashcpy(istate->oid.hash, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz);
istate->version = ntohl(hdr->hdr_version);
istate->cache_nr = ntohl(hdr->hdr_entries);
istate->cache_alloc = alloc_nr(istate->cache_nr);
@ -1903,7 +1903,7 @@ int read_index_from(struct index_state *istate, const char *path,
uint64_t start = getnanotime();
struct split_index *split_index;
int ret;
char *base_sha1_hex;
char *base_oid_hex;
char *base_path;
/* istate->initialized covers both .git/index and .git/sharedindex.xxx */
@ -1914,7 +1914,7 @@ int read_index_from(struct index_state *istate, const char *path,
trace_performance_since(start, "read cache %s", path);
split_index = istate->split_index;
if (!split_index || is_null_sha1(split_index->base_sha1)) {
if (!split_index || is_null_oid(&split_index->base_oid)) {
post_read_index_from(istate);
return ret;
}
@ -1924,13 +1924,13 @@ int read_index_from(struct index_state *istate, const char *path,
else
split_index->base = xcalloc(1, sizeof(*split_index->base));
base_sha1_hex = sha1_to_hex(split_index->base_sha1);
base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_sha1_hex);
base_oid_hex = oid_to_hex(&split_index->base_oid);
base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
ret = do_read_index(split_index->base, base_path, 1);
if (hashcmp(split_index->base_sha1, split_index->base->sha1))
if (oidcmp(&split_index->base_oid, &split_index->base->oid))
die("broken index, expect %s in %s, got %s",
base_sha1_hex, base_path,
sha1_to_hex(split_index->base->sha1));
base_oid_hex, base_path,
oid_to_hex(&split_index->base->oid));
freshen_shared_index(base_path, 0);
merge_base_index(istate);
@ -2219,7 +2219,7 @@ static int verify_index_from(const struct index_state *istate, const char *path)
if (n != the_hash_algo->rawsz)
goto out;
if (hashcmp(istate->sha1, hash))
if (hashcmp(istate->oid.hash, hash))
goto out;
close(fd);
@ -2398,7 +2398,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
return -1;
}
if (ce_flush(&c, newfd, istate->sha1))
if (ce_flush(&c, newfd, istate->oid.hash))
return -1;
if (close_tempfile_gently(tempfile)) {
error(_("could not close '%s'"), tempfile->filename.buf);
@ -2522,10 +2522,10 @@ static int write_shared_index(struct index_state *istate,
return ret;
}
ret = rename_tempfile(temp,
git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
git_path("sharedindex.%s", oid_to_hex(&si->base->oid)));
if (!ret) {
hashcpy(si->base_sha1, si->base->sha1);
clean_shared_index_files(sha1_to_hex(si->base->sha1));
oidcpy(&si->base_oid, &si->base->oid);
clean_shared_index_files(oid_to_hex(&si->base->oid));
}
return ret;
@ -2579,13 +2579,13 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
if (!si || alternate_index_output ||
(istate->cache_changed & ~EXTMASK)) {
if (si)
hashclr(si->base_sha1);
oidclr(&si->base_oid);
ret = do_write_locked_index(istate, lock, flags);
goto out;
}
if (git_env_bool("GIT_TEST_SPLIT_INDEX", 0)) {
int v = si->base_sha1[0];
int v = si->base_oid.hash[0];
if ((v & 15) < 6)
istate->cache_changed |= SPLIT_INDEX_ORDERED;
}
@ -2600,7 +2600,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
temp = mks_tempfile(git_path("sharedindex_XXXXXX"));
if (!temp) {
hashclr(si->base_sha1);
oidclr(&si->base_oid);
ret = do_write_locked_index(istate, lock, flags);
goto out;
}
@ -2620,7 +2620,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
/* Freshen the shared index only if the split-index was written */
if (!ret && !new_shared_index) {
const char *shared_index = git_path("sharedindex.%s",
sha1_to_hex(si->base_sha1));
oid_to_hex(&si->base_oid));
freshen_shared_index(shared_index, 1);
}