Commit 8be8342b authored by Junio C Hamano's avatar Junio C Hamano

Merge branch 'po/object-id'

Conversion from uchar[20] to struct object_id continues.

* po/object-id:
  sha1_file: rename hash_sha1_file_literally
  sha1_file: convert write_loose_object to object_id
  sha1_file: convert force_object_loose to object_id
  sha1_file: convert write_sha1_file to object_id
  notes: convert write_notes_tree to object_id
  notes: convert combine_notes_* to object_id
  commit: convert commit_tree* to object_id
  match-trees: convert splice_tree to object_id
  cache: clear whole hash buffer with oidclr
  sha1_file: convert hash_sha1_file to object_id
  dir: convert struct sha1_stat to use object_id
  sha1_file: convert pretend_sha1_file to object_id
parents 157ee050 1752cbbc
......@@ -7,7 +7,7 @@ Talk about <sha1_file.c> and <object.h> family, things like
* read_object_with_reference()
* has_sha1_file()
* write_sha1_file()
* pretend_sha1_file()
* pretend_object_file()
* lookup_{object,commit,tag,blob,tree}
* parse_{object,commit,tag,blob,tree}
* Use of object flags
......
......@@ -3154,7 +3154,7 @@ static int apply_binary(struct apply_state *state,
* See if the old one matches what the patch
* applies to.
*/
hash_sha1_file(img->buf, img->len, blob_type, oid.hash);
hash_object_file(img->buf, img->len, blob_type, &oid);
if (strcmp(oid_to_hex(&oid), patch->old_sha1_prefix))
return error(_("the patch applies to '%s' (%s), "
"which does not match the "
......@@ -3199,7 +3199,7 @@ static int apply_binary(struct apply_state *state,
name);
/* verify that the result matches */
hash_sha1_file(img->buf, img->len, blob_type, oid.hash);
hash_object_file(img->buf, img->len, blob_type, &oid);
if (strcmp(oid_to_hex(&oid), patch->new_sha1_prefix))
return error(_("binary patch to '%s' creates incorrect result (expecting %s, got %s)"),
name, patch->new_sha1_prefix, oid_to_hex(&oid));
......@@ -3554,7 +3554,7 @@ static int try_threeway(struct apply_state *state,
/* Preimage the patch was prepared for */
if (patch->is_new)
write_sha1_file("", 0, blob_type, pre_oid.hash);
write_object_file("", 0, blob_type, &pre_oid);
else if (get_oid(patch->old_sha1_prefix, &pre_oid) ||
read_blob_object(&buf, &pre_oid, patch->old_mode))
return error(_("repository lacks the necessary blob to fall back on 3-way merge."));
......@@ -3570,7 +3570,7 @@ static int try_threeway(struct apply_state *state,
return -1;
}
/* post_oid is theirs */
write_sha1_file(tmp_image.buf, tmp_image.len, blob_type, post_oid.hash);
write_object_file(tmp_image.buf, tmp_image.len, blob_type, &post_oid);
clear_image(&tmp_image);
/* our_oid is ours */
......@@ -3583,7 +3583,7 @@ static int try_threeway(struct apply_state *state,
return error(_("cannot read the current contents of '%s'"),
patch->old_name);
}
write_sha1_file(tmp_image.buf, tmp_image.len, blob_type, our_oid.hash);
write_object_file(tmp_image.buf, tmp_image.len, blob_type, &our_oid);
clear_image(&tmp_image);
/* in-core three-way merge between post and our using pre as base */
......@@ -4291,7 +4291,7 @@ static int add_index_file(struct apply_state *state,
}
fill_stat_cache_info(ce, &st);
}
if (write_sha1_file(buf, size, blob_type, ce->oid.hash) < 0) {
if (write_object_file(buf, size, blob_type, &ce->oid) < 0) {
free(ce);
return error(_("unable to create backing store "
"for newly created file %s"), path);
......
......@@ -232,7 +232,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
convert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash);
pretend_object_file(buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
/*
* Read the current index, replace the path entry with
......
......@@ -1641,8 +1641,8 @@ static void do_commit(const struct am_state *state)
setenv("GIT_COMMITTER_DATE",
state->ignore_date ? "" : state->author_date, 1);
if (commit_tree(state->msg, state->msg_len, tree.hash, parents, commit.hash,
author, state->sign_commit))
if (commit_tree(state->msg, state->msg_len, &tree, parents, &commit,
author, state->sign_commit))
die(_("failed to write commit object"));
reflog_msg = getenv("GIT_REFLOG_ACTION");
......
......@@ -227,8 +227,7 @@ static int checkout_merged(int pos, const struct checkout *state)
* (it also writes the merge result to the object database even
* when it may contain conflicts).
*/
if (write_sha1_file(result_buf.ptr, result_buf.size,
blob_type, oid.hash))
if (write_object_file(result_buf.ptr, result_buf.size, blob_type, &oid))
die(_("Unable to add merge result for '%s'"), path);
free(result_buf.ptr);
ce = make_cache_entry(mode, oid.hash, path, 2, 0);
......
......@@ -117,8 +117,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
die_errno("git commit-tree: failed to read");
}
if (commit_tree(buffer.buf, buffer.len, tree_oid.hash, parents,
commit_oid.hash, NULL, sign_commit)) {
if (commit_tree(buffer.buf, buffer.len, &tree_oid, parents, &commit_oid,
NULL, sign_commit)) {
strbuf_release(&buffer);
return 1;
}
......
......@@ -1579,8 +1579,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
append_merge_tag_headers(parents, &tail);
}
if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash,
parents, oid.hash, author_ident.buf, sign_commit, extra)) {
if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
parents, &oid, author_ident.buf, sign_commit,
extra)) {
rollback_index_files();
die(_("failed to write commit object"));
}
......
......@@ -24,7 +24,8 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsig
if (strbuf_read(&buf, fd, 4096) < 0)
ret = -1;
else
ret = hash_sha1_file_literally(buf.buf, buf.len, type, oid, flags);
ret = hash_object_file_literally(buf.buf, buf.len, type, oid,
flags);
strbuf_release(&buf);
return ret;
}
......
......@@ -958,9 +958,8 @@ static void resolve_delta(struct object_entry *delta_obj,
free(delta_data);
if (!result->data)
bad_object(delta_obj->idx.offset, _("failed to apply delta"));
hash_sha1_file(result->data, result->size,
typename(delta_obj->real_type),
delta_obj->idx.oid.hash);
hash_object_file(result->data, result->size,
typename(delta_obj->real_type), &delta_obj->idx.oid);
sha1_object(result->data, NULL, result->size, delta_obj->real_type,
&delta_obj->idx.oid);
counter_lock();
......
......@@ -820,8 +820,8 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
pptr = commit_list_append(head, pptr);
pptr = commit_list_append(remoteheads->item, pptr);
prepare_to_commit(remoteheads);
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree.hash, parents,
result_commit.hash, NULL, sign_commit))
if (commit_tree(merge_msg.buf, merge_msg.len, &result_tree, parents,
&result_commit, NULL, sign_commit))
die(_("failed to write commit object"));
finish(head, remoteheads, &result_commit, "In-index merge");
drop_save();
......@@ -845,8 +845,8 @@ static int finish_automerge(struct commit *head,
commit_list_insert(head, &parents);
strbuf_addch(&merge_msg, '\n');
prepare_to_commit(remoteheads);
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree->hash, parents,
result_commit.hash, NULL, sign_commit))
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
&result_commit, NULL, sign_commit))
die(_("failed to write commit object"));
strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
finish(head, remoteheads, &result_commit, buf.buf);
......
......@@ -151,7 +151,7 @@ static int verify_tag(char *buffer, unsigned long size)
int cmd_mktag(int argc, const char **argv, const char *prefix)
{
struct strbuf buf = STRBUF_INIT;
unsigned char result_sha1[20];
struct object_id result;
if (argc != 1)
usage("git mktag");
......@@ -165,10 +165,10 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
if (verify_tag(buf.buf, buf.len) < 0)
die("invalid tag signature file");
if (write_sha1_file(buf.buf, buf.len, tag_type, result_sha1) < 0)
if (write_object_file(buf.buf, buf.len, tag_type, &result) < 0)
die("unable to write tag file");
strbuf_release(&buf);
printf("%s\n", sha1_to_hex(result_sha1));
printf("%s\n", oid_to_hex(&result));
return 0;
}
......@@ -40,7 +40,7 @@ static int ent_compare(const void *a_, const void *b_)
b->name, b->len, b->mode);
}
static void write_tree(unsigned char *sha1)
static void write_tree(struct object_id *oid)
{
struct strbuf buf;
size_t size;
......@@ -57,7 +57,7 @@ static void write_tree(unsigned char *sha1)
strbuf_add(&buf, ent->sha1, 20);
}
write_sha1_file(buf.buf, buf.len, tree_type, sha1);
write_object_file(buf.buf, buf.len, tree_type, oid);
strbuf_release(&buf);
}
......@@ -142,7 +142,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
int cmd_mktree(int ac, const char **av, const char *prefix)
{
struct strbuf sb = STRBUF_INIT;
unsigned char sha1[20];
struct object_id oid;
int nul_term_line = 0;
int allow_missing = 0;
int is_batch_mode = 0;
......@@ -181,8 +181,8 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
*/
; /* skip creating an empty tree */
} else {
write_tree(sha1);
puts(sha1_to_hex(sha1));
write_tree(&oid);
puts(oid_to_hex(&oid));
fflush(stdout);
}
used=0; /* reset tree entry buffer for re-use in batch mode */
......
......@@ -198,9 +198,9 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
}
}
static void write_note_data(struct note_data *d, unsigned char *sha1)
static void write_note_data(struct note_data *d, struct object_id *oid)
{
if (write_sha1_file(d->buf.buf, d->buf.len, blob_type, sha1)) {
if (write_object_file(d->buf.buf, d->buf.len, blob_type, oid)) {
error(_("unable to write note object"));
if (d->edit_path)
error(_("the note contents have been left in %s"),
......@@ -459,7 +459,7 @@ static int add(int argc, const char **argv, const char *prefix)
prepare_note_data(&object, &d, note ? note->hash : NULL);
if (d.buf.len || allow_empty) {
write_note_data(&d, new_note.hash);
write_note_data(&d, &new_note);
if (add_note(t, &object, &new_note, combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed");
commit_notes(t, "Notes added by 'git notes add'");
......@@ -619,7 +619,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
}
if (d.buf.len || allow_empty) {
write_note_data(&d, new_note.hash);
write_note_data(&d, &new_note);
if (add_note(t, &object, &new_note, combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed");
logmsg = xstrfmt("Notes added by 'git notes %s'", argv[0]);
......
......@@ -2793,7 +2793,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
if (!packlist_find(&to_pack, oid.hash, NULL) &&
!has_sha1_pack_kept_or_nonlocal(&oid) &&
!loosened_object_can_be_discarded(&oid, p->mtime))
if (force_object_loose(oid.hash, p->mtime))
if (force_object_loose(&oid, p->mtime))
die("unable to force loose object");
}
}
......
......@@ -69,7 +69,7 @@ static int sent_capabilities;
static int shallow_update;
static const char *alt_shallow_file;
static struct strbuf push_cert = STRBUF_INIT;
static unsigned char push_cert_sha1[20];
static struct object_id push_cert_oid;
static struct signature_check sigcheck;
static const char *push_cert_nonce;
static const char *cert_nonce_seed;
......@@ -633,8 +633,9 @@ static void prepare_push_cert_sha1(struct child_process *proc)
int bogs /* beginning_of_gpg_sig */;
already_done = 1;
if (write_sha1_file(push_cert.buf, push_cert.len, "blob", push_cert_sha1))
hashclr(push_cert_sha1);
if (write_object_file(push_cert.buf, push_cert.len, "blob",
&push_cert_oid))
oidclr(&push_cert_oid);
memset(&sigcheck, '\0', sizeof(sigcheck));
sigcheck.result = 'N';
......@@ -655,9 +656,9 @@ static void prepare_push_cert_sha1(struct child_process *proc)
strbuf_release(&gpg_status);
nonce_status = check_nonce(push_cert.buf, bogs);
}
if (!is_null_sha1(push_cert_sha1)) {
if (!is_null_oid(&push_cert_oid)) {
argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT=%s",
sha1_to_hex(push_cert_sha1));
oid_to_hex(&push_cert_oid));
argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s",
sigcheck.signer ? sigcheck.signer : "");
argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s",
......
......@@ -355,7 +355,7 @@ static void check_one_mergetag(struct commit *commit,
struct tag *tag;
int i;
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_oid.hash);
hash_object_file(extra->value, extra->len, typename(OBJ_TAG), &tag_oid);
tag = lookup_tag(&tag_oid);
if (!tag)
die(_("bad mergetag in commit '%s'"), ref);
......@@ -410,7 +410,7 @@ static int create_graft(int argc, const char **argv, int force)
check_mergetags(commit, argc, argv);
if (write_sha1_file(buf.buf, buf.len, commit_type, new.hash))
if (write_object_file(buf.buf, buf.len, commit_type, &new))
die(_("could not write replacement commit for: '%s'"), old_ref);
strbuf_release(&buf);
......
......@@ -187,7 +187,7 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu
{
if (sign && do_sign(buf) < 0)
return error(_("unable to sign the tag"));
if (write_sha1_file(buf->buf, buf->len, tag_type, result->hash) < 0)
if (write_object_file(buf->buf, buf->len, tag_type, result) < 0)
return error(_("unable to write tag file"));
return 0;
}
......
......@@ -172,7 +172,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
{
struct object_id oid;
if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), oid.hash) < 0)
if (write_object_file(obj_buf->buffer, obj_buf->size,
typename(obj->type), &oid) < 0)
die("failed to write object %s", oid_to_hex(&obj->oid));
obj->flags |= FLAG_WRITTEN;
}
......@@ -237,14 +238,16 @@ static void write_object(unsigned nr, enum object_type type,
void *buf, unsigned long size)
{
if (!strict) {
if (write_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash) < 0)
if (write_object_file(buf, size, typename(type),
&obj_list[nr].oid) < 0)
die("failed to write object");
added_object(nr, type, buf, size);
free(buf);
obj_list[nr].obj = NULL;
} else if (type == OBJ_BLOB) {
struct blob *blob;
if (write_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash) < 0)
if (write_object_file(buf, size, typename(type),
&obj_list[nr].oid) < 0)
die("failed to write object");
added_object(nr, type, buf, size);
free(buf);
......@@ -258,7 +261,7 @@ static void write_object(unsigned nr, enum object_type type,
} else {
struct object *obj;
int eaten;
hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash);
hash_object_file(buf, size, typename(type), &obj_list[nr].oid);
added_object(nr, type, buf, size);
obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,
&eaten);
......
......@@ -399,16 +399,16 @@ static int update_one(struct cache_tree *it,
}
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_sha1_file(oid.hash))
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;
}
......
......@@ -1032,7 +1032,7 @@ static inline void hashclr(unsigned char *hash)
static inline void oidclr(struct object_id *oid)
{
hashclr(oid->hash);
memset(oid->hash, 0, GIT_MAX_RAWSZ);
}
......@@ -1050,8 +1050,6 @@ extern const struct object_id empty_tree_oid;
"\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;
#define EMPTY_BLOB_SHA1_BIN (empty_blob_oid.hash)
static inline int is_empty_blob_sha1(const unsigned char *sha1)
{
......@@ -1241,11 +1239,22 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
extern int sha1_object_info(const unsigned char *, unsigned long *);
extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);
extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
extern int force_object_loose(const unsigned char *sha1, time_t mtime);
extern int hash_object_file(const void *buf, unsigned long len,
const char *type, struct object_id *oid);
extern int write_object_file(const void *buf, unsigned long len,
const char *type, struct object_id *oid);
extern int hash_object_file_literally(const void *buf, unsigned long len,
const char *type, struct object_id *oid,
unsigned flags);
extern int pretend_object_file(void *, unsigned long, enum object_type,
struct object_id *oid);
extern int force_object_loose(const struct object_id *oid, time_t mtime);
extern int git_open_cloexec(const char *name, int flags);
#define git_open(name) git_open_cloexec(name, O_RDONLY)
extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
......
......@@ -1378,9 +1378,8 @@ void free_commit_extra_headers(struct commit_extra_header *extra)
}
}
int commit_tree(const char *msg, size_t msg_len,
const unsigned char *tree,
struct commit_list *parents, unsigned char *ret,
int commit_tree(const char *msg, size_t msg_len, const struct object_id *tree,
struct commit_list *parents, struct object_id *ret,
const char *author, const char *sign_commit)
{
struct commit_extra_header *extra = NULL, **tail = &extra;
......@@ -1509,8 +1508,8 @@ N_("Warning: commit message did not conform to UTF-8.\n"
"variable i18n.commitencoding to the encoding your project uses.\n");
int commit_tree_extended(const char *msg, size_t msg_len,
const unsigned char *tree,
struct commit_list *parents, unsigned char *ret,
const struct object_id *tree,
struct commit_list *parents, struct object_id *ret,
const char *author, const char *sign_commit,
struct commit_extra_header *extra)
{
......@@ -1518,7 +1517,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
int encoding_is_utf8;
struct strbuf buffer;
assert_sha1_type(tree, OBJ_TREE);
assert_sha1_type(tree->hash, OBJ_TREE);
if (memchr(msg, '\0', msg_len))
return error("a NUL byte in commit log message not allowed.");
......@@ -1527,7 +1526,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
strbuf_init(&buffer, 8192); /* should avoid reallocs for the headers */
strbuf_addf(&buffer, "tree %s\n", sha1_to_hex(tree));
strbuf_addf(&buffer, "tree %s\n", oid_to_hex(tree));
/*
* NOTE! This ordering means that the same exact tree merged with a
......@@ -1566,7 +1565,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
goto out;
}
result = write_sha1_file(buffer.buf, buffer.len, commit_type, ret);
result = write_object_file(buffer.buf, buffer.len, commit_type, ret);
out:
strbuf_release(&buffer);
return result;
......
......@@ -262,14 +262,15 @@ extern void append_merge_tag_headers(struct commit_list *parents,
struct commit_extra_header ***tail);
extern int commit_tree(const char *msg, size_t msg_len,
const unsigned char *tree,
struct commit_list *parents, unsigned char *ret,
const struct object_id *tree,
struct commit_list *parents, struct object_id *ret,
const char *author, const char *sign_commit);
extern int commit_tree_extended(const char *msg, size_t msg_len,
const unsigned char *tree,
struct commit_list *parents, unsigned char *ret,
const char *author, const char *sign_commit,
const struct object_id *tree,
struct commit_list *parents,
struct object_id *ret, const char *author,
const char *sign_commit,
struct commit_extra_header *);
extern struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **);
......
......@@ -898,7 +898,7 @@ static int ident_to_git(const char *path, const char *src, size_t len,
static int ident_to_worktree(const char *path, const char *src, size_t len,
struct strbuf *buf, int ident)
{
unsigned char sha1[20];
struct object_id oid;
char *to_free = NULL, *dollar, *spc;
int cnt;
......@@ -912,7 +912,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
/* are we "faking" in place editing ? */
if (src == buf->buf)
to_free = strbuf_detach(buf, NULL);
hash_sha1_file(src, len, "blob", sha1);
hash_object_file(src, len, "blob", &oid);
strbuf_grow(buf, len + cnt * 43);
for (;;) {
......@@ -969,7 +969,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
/* step 4: substitute */
strbuf_addstr(buf, "Id: ");
strbuf_add(buf, sha1_to_hex(sha1), 40);
strbuf_addstr(buf, oid_to_hex(&oid));
strbuf_addstr(buf, " $");
}
strbuf_add(buf, src, len);
......
......@@ -260,8 +260,8 @@ static unsigned int hash_filespec(struct diff_filespec *filespec)
if (!filespec->oid_valid) {
if (diff_populate_filespec(filespec, 0))
return 0;
hash_sha1_file(filespec->data, filespec->size, "blob",
filespec->oid.hash);
hash_object_file(filespec->data, filespec->size, "blob",
&filespec->oid);
}
return sha1hash(filespec->oid.hash);
}
......
......@@ -231,12 +231,10 @@ int within_depth(const char *name, int namelen,
* 1 along with { data, size } of the (possibly augmented) buffer
* when successful.
*
* Optionally updates the given sha1_stat with the given OID (when valid).
* Optionally updates the given oid_stat with the given OID (when valid).
*/
static int do_read_blob(const struct object_id *oid,
struct sha1_stat *sha1_stat,
size_t *size_out,
char **data_out)
static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
size_t *size_out, char **data_out)
{
enum object_type type;
unsigned long sz;
......@@ -251,9 +249,9 @@ static int do_read_blob(const struct object_id *oid,
return -1;
}
if (sha1_stat) {
memset(&sha1_stat->stat, 0, sizeof(sha1_stat->stat));
hashcpy(sha1_stat->sha1, oid->hash);
if (oid_stat) {
memset(&oid_stat->stat, 0, sizeof(oid_stat->stat));
oidcpy(&oid_stat->oid, oid);
}
if (sz == 0) {
......@@ -654,9 +652,8 @@ void add_exclude(const char *string, const char *base,
static int read_skip_worktree_file_from_index(const struct index_state *istate,
const char *path,
size_t *size_out,
char **data_out,
struct sha1_stat *sha1_stat)
size_t *size_out, char **data_out,
struct oid_stat *oid_stat)
{
int pos, len;
......@@ -667,7 +664,7 @@ static int read_skip_worktree_file_from_index(const struct index_state *istate,
if (!ce_skip_worktree(istate->cache[pos]))
return -1;
return do_read_blob(&istate->cache[pos]->oid, sha1_stat, size_out, data_out);
return do_read_blob(&istate->cache[pos]->oid, oid_stat, size_out, data_out);
}
/*
......@@ -795,9 +792,8 @@ static int add_excludes_from_buffer(char *buf, size_t size,
* ss_valid is non-zero, "ss" must contain good value as input.
*/
static int add_excludes(const char *fname, const char *base, int baselen,
struct exclude_list *el,
struct index_state *istate,
struct sha1_stat *sha1_stat)
struct exclude_list *el, struct index_state *istate,
struct oid_stat *oid_stat)
{
struct stat st;
int r;
......@@ -815,16 +811,16 @@ static int add_excludes(const char *fname, const char *base, int baselen,
return -1;
r = read_skip_worktree_file_from_index(istate, fname,
&size, &buf,
sha1_stat);
oid_stat);
if (r != 1)
return r;
} else {
size = xsize_t(st.st_size);
if (size == 0) {
if (sha1_stat) {
fill_stat_data(&sha1_stat->stat, &st);
hashcpy(sha1_stat->sha1, EMPTY_BLOB_SHA1_BIN);
sha1_stat->valid = 1;
if (oid_stat) {
fill_stat_data(&oid_stat->stat, &st);
oidcpy(&oid_stat->oid, &empty_blob_oid);
oid_stat->valid = 1;
}
close(fd);
return 0;
......@@ -837,22 +833,23 @@ static int add_excludes(const char *fname, const char *base, int baselen,
}
buf[size++] = '\n';
close(fd);
if (sha1_stat) {
if (oid_stat) {
int pos;
if (sha1_stat->valid &&
!match_stat_data_racy(istate, &sha1_stat->stat, &st))
if (oid_stat->valid &&
!match_stat_data_racy(istate, &oid_stat->stat, &st))
; /* no content change, ss->sha1 still good */
else if (istate &&
(pos = index_name_pos(istate, fname, strlen(fname))) >= 0 &&
!ce_stage(istate->cache[pos]) &&
ce_uptodate(istate->cache[pos]) &&
!would_convert_to_git(istate, fname))
hashcpy(sha1_stat->sha1,
istate->cache[pos]->oid.hash);
oidcpy(&oid_stat->oid,
&istate->cache[pos]->oid);
else
hash_sha1_file(buf, size, "blob", sha1_stat->sha1);
fill_stat_data(&sha1_stat->stat, &st);
sha1_stat->valid = 1;
hash_object_file(buf, size, "blob",
&oid_stat->oid);
fill_stat_data(&oid_stat->stat, &st);
oid_stat->valid = 1;
}
}
......@@ -930,7 +927,7 @@ struct exclude_list *add_exclude_list(struct dir_struct *dir,
* Used to set up core.excludesfile and .git/info/exclude lists.
*/
static void add_excludes_from_file_1(struct dir_struct *dir, const char *fname,
struct sha1_stat *sha1_stat)
struct oid_stat *oid_stat)
{
struct exclude_list *el;
/*
......@@ -941,7 +938,7 @@ static void add_excludes_from_file_1(struct dir_struct *dir, const char *fname,
if (!dir->untracked)
dir->unmanaged_exclude_files++;
el = add_exclude_list(dir, EXC_FILE, fname);
if (add_excludes(fname, "", 0, el, NULL, sha1_stat) < 0)
if (add_excludes(fname, "", 0, el, NULL, oid_stat) < 0)
die("cannot use %s as an exclude file", fname);
}
......@@ -1180,7 +1177,7 @@ static void prep_exclude(struct dir_struct *dir,
while (current < baselen) {
const char *cp;
struct sha1_stat sha1_stat;
struct oid_stat oid_stat;
stk = xcalloc(1, sizeof(*stk));
if (current < 0) {
......@@ -1223,8 +1220,8 @@ static void prep_exclude(struct dir_struct *dir,
}
/* Try to read per-directory file */
hashclr(sha1_stat.sha1);
sha1_stat.valid = 0;
oidclr(&oid_stat.oid);
oid_stat.valid = 0;