зеркало из https://github.com/microsoft/git.git
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
This commit is contained in:
Коммит
8be8342b4c
|
@ -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
|
||||
|
|
12
apply.c
12
apply.c
|
@ -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);
|
||||
|
|
2
blame.c
2
blame.c
|
@ -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);
|
||||
|
|
16
cache-tree.c
16
cache-tree.c
|
@ -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;
|
||||
}
|
||||
|
|
25
cache.h
25
cache.h
|
@ -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);
|
||||
|
|
15
commit.c
15
commit.c
|
@ -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;
|
||||
|
|
11
commit.h
11
commit.h
|
@ -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);
|
||||
}
|
||||
|
|
104
dir.c
104
dir.c
|
@ -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;
|
||||
if (dir->exclude_per_dir &&
|
||||
/*
|
||||
* If we know that no files have been added in
|
||||
|
@ -1252,7 +1249,7 @@ static void prep_exclude(struct dir_struct *dir,
|
|||
strbuf_addstr(&sb, dir->exclude_per_dir);
|
||||
el->src = strbuf_detach(&sb, NULL);
|
||||
add_excludes(el->src, el->src, stk->baselen, el, istate,
|
||||
untracked ? &sha1_stat : NULL);
|
||||
untracked ? &oid_stat : NULL);
|
||||
}
|
||||
/*
|
||||
* NEEDSWORK: when untracked cache is enabled, prep_exclude()
|
||||
|
@ -1269,9 +1266,9 @@ static void prep_exclude(struct dir_struct *dir,
|
|||
* order, though, if you do that.
|
||||
*/
|
||||
if (untracked &&
|
||||
hashcmp(sha1_stat.sha1, untracked->exclude_sha1)) {
|
||||
hashcmp(oid_stat.oid.hash, untracked->exclude_sha1)) {
|
||||
invalidate_gitignore(dir->untracked, untracked);
|
||||
hashcpy(untracked->exclude_sha1, sha1_stat.sha1);
|
||||
hashcpy(untracked->exclude_sha1, oid_stat.oid.hash);
|
||||
}
|
||||
dir->exclude_stack = stk;
|
||||
current = stk->baselen;
|
||||
|
@ -2228,13 +2225,13 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
|
|||
|
||||
/* Validate $GIT_DIR/info/exclude and core.excludesfile */
|
||||
root = dir->untracked->root;
|
||||
if (hashcmp(dir->ss_info_exclude.sha1,
|
||||
dir->untracked->ss_info_exclude.sha1)) {
|
||||
if (oidcmp(&dir->ss_info_exclude.oid,
|
||||
&dir->untracked->ss_info_exclude.oid)) {
|
||||
invalidate_gitignore(dir->untracked, root);
|
||||
dir->untracked->ss_info_exclude = dir->ss_info_exclude;
|
||||
}
|
||||
if (hashcmp(dir->ss_excludes_file.sha1,
|
||||
dir->untracked->ss_excludes_file.sha1)) {
|
||||
if (oidcmp(&dir->ss_excludes_file.oid,
|
||||
&dir->untracked->ss_excludes_file.oid)) {
|
||||
invalidate_gitignore(dir->untracked, root);
|
||||
dir->untracked->ss_excludes_file = dir->ss_excludes_file;
|
||||
}
|
||||
|
@ -2638,8 +2635,8 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
|
|||
FLEX_ALLOC_MEM(ouc, exclude_per_dir, untracked->exclude_per_dir, len);
|
||||
stat_data_to_disk(&ouc->info_exclude_stat, &untracked->ss_info_exclude.stat);
|
||||
stat_data_to_disk(&ouc->excludes_file_stat, &untracked->ss_excludes_file.stat);
|
||||
hashcpy(ouc->info_exclude_sha1, untracked->ss_info_exclude.sha1);
|
||||
hashcpy(ouc->excludes_file_sha1, untracked->ss_excludes_file.sha1);
|
||||
hashcpy(ouc->info_exclude_sha1, untracked->ss_info_exclude.oid.hash);
|
||||
hashcpy(ouc->excludes_file_sha1, untracked->ss_excludes_file.oid.hash);
|
||||
ouc->dir_flags = htonl(untracked->dir_flags);
|
||||
|
||||
varint_len = encode_varint(untracked->ident.len, varbuf);
|
||||
|
@ -2816,13 +2813,12 @@ static void read_sha1(size_t pos, void *cb)
|
|||
rd->data += 20;
|
||||
}
|
||||
|
||||
static void load_sha1_stat(struct sha1_stat *sha1_stat,
|
||||
const unsigned char *data,
|
||||
const unsigned char *sha1)
|
||||
static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
|
||||
const unsigned char *sha1)
|
||||
{
|
||||
stat_data_from_disk(&sha1_stat->stat, data);
|
||||
hashcpy(sha1_stat->sha1, sha1);
|
||||
sha1_stat->valid = 1;
|
||||
stat_data_from_disk(&oid_stat->stat, data);
|
||||
hashcpy(oid_stat->oid.hash, sha1);
|
||||
oid_stat->valid = 1;
|
||||
}
|
||||
|
||||
struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz)
|
||||
|
@ -2850,12 +2846,12 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
|
|||
uc = xcalloc(1, sizeof(*uc));
|
||||
strbuf_init(&uc->ident, ident_len);
|
||||
strbuf_add(&uc->ident, ident, ident_len);
|
||||
load_sha1_stat(&uc->ss_info_exclude,
|
||||
next + ouc_offset(info_exclude_stat),
|
||||
next + ouc_offset(info_exclude_sha1));
|
||||
load_sha1_stat(&uc->ss_excludes_file,
|
||||
next + ouc_offset(excludes_file_stat),
|
||||
next + ouc_offset(excludes_file_sha1));
|
||||
load_oid_stat(&uc->ss_info_exclude,
|
||||
next + ouc_offset(info_exclude_stat),
|
||||
next + ouc_offset(info_exclude_sha1));
|
||||
load_oid_stat(&uc->ss_excludes_file,
|
||||
next + ouc_offset(excludes_file_stat),
|
||||
next + ouc_offset(excludes_file_sha1));
|
||||
uc->dir_flags = get_be32(next + ouc_offset(dir_flags));
|
||||
exclude_per_dir = (const char *)next + ouc_offset(exclude_per_dir);
|
||||
uc->exclude_per_dir = xstrdup(exclude_per_dir);
|
||||
|
|
12
dir.h
12
dir.h
|
@ -74,9 +74,9 @@ struct exclude_list_group {
|
|||
struct exclude_list *el;
|
||||
};
|
||||
|
||||
struct sha1_stat {
|
||||
struct oid_stat {
|
||||
struct stat_data stat;
|
||||
unsigned char sha1[20];
|
||||
struct object_id oid;
|
||||
int valid;
|
||||
};
|
||||
|
||||
|
@ -124,8 +124,8 @@ struct untracked_cache_dir {
|
|||
};
|
||||
|
||||
struct untracked_cache {
|
||||
struct sha1_stat ss_info_exclude;
|
||||
struct sha1_stat ss_excludes_file;
|
||||
struct oid_stat ss_info_exclude;
|
||||
struct oid_stat ss_excludes_file;
|
||||
const char *exclude_per_dir;
|
||||
struct strbuf ident;
|
||||
/*
|
||||
|
@ -195,8 +195,8 @@ struct dir_struct {
|
|||
|
||||
/* Enable untracked file cache if set */
|
||||
struct untracked_cache *untracked;
|
||||
struct sha1_stat ss_info_exclude;
|
||||
struct sha1_stat ss_excludes_file;
|
||||
struct oid_stat ss_info_exclude;
|
||||
struct oid_stat ss_excludes_file;
|
||||
unsigned unmanaged_exclude_files;
|
||||
};
|
||||
|
||||
|
|
|
@ -499,7 +499,7 @@ static void show_one_mergetag(struct commit *commit,
|
|||
int status, nth;
|
||||
size_t payload_size, gpg_message_offset;
|
||||
|
||||
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), oid.hash);
|
||||
hash_object_file(extra->value, extra->len, typename(OBJ_TAG), &oid);
|
||||
tag = lookup_tag(&oid);
|
||||
if (!tag)
|
||||
return; /* error message already given */
|
||||
|
|
|
@ -158,22 +158,20 @@ static void match_trees(const struct object_id *hash1,
|
|||
}
|
||||
|
||||
/*
|
||||
* A tree "hash1" has a subdirectory at "prefix". Come up with a
|
||||
* tree object by replacing it with another tree "hash2".
|
||||
* A tree "oid1" has a subdirectory at "prefix". Come up with a tree object by
|
||||
* replacing it with another tree "oid2".
|
||||
*/
|
||||
static int splice_tree(const unsigned char *hash1,
|
||||
const char *prefix,
|
||||
const unsigned char *hash2,
|
||||
unsigned char *result)
|
||||
static int splice_tree(const struct object_id *oid1, const char *prefix,
|
||||
const struct object_id *oid2, struct object_id *result)
|
||||
{
|
||||
char *subpath;
|
||||
int toplen;
|
||||
char *buf;
|
||||
unsigned long sz;
|
||||
struct tree_desc desc;
|
||||
unsigned char *rewrite_here;
|
||||
const unsigned char *rewrite_with;
|
||||
unsigned char subtree[20];
|
||||
struct object_id *rewrite_here;
|
||||
const struct object_id *rewrite_with;
|
||||
struct object_id subtree;
|
||||
enum object_type type;
|
||||
int status;
|
||||
|
||||
|
@ -182,9 +180,9 @@ static int splice_tree(const unsigned char *hash1,
|
|||
if (*subpath)
|
||||
subpath++;
|
||||
|
||||
buf = read_sha1_file(hash1, &type, &sz);
|
||||
buf = read_sha1_file(oid1->hash, &type, &sz);
|
||||
if (!buf)
|
||||
die("cannot read tree %s", sha1_to_hex(hash1));
|
||||
die("cannot read tree %s", oid_to_hex(oid1));
|
||||
init_tree_desc(&desc, buf, sz);
|
||||
|
||||
rewrite_here = NULL;
|
||||
|
@ -197,26 +195,26 @@ static int splice_tree(const unsigned char *hash1,
|
|||
if (strlen(name) == toplen &&
|
||||
!memcmp(name, prefix, toplen)) {
|
||||
if (!S_ISDIR(mode))
|
||||
die("entry %s in tree %s is not a tree",
|
||||
name, sha1_to_hex(hash1));
|
||||
rewrite_here = (unsigned char *) oid->hash;
|
||||
die("entry %s in tree %s is not a tree", name,
|
||||
oid_to_hex(oid1));
|
||||
rewrite_here = (struct object_id *)oid;
|
||||
break;
|
||||
}
|
||||
update_tree_entry(&desc);
|
||||
}
|
||||
if (!rewrite_here)
|
||||
die("entry %.*s not found in tree %s",
|
||||
toplen, prefix, sha1_to_hex(hash1));
|
||||
die("entry %.*s not found in tree %s", toplen, prefix,
|
||||
oid_to_hex(oid1));
|
||||
if (*subpath) {
|
||||
status = splice_tree(rewrite_here, subpath, hash2, subtree);
|
||||
status = splice_tree(rewrite_here, subpath, oid2, &subtree);
|
||||
if (status)
|
||||
return status;
|
||||
rewrite_with = subtree;
|
||||
rewrite_with = &subtree;
|
||||
} else {
|
||||
rewrite_with = oid2;
|
||||
}
|
||||
else
|
||||
rewrite_with = hash2;
|
||||
hashcpy(rewrite_here, rewrite_with);
|
||||
status = write_sha1_file(buf, sz, tree_type, result);
|
||||
oidcpy(rewrite_here, rewrite_with);
|
||||
status = write_object_file(buf, sz, tree_type, result);
|
||||
free(buf);
|
||||
return status;
|
||||
}
|
||||
|
@ -280,7 +278,7 @@ void shift_tree(const struct object_id *hash1,
|
|||
if (!*add_prefix)
|
||||
return;
|
||||
|
||||
splice_tree(hash1->hash, add_prefix, hash2->hash, shifted->hash);
|
||||
splice_tree(hash1, add_prefix, hash2, shifted);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -334,7 +332,7 @@ void shift_tree_by(const struct object_id *hash1,
|
|||
* shift tree2 down by adding shift_prefix above it
|
||||
* to match tree1.
|
||||
*/
|
||||
splice_tree(hash1->hash, shift_prefix, hash2->hash, shifted->hash);
|
||||
splice_tree(hash1, shift_prefix, hash2, shifted);
|
||||
else
|
||||
/*
|
||||
* shift tree2 up by removing shift_prefix from it
|
||||
|
|
|
@ -1028,8 +1028,9 @@ static int merge_file_1(struct merge_options *o,
|
|||
if ((merge_status < 0) || !result_buf.ptr)
|
||||
ret = err(o, _("Failed to execute internal merge"));
|
||||
|
||||
if (!ret && write_sha1_file(result_buf.ptr, result_buf.size,
|
||||
blob_type, result->oid.hash))
|
||||
if (!ret &&
|
||||
write_object_file(result_buf.ptr, result_buf.size,
|
||||
blob_type, &result->oid))
|
||||
ret = err(o, _("Unable to add %s to database"),
|
||||
a->path);
|
||||
|
||||
|
|
|
@ -54,10 +54,10 @@ int notes_cache_write(struct notes_cache *c)
|
|||
if (!c->tree.dirty)
|
||||
return 0;
|
||||
|
||||
if (write_notes_tree(&c->tree, tree_oid.hash))
|
||||
if (write_notes_tree(&c->tree, &tree_oid))
|
||||
return -1;
|
||||
if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL,
|
||||
commit_oid.hash, NULL, NULL) < 0)
|
||||
if (commit_tree(c->validity, strlen(c->validity), &tree_oid, NULL,
|
||||
&commit_oid, NULL, NULL) < 0)
|
||||
return -1;
|
||||
if (update_ref("update notes cache", c->tree.update_ref, &commit_oid,
|
||||
NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
|
||||
|
@ -88,7 +88,7 @@ int notes_cache_put(struct notes_cache *c, struct object_id *key_oid,
|
|||
{
|
||||
struct object_id value_oid;
|
||||
|
||||
if (write_sha1_file(data, size, "blob", value_oid.hash) < 0)
|
||||
if (write_object_file(data, size, "blob", &value_oid) < 0)
|
||||
return -1;
|
||||
return add_note(&c->tree, key_oid, &value_oid, NULL);
|
||||
}
|
||||
|
|
|
@ -642,9 +642,8 @@ int notes_merge(struct notes_merge_options *o,
|
|||
struct commit_list *parents = NULL;
|
||||
commit_list_insert(remote, &parents); /* LIFO order */
|
||||
commit_list_insert(local, &parents);
|
||||
create_notes_commit(local_tree, parents,
|
||||
o->commit_msg.buf, o->commit_msg.len,
|
||||
result_oid->hash);
|
||||
create_notes_commit(local_tree, parents, o->commit_msg.buf,
|
||||
o->commit_msg.len, result_oid);
|
||||
}
|
||||
|
||||
found_result:
|
||||
|
@ -718,8 +717,8 @@ int notes_merge_commit(struct notes_merge_options *o,
|
|||
strbuf_setlen(&path, baselen);
|
||||
}
|
||||
|
||||
create_notes_commit(partial_tree, partial_commit->parents,
|
||||
msg, strlen(msg), result_oid->hash);
|
||||
create_notes_commit(partial_tree, partial_commit->parents, msg,
|
||||
strlen(msg), result_oid);
|
||||
unuse_commit_buffer(partial_commit, buffer);
|
||||
if (o->verbosity >= 4)
|
||||
printf("Finalized notes merge commit: %s\n",
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
|
||||
const char *msg, size_t msg_len,
|
||||
unsigned char *result_sha1)
|
||||
struct object_id *result_oid)
|
||||
{
|
||||
struct object_id tree_oid;
|
||||
|
||||
assert(t->initialized);
|
||||
|
||||
if (write_notes_tree(t, tree_oid.hash))
|
||||
if (write_notes_tree(t, &tree_oid))
|
||||
die("Failed to write notes tree to database");
|
||||
|
||||
if (!parents) {
|
||||
|
@ -27,7 +27,8 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
|
|||
/* else: t->ref points to nothing, assume root/orphan commit */
|
||||
}
|
||||
|
||||
if (commit_tree(msg, msg_len, tree_oid.hash, parents, result_sha1, NULL, NULL))
|
||||
if (commit_tree(msg, msg_len, &tree_oid, parents, result_oid, NULL,
|
||||
NULL))
|
||||
die("Failed to commit notes tree to database");
|
||||
}
|
||||
|
||||
|
@ -47,7 +48,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
|
|||
strbuf_addstr(&buf, msg);
|
||||
strbuf_complete_line(&buf);
|
||||
|
||||
create_notes_commit(t, NULL, buf.buf, buf.len, commit_oid.hash);
|
||||
create_notes_commit(t, NULL, buf.buf, buf.len, &commit_oid);
|
||||
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
|
||||
update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
|
||||
UPDATE_REFS_DIE_ON_ERR);
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
* The resulting commit SHA1 is stored in result_sha1.
|
||||
*/
|
||||
void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
|
||||
const char *msg, size_t msg_len, unsigned char *result_sha1);
|
||||
const char *msg, size_t msg_len,
|
||||
struct object_id *result_oid);
|
||||
|
||||
void commit_notes(struct notes_tree *t, const char *msg);
|
||||
|
||||
|
|
63
notes.c
63
notes.c
|
@ -270,8 +270,8 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
|
|||
if (!oidcmp(&l->val_oid, &entry->val_oid))
|
||||
return 0;
|
||||
|
||||
ret = combine_notes(l->val_oid.hash,
|
||||
entry->val_oid.hash);
|
||||
ret = combine_notes(&l->val_oid,
|
||||
&entry->val_oid);
|
||||
if (!ret && is_null_oid(&l->val_oid))
|
||||
note_tree_remove(t, tree, n, entry);
|
||||
free(entry);
|
||||
|
@ -667,7 +667,7 @@ static int tree_write_stack_finish_subtree(struct tree_write_stack *tws)
|
|||
ret = tree_write_stack_finish_subtree(n);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = write_sha1_file(n->buf.buf, n->buf.len, tree_type, s.hash);
|
||||
ret = write_object_file(n->buf.buf, n->buf.len, tree_type, &s);
|
||||
if (ret)
|
||||
return ret;
|
||||
strbuf_release(&n->buf);
|
||||
|
@ -786,8 +786,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int combine_notes_concatenate(unsigned char *cur_sha1,
|
||||
const unsigned char *new_sha1)
|
||||
int combine_notes_concatenate(struct object_id *cur_oid,
|
||||
const struct object_id *new_oid)
|
||||
{
|
||||
char *cur_msg = NULL, *new_msg = NULL, *buf;
|
||||
unsigned long cur_len, new_len, buf_len;
|
||||
|
@ -795,18 +795,18 @@ int combine_notes_concatenate(unsigned char *cur_sha1,
|
|||
int ret;
|
||||
|
||||
/* read in both note blob objects */
|
||||
if (!is_null_sha1(new_sha1))
|
||||
new_msg = read_sha1_file(new_sha1, &new_type, &new_len);
|
||||
if (!is_null_oid(new_oid))
|
||||
new_msg = read_sha1_file(new_oid->hash, &new_type, &new_len);
|
||||
if (!new_msg || !new_len || new_type != OBJ_BLOB) {
|
||||
free(new_msg);
|
||||
return 0;
|
||||
}
|
||||
if (!is_null_sha1(cur_sha1))
|
||||
cur_msg = read_sha1_file(cur_sha1, &cur_type, &cur_len);
|
||||
if (!is_null_oid(cur_oid))
|
||||
cur_msg = read_sha1_file(cur_oid->hash, &cur_type, &cur_len);
|
||||
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
|
||||
free(cur_msg);
|
||||
free(new_msg);
|
||||
hashcpy(cur_sha1, new_sha1);
|
||||
oidcpy(cur_oid, new_oid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -825,20 +825,20 @@ int combine_notes_concatenate(unsigned char *cur_sha1,
|
|||
free(new_msg);
|
||||
|
||||
/* create a new blob object from buf */
|
||||
ret = write_sha1_file(buf, buf_len, blob_type, cur_sha1);
|
||||
ret = write_object_file(buf, buf_len, blob_type, cur_oid);
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int combine_notes_overwrite(unsigned char *cur_sha1,
|
||||
const unsigned char *new_sha1)
|
||||
int combine_notes_overwrite(struct object_id *cur_oid,
|
||||
const struct object_id *new_oid)
|
||||
{
|
||||
hashcpy(cur_sha1, new_sha1);
|
||||
oidcpy(cur_oid, new_oid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int combine_notes_ignore(unsigned char *cur_sha1,
|
||||
const unsigned char *new_sha1)
|
||||
int combine_notes_ignore(struct object_id *cur_oid,
|
||||
const struct object_id *new_oid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -848,17 +848,17 @@ int combine_notes_ignore(unsigned char *cur_sha1,
|
|||
* newlines removed.
|
||||
*/
|
||||
static int string_list_add_note_lines(struct string_list *list,
|
||||
const unsigned char *sha1)
|
||||
const struct object_id *oid)
|
||||
{
|
||||
char *data;
|
||||
unsigned long len;
|
||||
enum object_type t;
|
||||
|
||||
if (is_null_sha1(sha1))
|
||||
if (is_null_oid(oid))
|
||||
return 0;
|
||||
|
||||
/* read_sha1_file NUL-terminates */
|
||||
data = read_sha1_file(sha1, &t, &len);
|
||||
data = read_sha1_file(oid->hash, &t, &len);
|
||||
if (t != OBJ_BLOB || !data || !len) {
|
||||
free(data);
|
||||
return t != OBJ_BLOB || !data;
|
||||
|
@ -884,17 +884,17 @@ static int string_list_join_lines_helper(struct string_list_item *item,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int combine_notes_cat_sort_uniq(unsigned char *cur_sha1,
|
||||
const unsigned char *new_sha1)
|
||||
int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
|
||||
const struct object_id *new_oid)
|
||||
{
|
||||
struct string_list sort_uniq_list = STRING_LIST_INIT_DUP;
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
int ret = 1;
|
||||
|
||||
/* read both note blob objects into unique_lines */
|
||||
if (string_list_add_note_lines(&sort_uniq_list, cur_sha1))
|
||||
if (string_list_add_note_lines(&sort_uniq_list, cur_oid))
|
||||
goto out;
|
||||
if (string_list_add_note_lines(&sort_uniq_list, new_sha1))
|
||||
if (string_list_add_note_lines(&sort_uniq_list, new_oid))
|
||||
goto out;
|
||||
string_list_remove_empty_items(&sort_uniq_list, 0);
|
||||
string_list_sort(&sort_uniq_list);
|
||||
|
@ -905,7 +905,7 @@ int combine_notes_cat_sort_uniq(unsigned char *cur_sha1,
|
|||
string_list_join_lines_helper, &buf))
|
||||
goto out;
|
||||
|
||||
ret = write_sha1_file(buf.buf, buf.len, blob_type, cur_sha1);
|
||||
ret = write_object_file(buf.buf, buf.len, blob_type, cur_oid);
|
||||
|
||||
out:
|
||||
strbuf_release(&buf);
|
||||
|
@ -1123,11 +1123,12 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
|
|||
return for_each_note_helper(t, t->root, 0, 0, flags, fn, cb_data);
|
||||
}
|
||||
|
||||
int write_notes_tree(struct notes_tree *t, unsigned char *result)
|
||||
int write_notes_tree(struct notes_tree *t, struct object_id *result)
|
||||
{
|
||||
struct tree_write_stack root;
|
||||
struct write_each_note_data cb_data;
|
||||
int ret;
|
||||
int flags;
|
||||
|
||||
if (!t)
|
||||
t = &default_notes_tree;
|
||||
|
@ -1141,12 +1142,12 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result)
|
|||
cb_data.next_non_note = t->first_non_note;
|
||||
|
||||
/* Write tree objects representing current notes tree */
|
||||
ret = for_each_note(t, FOR_EACH_NOTE_DONT_UNPACK_SUBTREES |
|
||||
FOR_EACH_NOTE_YIELD_SUBTREES,
|
||||
write_each_note, &cb_data) ||
|
||||
write_each_non_note_until(NULL, &cb_data) ||
|
||||
tree_write_stack_finish_subtree(&root) ||
|
||||
write_sha1_file(root.buf.buf, root.buf.len, tree_type, result);
|
||||
flags = FOR_EACH_NOTE_DONT_UNPACK_SUBTREES |
|
||||
FOR_EACH_NOTE_YIELD_SUBTREES;
|
||||
ret = for_each_note(t, flags, write_each_note, &cb_data) ||
|
||||
write_each_non_note_until(NULL, &cb_data) ||
|
||||
tree_write_stack_finish_subtree(&root) ||
|
||||
write_object_file(root.buf.buf, root.buf.len, tree_type, result);
|
||||
strbuf_release(&root.buf);
|
||||
return ret;
|
||||
}
|
||||
|
|
29
notes.h
29
notes.h
|
@ -9,27 +9,32 @@
|
|||
* When adding a new note annotating the same object as an existing note, it is
|
||||
* up to the caller to decide how to combine the two notes. The decision is
|
||||
* made by passing in a function of the following form. The function accepts
|
||||
* two SHA1s -- of the existing note and the new note, respectively. The
|
||||
* two object_ids -- of the existing note and the new note, respectively. The
|
||||
* function then combines the notes in whatever way it sees fit, and writes the
|
||||
* resulting SHA1 into the first SHA1 argument (cur_sha1). A non-zero return
|
||||
* resulting oid into the first argument (cur_oid). A non-zero return
|
||||
* value indicates failure.
|
||||
*
|
||||
* The two given SHA1s shall both be non-NULL and different from each other.
|
||||
* Either of them (but not both) may be == null_sha1, which indicates an
|
||||
* empty/non-existent note. If the resulting SHA1 (cur_sha1) is == null_sha1,
|
||||
* The two given object_ids shall both be non-NULL and different from each
|
||||
* other. Either of them (but not both) may be == null_oid, which indicates an
|
||||
* empty/non-existent note. If the resulting oid (cur_oid) is == null_oid,
|
||||
* the note will be removed from the notes tree.
|
||||
*
|
||||
* The default combine_notes function (you get this when passing NULL) is
|
||||
* combine_notes_concatenate(), which appends the contents of the new note to
|
||||
* the contents of the existing note.
|
||||
*/
|
||||
typedef int (*combine_notes_fn)(unsigned char *cur_sha1, const unsigned char *new_sha1);
|
||||
typedef int (*combine_notes_fn)(struct object_id *cur_oid,
|
||||
const struct object_id *new_oid);
|
||||
|
||||
/* Common notes combinators */
|
||||
int combine_notes_concatenate(unsigned char *cur_sha1, const unsigned char *new_sha1);
|
||||
int combine_notes_overwrite(unsigned char *cur_sha1, const unsigned char *new_sha1);
|
||||
int combine_notes_ignore(unsigned char *cur_sha1, const unsigned char *new_sha1);
|
||||
int combine_notes_cat_sort_uniq(unsigned char *cur_sha1, const unsigned char *new_sha1);
|
||||
int combine_notes_concatenate(struct object_id *cur_oid,
|
||||
const struct object_id *new_oid);
|
||||
int combine_notes_overwrite(struct object_id *cur_oid,
|
||||
const struct object_id *new_oid);
|
||||
int combine_notes_ignore(struct object_id *cur_oid,
|
||||
const struct object_id *new_oid);
|
||||
int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
|
||||
const struct object_id *new_oid);
|
||||
|
||||
/*
|
||||
* Notes tree object
|
||||
|
@ -212,7 +217,7 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
|
|||
* Write the given notes_tree structure to the object database
|
||||
*
|
||||
* Creates a new tree object encapsulating the current state of the given
|
||||
* notes_tree, and stores its SHA1 into the 'result' argument.
|
||||
* notes_tree, and stores its object id into the 'result' argument.
|
||||
*
|
||||
* Returns zero on success, non-zero on failure.
|
||||
*
|
||||
|
@ -220,7 +225,7 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
|
|||
* this function has returned zero. Please also remember to create a
|
||||
* corresponding commit object, and update the appropriate notes ref.
|
||||
*/
|
||||
int write_notes_tree(struct notes_tree *t, unsigned char *result);
|
||||
int write_notes_tree(struct notes_tree *t, struct object_id *result);
|
||||
|
||||
/* Flags controlling the operation of prune */
|
||||
#define NOTES_PRUNE_VERBOSE 1
|
||||
|
|
|
@ -631,10 +631,10 @@ static struct cache_entry *create_alias_ce(struct index_state *istate,
|
|||
|
||||
void set_object_name_for_intent_to_add_entry(struct cache_entry *ce)
|
||||
{
|
||||
unsigned char sha1[20];
|
||||
if (write_sha1_file("", 0, blob_type, sha1))
|
||||
struct object_id oid;
|
||||
if (write_object_file("", 0, blob_type, &oid))
|
||||
die("cannot create an empty blob in the object database");
|
||||
hashcpy(ce->oid.hash, sha1);
|
||||
oidcpy(&ce->oid, &oid);
|
||||
}
|
||||
|
||||
int add_to_index(struct index_state *istate, const char *path, struct stat *st, int flags)
|
||||
|
|
|
@ -1149,8 +1149,8 @@ static int try_to_commit(struct strbuf *msg, const char *author,
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (commit_tree_extended(msg->buf, msg->len, tree.hash, parents,
|
||||
oid->hash, author, opts->gpg_sign, extra)) {
|
||||
if (commit_tree_extended(msg->buf, msg->len, &tree, parents,
|
||||
oid, author, opts->gpg_sign, extra)) {
|
||||
res = error(_("failed to write commit object"));
|
||||
goto out;
|
||||
}
|
||||
|
|
100
sha1_file.c
100
sha1_file.c
|
@ -789,7 +789,7 @@ void *xmmap(void *start, size_t length,
|
|||
int check_sha1_signature(const unsigned char *sha1, void *map,
|
||||
unsigned long size, const char *type)
|
||||
{
|
||||
unsigned char real_sha1[20];
|
||||
struct object_id real_oid;
|
||||
enum object_type obj_type;
|
||||
struct git_istream *st;
|
||||
git_SHA_CTX c;
|
||||
|
@ -797,8 +797,8 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
|
|||
int hdrlen;
|
||||
|
||||
if (map) {
|
||||
hash_sha1_file(map, size, type, real_sha1);
|
||||
return hashcmp(sha1, real_sha1) ? -1 : 0;
|
||||
hash_object_file(map, size, type, &real_oid);
|
||||
return hashcmp(sha1, real_oid.hash) ? -1 : 0;
|
||||
}
|
||||
|
||||
st = open_istream(sha1, &obj_type, &size, NULL);
|
||||
|
@ -823,9 +823,9 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
|
|||
break;
|
||||
git_SHA1_Update(&c, buf, readlen);
|
||||
}
|
||||
git_SHA1_Final(real_sha1, &c);
|
||||
git_SHA1_Final(real_oid.hash, &c);
|
||||
close_istream(st);
|
||||
return hashcmp(sha1, real_sha1) ? -1 : 0;
|
||||
return hashcmp(sha1, real_oid.hash) ? -1 : 0;
|
||||
}
|
||||
|
||||
int git_open_cloexec(const char *name, int flags)
|
||||
|
@ -1336,13 +1336,13 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
|
|||
return content;
|
||||
}
|
||||
|
||||
int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
|
||||
unsigned char *sha1)
|
||||
int pretend_object_file(void *buf, unsigned long len, enum object_type type,
|
||||
struct object_id *oid)
|
||||
{
|
||||
struct cached_object *co;
|
||||
|
||||
hash_sha1_file(buf, len, typename(type), sha1);
|
||||
if (has_sha1_file(sha1) || find_cached_object(sha1))
|
||||
hash_object_file(buf, len, typename(type), oid);
|
||||
if (has_sha1_file(oid->hash) || find_cached_object(oid->hash))
|
||||
return 0;
|
||||
ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
|
||||
co = &cached_objects[cached_object_nr++];
|
||||
|
@ -1350,7 +1350,7 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
|
|||
co->type = type;
|
||||
co->buf = xmalloc(len);
|
||||
memcpy(co->buf, buf, len);
|
||||
hashcpy(co->sha1, sha1);
|
||||
hashcpy(co->sha1, oid->hash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1443,9 +1443,9 @@ void *read_object_with_reference(const unsigned char *sha1,
|
|||
}
|
||||
}
|
||||
|
||||
static void write_sha1_file_prepare(const void *buf, unsigned long len,
|
||||
const char *type, unsigned char *sha1,
|
||||
char *hdr, int *hdrlen)
|
||||
static void write_object_file_prepare(const void *buf, unsigned long len,
|
||||
const char *type, struct object_id *oid,
|
||||
char *hdr, int *hdrlen)
|
||||
{
|
||||
git_SHA_CTX c;
|
||||
|
||||
|
@ -1456,7 +1456,7 @@ static void write_sha1_file_prepare(const void *buf, unsigned long len,
|
|||
git_SHA1_Init(&c);
|
||||
git_SHA1_Update(&c, hdr, *hdrlen);
|
||||
git_SHA1_Update(&c, buf, len);
|
||||
git_SHA1_Final(sha1, &c);
|
||||
git_SHA1_Final(oid->hash, &c);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1509,12 +1509,12 @@ static int write_buffer(int fd, const void *buf, size_t len)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int hash_sha1_file(const void *buf, unsigned long len, const char *type,
|
||||
unsigned char *sha1)
|
||||
int hash_object_file(const void *buf, unsigned long len, const char *type,
|
||||
struct object_id *oid)
|
||||
{
|
||||
char hdr[32];
|
||||
int hdrlen = sizeof(hdr);
|
||||
write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
|
||||
write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1572,19 +1572,20 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename)
|
|||
return fd;
|
||||
}
|
||||
|
||||
static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
|
||||
const void *buf, unsigned long len, time_t mtime)
|
||||
static int write_loose_object(const struct object_id *oid, char *hdr,
|
||||
int hdrlen, const void *buf, unsigned long len,
|
||||
time_t mtime)
|
||||
{
|
||||
int fd, ret;
|
||||
unsigned char compressed[4096];
|
||||
git_zstream stream;
|
||||
git_SHA_CTX c;
|
||||
unsigned char parano_sha1[20];
|
||||
struct object_id parano_oid;
|
||||
static struct strbuf tmp_file = STRBUF_INIT;
|
||||
static struct strbuf filename = STRBUF_INIT;
|
||||
|
||||
strbuf_reset(&filename);
|
||||
sha1_file_name(&filename, sha1);
|
||||
sha1_file_name(&filename, oid->hash);
|
||||
|
||||
fd = create_tmpfile(&tmp_file, filename.buf);
|
||||
if (fd < 0) {
|
||||
|
@ -1621,13 +1622,16 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
|
|||
} while (ret == Z_OK);
|
||||
|
||||
if (ret != Z_STREAM_END)
|
||||
die("unable to deflate new object %s (%d)", sha1_to_hex(sha1), ret);
|
||||
die("unable to deflate new object %s (%d)", oid_to_hex(oid),
|
||||
ret);
|
||||
ret = git_deflate_end_gently(&stream);
|
||||
if (ret != Z_OK)
|
||||
die("deflateEnd on object %s failed (%d)", sha1_to_hex(sha1), ret);
|
||||
git_SHA1_Final(parano_sha1, &c);
|
||||
if (hashcmp(sha1, parano_sha1) != 0)
|
||||
die("confused by unstable object source data for %s", sha1_to_hex(sha1));
|
||||
die("deflateEnd on object %s failed (%d)", oid_to_hex(oid),
|
||||
ret);
|
||||
git_SHA1_Final(parano_oid.hash, &c);
|
||||
if (oidcmp(oid, ¶no_oid) != 0)
|
||||
die("confused by unstable object source data for %s",
|
||||
oid_to_hex(oid));
|
||||
|
||||
close_sha1_file(fd);
|
||||
|
||||
|
@ -1660,7 +1664,8 @@ static int freshen_packed_object(const unsigned char *sha1)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1)
|
||||
int write_object_file(const void *buf, unsigned long len, const char *type,
|
||||
struct object_id *oid)
|
||||
{
|
||||
char hdr[32];
|
||||
int hdrlen = sizeof(hdr);
|
||||
|
@ -1668,14 +1673,15 @@ int write_sha1_file(const void *buf, unsigned long len, const char *type, unsign
|
|||
/* Normally if we have it in the pack then we do not bother writing
|
||||
* it out into .git/objects/??/?{38} file.
|
||||
*/
|
||||
write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
|
||||
if (freshen_packed_object(sha1) || freshen_loose_object(sha1))
|
||||
write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
|
||||
if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash))
|
||||
return 0;
|
||||
return write_loose_object(sha1, hdr, hdrlen, buf, len, 0);
|
||||
return write_loose_object(oid, hdr, hdrlen, buf, len, 0);
|
||||
}
|
||||
|
||||
int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type,
|
||||
struct object_id *oid, unsigned flags)
|
||||
int hash_object_file_literally(const void *buf, unsigned long len,
|
||||
const char *type, struct object_id *oid,
|
||||
unsigned flags)
|
||||
{
|
||||
char *header;
|
||||
int hdrlen, status = 0;
|
||||
|
@ -1683,20 +1689,20 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typ
|
|||
/* type string, SP, %lu of the length plus NUL must fit this */
|
||||
hdrlen = strlen(type) + 32;
|
||||
header = xmalloc(hdrlen);
|
||||
write_sha1_file_prepare(buf, len, type, oid->hash, header, &hdrlen);
|
||||
write_object_file_prepare(buf, len, type, oid, header, &hdrlen);
|
||||
|
||||
if (!(flags & HASH_WRITE_OBJECT))
|
||||
goto cleanup;
|
||||
if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash))
|
||||
goto cleanup;
|
||||
status = write_loose_object(oid->hash, header, hdrlen, buf, len, 0);
|
||||
status = write_loose_object(oid, header, hdrlen, buf, len, 0);
|
||||
|
||||
cleanup:
|
||||
free(header);
|
||||
return status;
|
||||
}
|
||||
|
||||
int force_object_loose(const unsigned char *sha1, time_t mtime)
|
||||
int force_object_loose(const struct object_id *oid, time_t mtime)
|
||||
{
|
||||
void *buf;
|
||||
unsigned long len;
|
||||
|
@ -1705,13 +1711,13 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
|
|||
int hdrlen;
|
||||
int ret;
|
||||
|
||||
if (has_loose_object(sha1))
|
||||
if (has_loose_object(oid->hash))
|
||||
return 0;
|
||||
buf = read_object(sha1, &type, &len);
|
||||
buf = read_object(oid->hash, &type, &len);
|
||||
if (!buf)
|
||||
return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
|
||||
return error("cannot read sha1_file for %s", oid_to_hex(oid));
|
||||
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
|
||||
ret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
|
||||
ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime);
|
||||
free(buf);
|
||||
|
||||
return ret;
|
||||
|
@ -1794,9 +1800,9 @@ static int index_mem(struct object_id *oid, void *buf, size_t size,
|
|||
}
|
||||
|
||||
if (write_object)
|
||||
ret = write_sha1_file(buf, size, typename(type), oid->hash);
|
||||
ret = write_object_file(buf, size, typename(type), oid);
|
||||
else
|
||||
ret = hash_sha1_file(buf, size, typename(type), oid->hash);
|
||||
ret = hash_object_file(buf, size, typename(type), oid);
|
||||
if (re_allocated)
|
||||
free(buf);
|
||||
return ret;
|
||||
|
@ -1816,11 +1822,11 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,
|
|||
get_conv_flags(flags));
|
||||
|
||||
if (write_object)
|
||||
ret = write_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
|
||||
oid->hash);
|
||||
ret = write_object_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
|
||||
oid);
|
||||
else
|
||||
ret = hash_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
|
||||
oid->hash);
|
||||
ret = hash_object_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
|
||||
oid);
|
||||
strbuf_release(&sbuf);
|
||||
return ret;
|
||||
}
|
||||
|
@ -1934,8 +1940,8 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
|
|||
if (strbuf_readlink(&sb, path, st->st_size))
|
||||
return error_errno("readlink(\"%s\")", path);
|
||||
if (!(flags & HASH_WRITE_OBJECT))
|
||||
hash_sha1_file(sb.buf, sb.len, blob_type, oid->hash);
|
||||
else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash))
|
||||
hash_object_file(sb.buf, sb.len, blob_type, oid);
|
||||
else if (write_object_file(sb.buf, sb.len, blob_type, oid))
|
||||
rc = error("%s: failed to insert into database", path);
|
||||
strbuf_release(&sb);
|
||||
break;
|
||||
|
|
|
@ -54,8 +54,8 @@ int cmd_main(int ac, const char **av)
|
|||
printf("no untracked cache\n");
|
||||
return 0;
|
||||
}
|
||||
printf("info/exclude %s\n", sha1_to_hex(uc->ss_info_exclude.sha1));
|
||||
printf("core.excludesfile %s\n", sha1_to_hex(uc->ss_excludes_file.sha1));
|
||||
printf("info/exclude %s\n", oid_to_hex(&uc->ss_info_exclude.oid));
|
||||
printf("core.excludesfile %s\n", oid_to_hex(&uc->ss_excludes_file.oid));
|
||||
printf("exclude_per_dir %s\n", uc->exclude_per_dir);
|
||||
printf("flags %08x\n", uc->dir_flags);
|
||||
if (uc->root)
|
||||
|
|
Загрузка…
Ссылка в новой задаче