Some fixes and bunch of object_id conversions
Subsystems (2)
cover Some fixes and bunch of object_id conversions
This patch series puts some mundane groundwork for experimentation with a new hashing algorithm in git-hash-object.
Some time has passed since my last patches, and I see, that work on new hashing algorithm progressed nicely since then:
* brian m. carlson implemented vtable for hash algorithm selection and pushed the repository format front - thanks to him it's now quite easy to experimentally replace hashing functions and, e.g. do some performance testing.
* _a lot of people_ contributed to the transition plan, and now it's available in text format in Documentation dir - Thank you all! It's much more readable this way.
Patch 1 is not directly related to object_id conversions but helped with debugging t5540, which kept failing on master for me (spoiler: it was Fedora fault). It helps with debugging of failing git-push over HTTP in case of internal server error, so I think it might be worthwhile.
Patch 2 is a small adjustment to .clang-format, which prevents unnecessary line breaks after function return type.
Patch 6 is a tiny fix in oidclr function.
All other patches are progressive conversions to struct object_id with some formatting fixes sprinkled in. These should be somewhat uncontroversial, I hope.
Patryk Obara (11):
http-push: improve error log
clang-format: adjust penalty for return type line break
sha1_file: convert pretend_sha1_file to object_id
dir: convert struct sha1_stat to use object_id
sha1_file: convert hash_sha1_file to object_id
cache: clear whole hash buffer with oidclr
match-trees: convert splice_tree to object_id
commit: convert commit_tree* to object_id
notes: convert combine_notes_* to object_id
notes: convert write_notes_tree to object_id
sha1_file: convert write_sha1_file to object_id
.clang-format | 2 +- apply.c | 12 +++---- blame.c | 2 +- builtin/am.c | 4 +-- builtin/checkout.c | 3 +- builtin/commit-tree.c | 4 +-- builtin/commit.c | 5 +-- builtin/index-pack.c | 3 +- builtin/merge.c | 8 ++--- builtin/mktag.c | 6 ++-- builtin/mktree.c | 10 +++--- builtin/notes.c | 8 ++--- builtin/receive-pack.c | 11 ++++--- builtin/replace.c | 4 +-- builtin/tag.c | 2 +- builtin/unpack-objects.c | 11 ++++--- cache-tree.c | 13 ++++---- cache.h | 13 ++++---- commit.c | 13 ++++---- commit.h | 11 ++++--- convert.c | 6 ++-- diffcore-rename.c | 2 +- dir.c | 31 +++++++++--------- dir.h | 2 +- http-push.c | 4 +++ log-tree.c | 2 +- match-trees.c | 40 +++++++++++------------ merge-recursive.c | 5 +-- notes-cache.c | 8 ++--- notes-merge.c | 9 +++--- notes-utils.c | 9 +++--- notes-utils.h | 3 +- notes.c | 63 ++++++++++++++++++------------------ notes.h | 29 ++++++++++------- read-cache.c | 6 ++-- sha1_file.c | 51 +++++++++++++++-------------- t/helper/test-dump-untracked-cache.c | 4 +-- 37 files changed, 217 insertions(+), 202 deletions(-)
Signature · 1 line
2.14.3
PATCH 1/11 http-push: improve error log
When git push fails due to server-side WebDAV error, it's not easy to point to the main culprit. Additional information about exact cURL error and HTTP server response is helpful for debugging purpose.
New error log helped me pinpoint failing test t5540-http-push-webdav to a missing Apache dependency in Fedora 27:
https://bugzilla.redhat.com/show_bug.cgi?id=1491151
--- http-push.c | 4 ++++ 1 file changed, 4 insertions(+)
http-push.c +4 -0
@@ -915,6 +915,10 @@ static struct remote_lock *lock_remote(const char *path, long timeout) lock->timeout =-1 ; }XML_ParserFree (parser); + }else { +fprintf (stderr, +"error: curl result=%d, HTTP code=%ld\n" , + results.curl_result, results.http_code); } }else {fprintf (stderr,"Unable to start LOCK request\n" );
Signature · 1 line
2.14.3
PATCH 2/11 clang-format: adjust penalty for return type line break
In reply to Patryk ObaraThe penalty of 5 makes clang-format very eager to put even short type declarations (e.g. "extern int") into a separate line, even when breaking parameters list is sufficient.
--- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.clang-format +1 -1
@@ -163,7 +163,7 @@ PenaltyBreakComment: 10 PenaltyBreakFirstLessLess: 0 PenaltyBreakString: 10 PenaltyExcessCharacter: 100 -PenaltyReturnTypeOnItsOwnLine: 5 +PenaltyReturnTypeOnItsOwnLine: 60 # Don't sort #include's SortIncludes: false
Signature · 1 line
2.14.3
PATCH 3/11 sha1_file: convert pretend_sha1_file to object_id
In reply to Patryk ObaraConvert the declaration and definition of pretend_sha1_file to use struct object_id and adjust all usages of this function.
--- blame.c | 2 +- cache.h | 3 ++- sha1_file.c | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-)
blame.c +1 -1
@@ -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_sha1_file (buf.buf, buf.len,OBJ_BLOB , &origin->blob_oid);/* * Read the current index, replace the path entry with
cache.h +2 -1
@@ -1241,7 +1241,8 @@ 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 pretend_sha1_file (void *,unsigned long ,enum object_type , +struct object_id *oid);extern int force_object_loose (const unsigned char *sha1,time_t mtime);extern int git_open_cloexec (const char *name,int flags);#define git_open (name) git_open_cloexec(name, O_RDONLY)
sha1_file.c +4 -4
@@ -1313,12 +1313,12 @@ static void *read_object(const unsigned char *sha1, enum object_type *type, }int pretend_sha1_file (void *buf,unsigned long len,enum object_type type, -unsigned char *sha1) +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_sha1_file (buf, len,typename (type), oid->hash); +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++];
@@ -1326,7 +1326,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 ; }
Signature · 1 line
2.14.3
PATCH 4/11 dir: convert struct sha1_stat to use object_id
In reply to Patryk ObaraConvert the declaration of struct sha1_stat. Adjust all usages of this struct and replace hash{clr,cmp,cpy} with oid{clr,cmp,cpy} wherever possible.
Remove macro EMPTY_BLOB_SHA1_BIN, as it's no longer used.
--- cache.h | 2 -- dir.c | 31 ++++++++++++++++--------------- dir.h | 2 +- t/helper/test-dump-untracked-cache.c | 4 ++-- 4 files changed, 19 insertions(+), 20 deletions(-)
cache.h +0 -2
@@ -1047,8 +1047,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) {
dir.c +16 -15
@@ -253,7 +253,7 @@ static int do_read_blob(const struct object_id *oid,if (sha1_stat) {memset (&sha1_stat->stat,0 ,sizeof (sha1_stat->stat)); -hashcpy (sha1_stat->sha1, oid->hash); +oidcpy (&sha1_stat->oid, oid); }if (sz ==0 ) {
@@ -823,7 +823,7 @@ static int add_excludes(const char *fname, const char *base, int baselen,if (size ==0 ) {if (sha1_stat) {fill_stat_data (&sha1_stat->stat, &st); -hashcpy (sha1_stat->sha1,EMPTY_BLOB_SHA1_BIN ); +oidcpy (&sha1_stat->oid, &empty_blob_oid); sha1_stat->valid =1 ; }close (fd);
@@ -847,10 +847,11 @@ static int add_excludes(const char *fname, const char *base, int baselen, !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 (&sha1_stat->oid, + &istate->cache[pos]->oid); else - hash_sha1_file(buf, size, "blob", sha1_stat->sha1); + hash_sha1_file(buf, size, "blob", + sha1_stat->oid.hash);fill_stat_data (&sha1_stat->stat, &st); sha1_stat->valid =1 ; }
@@ -1223,7 +1224,7 @@ static void prep_exclude(struct dir_struct *dir, }/* Try to read per-directory file */ -hashclr (sha1_stat.sha1); +oidclr (&sha1_stat.oid); sha1_stat.valid =0 ; if (dir->exclude_per_dir &&/*
@@ -1269,9 +1270,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 (sha1_stat.oid.hash, untracked->exclude_sha1)) {invalidate_gitignore (dir->untracked, untracked); -hashcpy (untracked->exclude_sha1, sha1_stat.sha1); +hashcpy (untracked->exclude_sha1, sha1_stat.oid.hash); } dir->exclude_stack = stk; current = stk->baselen;
@@ -2228,13 +2229,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 +2639,8 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untraFLEX_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);
@@ -2821,7 +2822,7 @@ static void load_sha1_stat(struct sha1_stat *sha1_stat, const unsigned char *sha1) {stat_data_from_disk (&sha1_stat->stat, data); -hashcpy (sha1_stat->sha1, sha1); +hashcpy (sha1_stat->oid.hash, sha1); sha1_stat->valid =1 ; }
dir.h +1 -1
@@ -76,7 +76,7 @@ struct exclude_list_group {struct sha1_stat {struct stat_data stat; -unsigned char sha1[20 ]; +struct object_id oid;int valid; };
t/helper/test-dump-untracked-cache.c +2 -2
@@ -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)
Signature · 1 line
2.14.3
PATCH 5/11 sha1_file: convert hash_sha1_file to object_id
In reply to Patryk ObaraConvert the declaration and definition of hash_sha1_file to use struct object_id and adjust all function calls.
--- apply.c | 4 ++-- builtin/index-pack.c | 3 +-- builtin/replace.c | 2 +- builtin/unpack-objects.c | 2 +- cache-tree.c | 11 +++++------ cache.h | 3 ++- convert.c | 6 +++--- diffcore-rename.c | 2 +- dir.c | 2 +- log-tree.c | 2 +- sha1_file.c | 22 +++++++++++----------- 11 files changed, 29 insertions(+), 30 deletions(-)
apply.c +2 -2
@@ -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_sha1_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_sha1_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));
builtin/index-pack.c +1 -2
@@ -959,8 +959,7 @@ static void resolve_delta(struct object_entry *delta_obj,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); +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 ();
builtin/replace.c +1 -1
@@ -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_sha1_file (extra->value, extra->len,typename (OBJ_TAG ), &tag_oid); tag =lookup_tag (&tag_oid);if (!tag)die (_ ("bad mergetag in commit '%s'" ), ref);
builtin/unpack-objects.c +1 -1
@@ -258,7 +258,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_sha1_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);
cache-tree.c +5 -6
@@ -400,15 +400,14 @@ 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_sha1_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); +hash_sha1_file (buffer.buf, buffer.len, tree_type, &it->oid);else if (write_sha1_file (buffer.buf, buffer.len, tree_type, it->oid.hash)) {strbuf_release (&buffer);return -1 ;
cache.h +2 -1
@@ -1236,7 +1236,8 @@ 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 hash_sha1_file (const void *buf,unsigned long len,const char *type, +struct object_id *oid);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,
convert.c +3 -3
@@ -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_sha1_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_add (buf,sha1_to_hex (oid.hash),GIT_SHA1_HEXSZ );strbuf_addstr (buf," $" ); }strbuf_add (buf, src, len);
diffcore-rename.c +1 -1
@@ -261,7 +261,7 @@ static unsigned int hash_filespec(struct diff_filespec *filespec)if (diff_populate_filespec (filespec,0 ))return 0 ;hash_sha1_file (filespec->data, filespec->size,"blob" , - filespec->oid.hash); + &filespec->oid); }return sha1hash (filespec->oid.hash); }
dir.c +1 -1
@@ -851,7 +851,7 @@ static int add_excludes(const char *fname, const char *base, int baselen, &istate->cache[pos]->oid); else hash_sha1_file(buf, size, "blob", - sha1_stat->oid.hash); + &sha1_stat->oid);fill_stat_data (&sha1_stat->stat, &st); sha1_stat->valid =1 ; }
log-tree.c +1 -1
@@ -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_sha1_file (extra->value, extra->len,typename (OBJ_TAG ), &oid); tag =lookup_tag (&oid);if (!tag)return ;/* error message already given */
sha1_file.c +11 -11
@@ -788,7 +788,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;
@@ -796,8 +796,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_sha1_file (map, size, type, &real_oid); +return hashcmp (sha1, real_oid.hash) ?-1 :0 ; } st =open_istream (sha1, &obj_type, &size,NULL );
@@ -822,9 +822,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)
@@ -1317,7 +1317,7 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type, {struct cached_object *co; -hash_sha1_file (buf, len,typename (type), oid->hash); +hash_sha1_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);
@@ -1486,11 +1486,11 @@ static int write_buffer(int fd, const void *buf, size_t len) }int hash_sha1_file (const void *buf,unsigned long len,const char *type, -unsigned char *sha1) +struct object_id *oid) {char hdr[32 ];int hdrlen =sizeof (hdr); -write_sha1_file_prepare (buf, len, type, sha1, hdr, &hdrlen); +write_sha1_file_prepare (buf, len, type, oid->hash, hdr, &hdrlen);return 0 ; }
@@ -1769,7 +1769,7 @@ 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);else - ret =hash_sha1_file (buf, size,typename (type), oid->hash); + ret =hash_sha1_file (buf, size,typename (type), oid);if (re_allocated)free (buf);return ret;
@@ -1793,7 +1793,7 @@ static int index_stream_convert_blob(struct object_id *oid, int fd, oid->hash); else ret =hash_sha1_file (sbuf.buf, sbuf.len,typename (OBJ_BLOB ), - oid->hash); + oid);strbuf_release (&sbuf);return ret; }
@@ -1907,7 +1907,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigneif (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); +hash_sha1_file (sb.buf, sb.len, blob_type, oid);else if (write_sha1_file (sb.buf, sb.len, blob_type, oid->hash)) rc =error ("%s: failed to insert into database" , path);strbuf_release (&sb);
Signature · 1 line
2.14.3
PATCH 6/11 cache: clear whole hash buffer with oidclr
In reply to Patryk ObaraAs long as GIT_SHA1_RAWSZ is equal to GIT_MAX_RAWSZ there's no problem, but when new hashing algorithm will be in place this memset will clear only 20-byte prefix of hash buffer.
Alternatively, hashclr implementation could be adjusted, but this function is almost removed from codebase already. Separate implementation of oidclr prevents potential buffer overrun in case someone incorrectly used hashclr on object_id in future.
--- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cache.h +1 -1
@@ -1029,7 +1029,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 ); }
Signature · 1 line
2.14.3
PATCH 7/11 match-trees: convert splice_tree to object_id
In reply to Patryk ObaraConvert the definition of static recursive splice_tree function to use struct object_id and adjust single caller.
--- match-trees.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-)
match-trees.c +20 -22
@@ -161,19 +161,17 @@ 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". */ -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 *hash1,const char *prefix, +const struct object_id *hash2,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 (hash1->hash, &type, &sz);if (!buf) -die ("cannot read tree %s" ,sha1_to_hex (hash1)); +die ("cannot read tree %s" ,oid_to_hex (hash1));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 (hash1)); + 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 (hash1));if (*subpath) { - status =splice_tree (rewrite_here, subpath, hash2, subtree); + status =splice_tree (rewrite_here, subpath, hash2, &subtree);if (status)return status; - rewrite_with = subtree; - } -else + rewrite_with = &subtree; + }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_sha1_file (buf, sz, tree_type, result->hash);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
Signature · 1 line
2.14.3
PATCH 8/11 commit: convert commit_tree* to object_id
In reply to Patryk ObaraConvert the definitions and declarations of commit_tree and commit_tree_extended to use struct object_id and adjust all usages of these functions.
--- builtin/am.c | 4 ++-- builtin/commit-tree.c | 4 ++-- builtin/commit.c | 5 +++-- builtin/merge.c | 8 ++++---- commit.c | 15 +++++++-------- commit.h | 11 ++++++----- notes-cache.c | 4 ++-- notes-merge.c | 9 ++++----- notes-utils.c | 7 ++++--- notes-utils.h | 3 ++- 10 files changed, 36 insertions(+), 34 deletions(-)
builtin/am.c +2 -2
@@ -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" );
builtin/commit-tree.c +2 -2
@@ -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 ; }
builtin/commit.c +3 -2
@@ -1792,8 +1792,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" )); }
builtin/merge.c +4 -4
@@ -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);
commit.c +7 -8
@@ -1395,9 +1395,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;
@@ -1526,8 +1525,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) {
@@ -1535,7 +1534,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." );
@@ -1544,7 +1543,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
@@ -1583,7 +1582,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_sha1_file (buffer.buf, buffer.len, commit_type, ret->hash); out:strbuf_release (&buffer);return result;
commit.h +6 -5
@@ -263,14 +263,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 **);
notes-cache.c +2 -2
@@ -56,8 +56,8 @@ int notes_cache_write(struct notes_cache *c)if (write_notes_tree (&c->tree, tree_oid.hash))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 )
notes-merge.c +4 -5
@@ -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",
notes-utils.c +4 -3
@@ -6,7 +6,7 @@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;
@@ -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 );
notes-utils.h +2 -1
@@ -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);
Signature · 1 line
2.14.3
PATCH 9/11 notes: convert combine_notes_* to object_id
In reply to Patryk ObaraConvert the definition and declarations of combine_notes_* functions to struct object_id and adjust usage of these functions.
--- notes.c | 46 +++++++++++++++++++++++----------------------- notes.h | 25 +++++++++++++++---------- 2 files changed, 38 insertions(+), 33 deletions(-)
notes.c +23 -23
@@ -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);
@@ -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_sha1_file (buf, buf_len, blob_type, cur_oid->hash);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_sha1_file (buf.buf, buf.len, blob_type, cur_oid->hash); out:strbuf_release (&buf);
notes.h +15 -10
@@ -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
Signature · 1 line
2.14.3
PATCH 10/11 notes: convert write_notes_tree to object_id
In reply to Patryk ObaraConvert the definition and declaration of write_notes_tree to struct object_id and adjust usage of this function.
Additionally, improve style of small part of this function, as old formatting made it hard to understand at glance what this part of code is doing.
--- notes-cache.c | 2 +- notes-utils.c | 2 +- notes.c | 16 +++++++++------- notes.h | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-)
notes-cache.c +1 -1
@@ -54,7 +54,7 @@ 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,NULL , &commit_oid,NULL ,NULL ) <0 )
notes-utils.c +1 -1
@@ -12,7 +12,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,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) {
notes.c +9 -7
@@ -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,13 @@ 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_sha1_file (root.buf.buf, root.buf.len, tree_type, + result->hash);strbuf_release (&root.buf);return ret; }
notes.h +2 -2
@@ -217,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. *
@@ -225,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
Signature · 1 line
2.14.3
PATCH 11/11 sha1_file: convert write_sha1_file to object_id
In reply to Patryk ObaraConvert the definition and declaration of write_sha1_file to struct object_id and adjust usage of this function.
This commit also converts static function write_sha1_file_prepare, as it is closely related.
Replace sha1_to_hex, hashcpy and hashclr with their oid equivalents wherever possible.
--- apply.c | 8 ++++---- builtin/checkout.c | 3 +-- builtin/mktag.c | 6 +++--- builtin/mktree.c | 10 +++++----- builtin/notes.c | 8 ++++---- builtin/receive-pack.c | 11 ++++++----- builtin/replace.c | 2 +- builtin/tag.c | 2 +- builtin/unpack-objects.c | 9 ++++++--- cache-tree.c | 2 +- cache.h | 3 ++- commit.c | 2 +- match-trees.c | 2 +- merge-recursive.c | 5 +++-- notes-cache.c | 2 +- notes.c | 9 ++++----- read-cache.c | 6 +++--- sha1_file.c | 25 +++++++++++++------------ 18 files changed, 60 insertions(+), 55 deletions(-)
apply.c +4 -4
@@ -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_sha1_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_sha1_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_sha1_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_sha1_file (buf, size, blob_type, &ce->oid) <0 ) {free (ce);return error (_ ("unable to create backing store " "for newly created file %s" ), path);
builtin/checkout.c +1 -2
@@ -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_sha1_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 );
builtin/mktag.c +3 -3
@@ -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_sha1_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 ; }
builtin/mktree.c +5 -5
@@ -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_sha1_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_missint 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 */
builtin/notes.c +4 -4
@@ -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_sha1_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 ]);
builtin/receive-pack.c +6 -5
@@ -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_sha1_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",
builtin/replace.c +1 -1
@@ -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_sha1_file (buf.buf, buf.len, commit_type, &new))die (_ ("could not write replacement commit for: '%s'" ), old_ref);strbuf_release (&buf);
builtin/tag.c +1 -1
@@ -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_sha1_file (buf->buf, buf->len, tag_type, result) <0 )return error (_ ("unable to write tag file" ));return 0 ; }
builtin/unpack-objects.c +6 -3
@@ -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_sha1_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_sha1_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_sha1_file (buf, size,typename (type), + &obj_list[nr].oid) <0 )die ("failed to write object" );added_object (nr, type, buf, size);free (buf);
cache-tree.c +1 -1
@@ -408,7 +408,7 @@ static int update_one(struct cache_tree *it, to_invalidate =1 ; }else if (dryrun)hash_sha1_file (buffer.buf, buffer.len, tree_type, &it->oid); -else if (write_sha1_file (buffer.buf, buffer.len, tree_type, it->oid.hash)) { +else if (write_sha1_file (buffer.buf, buffer.len, tree_type, &it->oid)) {strbuf_release (&buffer);return -1 ; }
cache.h +2 -1
@@ -1238,7 +1238,8 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *shextern int sha1_object_info (const unsigned char *,unsigned long *);extern int hash_sha1_file (const void *buf,unsigned long len,const char *type,struct object_id *oid); -extern int write_sha1_file (const void *buf,unsigned long len,const char *type,unsigned char *return_sha1); +extern int write_sha1_file (const void *buf,unsigned long len,const char *type, +struct object_id *oid);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 ,struct object_id *oid);
commit.c +1 -1
@@ -1582,7 +1582,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->hash); + result =write_sha1_file (buffer.buf, buffer.len, commit_type, ret); out:strbuf_release (&buffer);return result;
match-trees.c +1 -1
@@ -214,7 +214,7 @@ static int splice_tree(const struct object_id *hash1, const char *prefix, rewrite_with = hash2; }oidcpy (rewrite_here, rewrite_with); - status =write_sha1_file (buf, sz, tree_type, result->hash); + status =write_sha1_file (buf, sz, tree_type, result);free (buf);return status; }
merge-recursive.c +3 -2
@@ -1009,8 +1009,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_sha1_file (result_buf.ptr, result_buf.size, + blob_type, &result->oid)) ret =err (o,_ ("Unable to add %s to database" ), a->path);
notes-cache.c +1 -1
@@ -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_sha1_file (data, size,"blob" , &value_oid) <0 )return -1 ;return add_note (&c->tree, key_oid, &value_oid,NULL ); }
notes.c +4 -5
@@ -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_sha1_file (n->buf.buf, n->buf.len, tree_type, &s);if (ret)return ret;strbuf_release (&n->buf);
@@ -825,7 +825,7 @@ int combine_notes_concatenate(struct object_id *cur_oid,free (new_msg);/* create a new blob object from buf */ - ret =write_sha1_file (buf, buf_len, blob_type, cur_oid->hash); + ret =write_sha1_file (buf, buf_len, blob_type, cur_oid);free (buf);return ret; }
@@ -905,7 +905,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid, string_list_join_lines_helper, &buf)) goto out; - ret =write_sha1_file (buf.buf, buf.len, blob_type, cur_oid->hash); + ret =write_sha1_file (buf.buf, buf.len, blob_type, cur_oid); out:strbuf_release (&buf);
@@ -1147,8 +1147,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result) 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_sha1_file (root.buf.buf, root.buf.len, tree_type, - result->hash); +write_sha1_file (root.buf.buf, root.buf.len, tree_type, result);strbuf_release (&root.buf);return ret; }
read-cache.c +3 -3
@@ -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_sha1_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)
sha1_file.c +13 -12
@@ -1420,8 +1420,8 @@ 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) +const char *type,struct object_id *oid, +char *hdr,int *hdrlen) {git_SHA_CTX c;
@@ -1432,7 +1432,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); }/*
@@ -1490,7 +1490,7 @@ int hash_sha1_file(const void *buf, unsigned long len, const char *type, {char hdr[32 ];int hdrlen =sizeof (hdr); -write_sha1_file_prepare (buf, len, type, oid->hash, hdr, &hdrlen); +write_sha1_file_prepare (buf, len, type, oid, hdr, &hdrlen);return 0 ; }
@@ -1633,7 +1633,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_sha1_file (const void *buf,unsigned long len,const char *type, +struct object_id *oid) {char hdr[32 ];int hdrlen =sizeof (hdr);
@@ -1641,10 +1642,10 @@ 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_sha1_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->hash, hdr, hdrlen, buf, len,0 ); } int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type,
@@ -1656,7 +1657,7 @@ 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_sha1_file_prepare (buf, len, type, oid, header, &hdrlen);if (!(flags &HASH_WRITE_OBJECT )) goto cleanup;
@@ -1767,7 +1768,7 @@ 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_sha1_file (buf, size,typename (type), oid);else ret =hash_sha1_file (buf, size,typename (type), oid);if (re_allocated)
@@ -1790,7 +1791,7 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,if (write_object) ret =write_sha1_file (sbuf.buf, sbuf.len,typename (OBJ_BLOB ), - oid->hash); + oid);else ret =hash_sha1_file (sbuf.buf, sbuf.len,typename (OBJ_BLOB ), oid);
@@ -1908,7 +1909,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsignereturn error_errno ("readlink(\"%s\")" , path);if (!(flags &HASH_WRITE_OBJECT ))hash_sha1_file (sb.buf, sb.len, blob_type, oid); -else if (write_sha1_file (sb.buf, sb.len, blob_type, oid->hash)) +else if (write_sha1_file (sb.buf, sb.len, blob_type, oid)) rc =error ("%s: failed to insert into database" , path);strbuf_release (&sb);break ;
Signature · 1 line
2.14.3
Re: [PATCH 11/11] sha1_file: convert write_sha1_file to object_id
sha1_file.c void *read_object_with_reference(const unsigned char *sha1, · line 1424
Quoted 12 lines · Patryk Obara
sha1_file.c +2
-2@@ -1420,8 +1420,8 @@ 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) +const char *type,struct object_id *oid, +char *hdr,int *hdrlen)
It looks like the indentation has changed here. Was that intentional?
Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US https://www.crustytoothpaste.net/~bmc | My opinion only OpenPGP: https://keybase.io/bk2204
Re: [PATCH 11/11] sha1_file: convert write_sha1_file to object_id
Quoted 8 lines · brian m. carlson
Quoted 7 lines · Patryk Obara
sha1_file.c +0
-0@@ -1420,8 +1420,8 @@ void *read_object_with_reference(const unsigned char *sha1, }
Quoted 7 lines
sha1_file.c void *read_object_with_reference(const unsigned char *sha1, · line 1424
Quoted 5 lines
sha1_file.c +2
-2static void write_sha1_file_prepare (const void *buf,unsigned long len, -const char *type,unsigned char *sha1, -char *hdr,int *hdrlen) +const char *type,struct object_id *oid, +char *hdr,int *hdrlen)It looks like the indentation has changed here. Was that intentional?
Yes. After every commit, I am running clang-format on lines, that I touch to verify formatting and
decide if I want to include formatting fixes or not. In this case, function parameters were
aligned using spaces only (which is arguably hard to see in the mail)
- now they are aligned to first
parameter (at least in my editor and in gitk :)).
Signature · 2 lines
| ← Ceci n'est pas une pipe Patryk Obara
Quoted 4 lines · On Thu, 18 Jan 2018 15:50:52 +0100 Patryk Obara <[email protected]> wrote:
Patch 1 is not directly related to
object_idconversions but helped with debugging t5540, which kept failing on master for me (spoiler: it was Fedora fault). It helps with debugging of failing git-push over HTTP in case of internal server error, so I think it might be worthwhile.
This patch seems reasonable to me - it is a little strange that, currently, an error message is printed upon an XML error and upon failure of start_active_slot(), but not when the slot cannot be run. This patch fills the gap.
Quoted 2 lines
Patch 2 is a small adjustment to .clang-format, which prevents unnecessary line breaks after function return type.
I'm not very familiar with clang-format, so no comment from me here.
Quoted 1 line
Patch 6 is a tiny fix in oidclr function.
Ah, good catch. I would write the memset line as "memset(oid, 0, sizeof(*oid))", but the existing one is fine too.
Quoted 2 lines
All other patches are progressive conversions to struct
object_idwith some formatting fixes sprinkled in. These should be somewhat uncontroversial, I hope.
I've looked at those and they appear to be obviously correct.
Quoted 3 lines · Patryk Obara
* brian m. carlson implemented vtable for hash algorithm selection and pushed the repository format front - thanks to him it's now quite easy to experimentally replace hashing functions and, e.g. do some performance testing.
Good, I'm glad this has been helpful.
Quoted 7 lines
Patch 1 is not directly related to
object_idconversions but helped with debugging t5540, which kept failing on master for me (spoiler: it was Fedora fault). It helps with debugging of failing git-push over HTTP in case of internal server error, so I think it might be worthwhile.Patch 2 is a small adjustment to .clang-format, which prevents unnecessary line breaks after function return type.
I have no strong opinions about these two patches, but didn't see anything that looked problematic. Better debugging is always nice.
Quoted 1 line
Patch 6 is a tiny fix in oidclr function.
I think this is a good direction to go in.
Quoted 2 lines
All other patches are progressive conversions to struct
object_idwith some formatting fixes sprinkled in. These should be somewhat uncontroversial, I hope.
Overall, I like the direction this series is going.
When I've made changes to the sha1_file functions, I've traditionally moved them away from using "sha1_file" to "object_file" to ensure that we make it a bit more obvious that they handle object_id structs and aren't limited to SHA-1. For consistency, it might be nice to make that change.
Other than that and the question I had about the formatting, I think the series looks good.
Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US https://www.crustytoothpaste.net/~bmc | My opinion only OpenPGP: https://keybase.io/bk2204
Quoted 5 lines · brian m. carlson
When I've made changes to the
sha1_filefunctions, I've traditionally moved them away from using "sha1_file" to "object_file" to ensure that we make it a bit more obvious that they handleobject_idstructs and aren't limited to SHA-1. For consistency, it might be nice to make that change.
I will address this in V2 and add several more conversions, that are sufficient to make git hash-object -w work with sha-256 (which I will send as separate RFC thread).
I started converting functions needed for cat-file, but number of places, that still needs to be touched up grew quite rapidly, so it'll take some time :).
Signature · 2 lines
| ← Ceci n'est pas une pipe Patryk Obara
v2 cover Some fixes and bunch of object_id conversions
In reply to Patryk ObaraCompared to v1:
Following brian's suggestion I renamed following functions and struct names to indicate, that they are no longer intended for sha1 algorithm only:
struct sha1_stat -> struct oid_stat pretend_sha1_file -> pretend_object_file write_sha1_file -> write_object_file hash_sha1_file -> hash_object_file
hash_sha1_file_literally -> hash_object_file_literally
Added two more patches converting some more functions to struct object_id and one with pure function rename.
Patryk Obara (14):
http-push: improve error log
clang-format: adjust penalty for return type line break
sha1_file: convert pretend_sha1_file to object_id
dir: convert struct sha1_stat to use object_id
sha1_file: convert hash_sha1_file to object_id
cache: clear whole hash buffer with oidclr
match-trees: convert splice_tree to object_id
commit: convert commit_tree* to object_id
notes: convert combine_notes_* to object_id
notes: convert write_notes_tree to object_id
sha1_file: convert write_sha1_file to object_id
sha1_file: convert force_object_loose to object_id
sha1_file: convert write_loose_object to object_id
sha1_file: rename hash_sha1_file_literally
.clang-format | 2 +- Documentation/technical/api-object-access.txt | 2 +- apply.c | 12 ++-- blame.c | 2 +- builtin/am.c | 4 +- builtin/checkout.c | 3 +- builtin/commit-tree.c | 4 +- builtin/commit.c | 5 +- builtin/hash-object.c | 3 +- builtin/index-pack.c | 5 +- builtin/merge.c | 8 +-- builtin/mktag.c | 6 +- builtin/mktree.c | 10 +-- builtin/notes.c | 8 +-- builtin/pack-objects.c | 2 +- builtin/receive-pack.c | 11 +-- builtin/replace.c | 4 +- builtin/tag.c | 2 +- builtin/unpack-objects.c | 11 +-- cache-tree.c | 16 ++--- cache.h | 25 ++++--- commit.c | 15 ++-- commit.h | 11 +-- convert.c | 6 +- diffcore-rename.c | 4 +- dir.c | 56 +++++++-------- dir.h | 12 ++-- http-push.c | 4 ++ log-tree.c | 2 +- match-trees.c | 42 ++++++----- merge-recursive.c | 5 +- notes-cache.c | 8 +-- notes-merge.c | 9 ++- notes-utils.c | 9 +-- notes-utils.h | 3 +- notes.c | 63 ++++++++-------- notes.h | 29 ++++---- read-cache.c | 6 +- sha1_file.c | 100 ++++++++++++++------------ t/helper/test-dump-untracked-cache.c | 4 +- 40 files changed, 279 insertions(+), 254 deletions(-)
base-commit: 59c276cf4da0705064c32c9dba54baefa282ea55
Signature · 1 line
2.14.3
PATCH v2 1/14 http-push: improve error log
When git push fails due to server-side WebDAV error, it's not easy to point to the main culprit. Additional information about exact cURL error and HTTP server response is helpful for debugging purpose.
New error log helped me pinpoint failing test t5540-http-push-webdav to a missing Apache dependency in Fedora 27:
https://bugzilla.redhat.com/show_bug.cgi?id=1491151
--- http-push.c | 4 ++++ 1 file changed, 4 insertions(+)
http-push.c +4 -0
@@ -915,6 +915,10 @@ static struct remote_lock *lock_remote(const char *path, long timeout) lock->timeout =-1 ; }XML_ParserFree (parser); + }else { +fprintf (stderr, +"error: curl result=%d, HTTP code=%ld\n" , + results.curl_result, results.http_code); } }else {fprintf (stderr,"Unable to start LOCK request\n" );
Signature · 1 line
2.14.3
PATCH v2 2/14 clang-format: adjust penalty for return type line break
In reply to Patryk ObaraThe penalty of 5 makes clang-format very eager to put even short type declarations (e.g. "extern int") into a separate line, even when breaking parameters list is sufficient.
--- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.clang-format +1 -1
@@ -163,7 +163,7 @@ PenaltyBreakComment: 10 PenaltyBreakFirstLessLess: 0 PenaltyBreakString: 10 PenaltyExcessCharacter: 100 -PenaltyReturnTypeOnItsOwnLine: 5 +PenaltyReturnTypeOnItsOwnLine: 60 # Don't sort #include's SortIncludes: false
Signature · 1 line
2.14.3
PATCH v2 3/14 sha1_file: convert pretend_sha1_file to object_id
In reply to Patryk ObaraConvert the declaration and definition of pretend_sha1_file to use struct object_id and adjust all usages of this function. Rename it to pretend_object_file.
--- Documentation/technical/api-object-access.txt | 2 +- blame.c | 2 +- cache.h | 5 ++++- sha1_file.c | 10 +++++----- 4 files changed, 11 insertions(+), 8 deletions(-)
Documentation/technical/api-object-access.txt +1 -1
@@ -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
blame.c +1 -1
@@ -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
cache.h +4 -1
@@ -1241,7 +1241,10 @@ 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 pretend_object_file (void *,unsigned long ,enum object_type , +struct object_id *oid); +extern int force_object_loose (const unsigned char *sha1,time_t mtime);extern int git_open_cloexec (const char *name,int flags);#define git_open (name) git_open_cloexec(name, O_RDONLY)
sha1_file.c +5 -5
@@ -1312,13 +1312,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_sha1_file (buf, len,typename (type), oid->hash); +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++];
@@ -1326,7 +1326,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 ; }
Signature · 1 line
2.14.3
PATCH v2 4/14 dir: convert struct sha1_stat to use object_id
In reply to Patryk ObaraConvert the declaration of struct sha1_stat. Adjust all usages of this struct and replace hash{clr,cmp,cpy} with oid{clr,cmp,cpy} wherever possible. Rename it to struct oid_stat.
Remove macro EMPTY_BLOB_SHA1_BIN, as it's no longer used.
--- cache.h | 2 -- dir.c | 56 +++++++++++++++++------------------- dir.h | 12 ++++---- t/helper/test-dump-untracked-cache.c | 4 +-- 4 files changed, 34 insertions(+), 40 deletions(-)
cache.h +0 -2
@@ -1047,8 +1047,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) {
dir.c +26 -30
141 lines not on this page · raw message
dir.h +6 -6
@@ -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; };
t/helper/test-dump-untracked-cache.c +2 -2
@@ -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)
Signature · 1 line
2.14.3
PATCH v2 5/14 sha1_file: convert hash_sha1_file to object_id
In reply to Patryk ObaraConvert the declaration and definition of hash_sha1_file to use struct object_id and adjust all function calls.
Rename this function to hash_object_file.
--- apply.c | 4 ++-- builtin/index-pack.c | 5 ++--- builtin/replace.c | 2 +- builtin/unpack-objects.c | 2 +- cache-tree.c | 11 +++++------ cache.h | 5 ++++- convert.c | 6 +++--- diffcore-rename.c | 4 ++-- dir.c | 4 ++-- log-tree.c | 2 +- sha1_file.c | 26 +++++++++++++------------- 11 files changed, 36 insertions(+), 35 deletions(-)
apply.c +2 -2
@@ -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));
builtin/index-pack.c +2 -3
@@ -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 ();
builtin/replace.c +1 -1
@@ -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);
builtin/unpack-objects.c +1 -1
@@ -258,7 +258,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);
cache-tree.c +5 -6
@@ -400,15 +400,14 @@ 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); +hash_object_file (buffer.buf, buffer.len, tree_type, &it->oid);else if (write_sha1_file (buffer.buf, buffer.len, tree_type, it->oid.hash)) {strbuf_release (&buffer);return -1 ;
cache.h +4 -1
@@ -1236,7 +1236,10 @@ 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 hash_object_file (const void *buf,unsigned long len, +const char *type,struct object_id *oid); +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);
convert.c +3 -3
@@ -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_add (buf,sha1_to_hex (oid.hash),GIT_SHA1_HEXSZ );strbuf_addstr (buf," $" ); }strbuf_add (buf, src, len);
diffcore-rename.c +2 -2
@@ -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); }
dir.c +2 -2
@@ -846,8 +846,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,oidcpy (&sha1_stat->oid, &istate->cache[pos]->oid); else - hash_sha1_file(buf, size, "blob", - sha1_stat->oid.hash); + hash_object_file(buf, size, "blob", + &sha1_stat->oid);fill_stat_data (&sha1_stat->stat, &st); sha1_stat->valid =1 ; }
log-tree.c +1 -1
@@ -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 */
sha1_file.c +13 -13
@@ -788,7 +788,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;
@@ -796,8 +796,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 );
@@ -822,9 +822,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)
@@ -1317,7 +1317,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type, {struct cached_object *co; -hash_sha1_file (buf, len,typename (type), oid->hash); +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);
@@ -1485,12 +1485,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_sha1_file_prepare (buf, len, type, oid->hash, hdr, &hdrlen);return 0 ; }
@@ -1769,7 +1769,7 @@ 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);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;
@@ -1792,8 +1792,8 @@ static int index_stream_convert_blob(struct object_id *oid, int fd, ret =write_sha1_file (sbuf.buf, sbuf.len,typename (OBJ_BLOB ), oid->hash); 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; }
@@ -1907,7 +1907,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigneif (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); +hash_object_file (sb.buf, sb.len, blob_type, oid);else if (write_sha1_file (sb.buf, sb.len, blob_type, oid->hash)) rc =error ("%s: failed to insert into database" , path);strbuf_release (&sb);
Signature · 1 line
2.14.3
Re: [PATCH v2 05/14] sha1_file: convert hash_sha1_file to object_id
convert.c static int ident_to_worktree(const char *path, const char *src, size_t len, · line 972
Quoted 6 lines · Patryk Obara
convert.c +1
-1@@ -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_add (buf,sha1_to_hex (oid.hash),GIT_SHA1_HEXSZ );
oid_to_hex()?
--
Duy
Re: [PATCH v2 05/14] sha1_file: convert hash_sha1_file to object_id
Quoted 9 lines · Duy Nguyen
convert.c static int ident_to_worktree(const char *path, const char *src, size_t len, · line 972
Quoted 6 lines · Patryk Obara
convert.c +1
-1@@ -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_add (buf,sha1_to_hex (oid.hash),GIT_SHA1_HEXSZ );
oid_to_hex()?
I didn't do it originally because the size of hash is explicitly passed as the third parameter.
I should probably replace this line with:
strbuf_addstr(buf, oid_to_hex(&oid));
... since a hex representation is correctly 0-delimited anyway. Will include in v3 unless there'll be some other suggestion :)
Signature · 2 lines
| ← Ceci n'est pas une pipe Patryk Obara
Re: [PATCH v2 05/14] sha1_file: convert hash_sha1_file to object_id
Quoted 11 lines · Patryk Obara
Quoted 9 lines · Duy Nguyen
convert.c static int ident_to_worktree(const char *path, const char *src, size_t len, · line 972
Quoted 6 lines · Patryk Obara
convert.c +1
-1@@ -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_add (buf,sha1_to_hex (oid.hash),GIT_SHA1_HEXSZ );
oid_to_hex()?
Quoted 2 lines
I didn't do it originally because the size of hash is explicitly passed as the third parameter.
Aha! I didn't see that.
Quoted 5 lines
I should probably replace this line with:
strbuf_addstr(buf, oid_to_hex(&oid));... since a hex representation is correctly 0-delimited anyway.
Yeah I think that's a good idea. This 40 came from 3fed15f568 (Add 'ident' conversion. - 2007-04-21). Back then memcpy was used and 40 made sense. The conversion to strbuf should have used strbuf_addstr() as you suggested, unless there's performance concerns, but I don't think there is any.
Signature · 1 line
Duy
PATCH v2 6/14 cache: clear whole hash buffer with oidclr
In reply to Patryk ObaraAs long as GIT_SHA1_RAWSZ is equal to GIT_MAX_RAWSZ there's no problem, but when new hashing algorithm will be in place this memset will clear only 20-byte prefix of hash buffer.
Alternatively, hashclr implementation could be adjusted, but this function is almost removed from codebase already. Separate implementation of oidclr prevents potential buffer overrun in case someone incorrectly used hashclr on object_id in future.
--- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cache.h +1 -1
@@ -1029,7 +1029,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 ); }
Signature · 1 line
2.14.3
PATCH v2 7/14 match-trees: convert splice_tree to object_id
In reply to Patryk ObaraConvert the definition of static recursive splice_tree function to use struct object_id and adjust single caller.
--- match-trees.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-)
match-trees.c +20 -22
@@ -161,19 +161,17 @@ 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". */ -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 *hash1,const char *prefix, +const struct object_id *hash2,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 (hash1->hash, &type, &sz);if (!buf) -die ("cannot read tree %s" ,sha1_to_hex (hash1)); +die ("cannot read tree %s" ,oid_to_hex (hash1));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 (hash1)); + 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 (hash1));if (*subpath) { - status =splice_tree (rewrite_here, subpath, hash2, subtree); + status =splice_tree (rewrite_here, subpath, hash2, &subtree);if (status)return status; - rewrite_with = subtree; - } -else + rewrite_with = &subtree; + }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_sha1_file (buf, sz, tree_type, result->hash);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
Signature · 1 line
2.14.3
Re: [PATCH v2 07/14] match-trees: convert splice_tree to object_id
Quoted 13 lines · Patryk Obara
Convert the definition of static recursive
splice_treefunction to use structobject_idand adjust single caller.Signed-off-by Patryk Obara <[email protected]>--- match-trees.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-)match-trees.c +0
-0
match-trees.c static void match_trees(const struct object_id *hash1, · line 165
Quoted 9 lines
match-trees.c +2
-4@@ -161,19 +161,17 @@ 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". */ -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 *hash1,const char *prefix, +const struct object_id *hash2,struct object_id *result)
Maybe change the names to oid1 and oid2 too. I had a "what?" moment when I read hash1->hash below.
match-trees.c static int splice_tree(const unsigned char *hash1, · line 200
Quoted 10 lines
match-trees.c +3
-3@@ -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 (hash1)); + rewrite_here = (struct object_id *)oid;
You don't need the typecast here anymore, do you?
--
Duy
Re: [PATCH v2 07/14] match-trees: convert splice_tree to object_id
Quoted 18 lines · Duy Nguyen
Quoted 17 lines · Patryk Obara
Convert the definition of static recursive
splice_treefunction to use structobject_idand adjust single caller.Signed-off-by Patryk Obara <[email protected]>--- match-trees.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-)match-trees.c +0
-1@@ -161,19 +161,17 @@ 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". */ -static int splice_tree(const unsigned char *hash1,
Quoted 8 lines
match-trees.c static void match_trees(const struct object_id *hash1, · line 165
Quoted 5 lines
match-trees.c +2
-3-const char *prefix, - const unsigned char *hash2, - unsigned char *result) +static int splice_tree (const struct object_id *hash1,const char *prefix, +const struct object_id *hash2,struct object_id *result)Maybe change the names to oid1 and oid2 too. I had a "what?" moment when I read
hash1->hashbelow.
OK
Quoted 4 lines
Quoted 4 lines
match-trees.c +0
-0@@ -197,26 +195,26 @@ static int splice_tree(const unsigned char *hash1,if (strlen (name) == toplen && !memcmp (name, prefix, toplen)) {if (!S_ISDIR (mode))
Quoted 8 lines
match-trees.c static int splice_tree(const unsigned char *hash1, · line 200
Quoted 6 lines
match-trees.c +3
-3-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 (hash1)); + rewrite_here = (struct object_id *)oid;You don't need the typecast here anymore, do you?
Unfortunately, I do :(
Few lines above:
192: const struct object_id *oid;
194: oid = tree_entry_extract(&desc, &name, &mode);
Function tree_entry_extract returns const pointer, which leads to compiler warning:
"assigning to 'struct object_id *' from 'const struct object_id *' discards qualifiers".
On the other hand, if I change const qualifier for 'rewrite_here' variable - warning will
appear in line 216:
216: oidcpy(rewrite_here, rewrite_with);
So the question here is rather: is it ok to overwrite buffer returned by tree_entry_extract?
When writing this I opted to preserve cv-qualifiers despite changing pointer type (which
implied preservation of typecast) - partly because parameter 'desc' of tree_entry_extract
is NOT const (which suggests to me, that it's ok).
But this cast might be indication of unintended modification inside tree description
structure and might lead to an error is some other place, if there's an assumption, that
this buffer is not overwritable.
Maybe const should be removed from return type of tree_entry_extract (and maybe from oid field of struct name_entry)?
I will give it some more thought - maybe oidcpy from line 216 could be replaced.
Signature · 2 lines
| ← Ceci n'est pas une pipe Patryk Obara
Re: [PATCH v2 07/14] match-trees: convert splice_tree to object_id
Quoted 43 lines · Patryk Obara
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -197,26 +195,26 @@ static int splice_tree(const unsigned char *hash1, if (strlen(name) == toplen && !memcmp(name, prefix, toplen)) { if (!S_ISDIR(mode))Quoted 8 lines
Review static int splice_tree(const unsigned char *hash1, · line 200
Quoted 6 lines
(quoted diff) +3
-3- 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(hash1)); + rewrite_here = (struct object_id *)oid;You don't need the typecast here anymore, do you?
Unfortunately, I do :(
Few lines above:
192: const structobject_id*oid;
194: oid =tree_entry_extract(&desc, &name, &mode);Function
tree_entry_extractreturns const pointer, which leads to compiler warning:
"assigning to 'structobject_id*' from 'const structobject_id*' discards qualifiers".On the other hand, if I change const qualifier for '
rewrite_here' variable - warning will
appear in line 216:216:
oidcpy(rewrite_here, rewrite_with);So the question here is rather: is it ok to overwrite buffer returned by
tree_entry_extract?When writing this I opted to preserve cv-qualifiers despite changing pointer type (which implied preservation of typecast) - partly because parameter 'desc' of
tree_entry_extractis NOT const (which suggests to me, that it's ok).But this cast might be indication of unintended modification inside tree description structure and might lead to an error is some other place, if there's an assumption, that this buffer is not overwritable.
Quoted 5 lines
Maybe const should be removed from return type of
tree_entry_extract(and maybe from oid field of structname_entry)?I will give it some more thought - maybe oidcpy from line 216 could be replaced.
I've read this code a bit more (sorry I didn't see the "const struct object_id *oid" line when I read this patch). I think the typecast is very much on purpose. Junio wanted to make a new tree with one different hash in 68faf68938 (A new merge stragety 'subtree'. - 2007-02-15) but I think he kinda abused the tree walker for this task.
A cleaner way is create a new tree by copying unmodified entries and replacing just one entry. I think the old way was ok when we dealt with SHA-1 directly, but with the object_id abstraction in place, this kind of update looks iffy.
Alternatively, perhaps we can do something like this to keep tree manipulation in tree-walk.c, one of the two places that know about tree object on-disk format (the other one is cache-tree.c)
-- 8< --
match-trees.c +3 -3
@@ -171,7 +171,7 @@ static int splice_tree(const unsigned char *hash1,char *buf;unsigned long sz;struct tree_desc desc; -unsigned char *rewrite_here; +const object_id *rewrite_here;const unsigned char *rewrite_with;unsigned char subtree[20 ];enum object_type type;
@@ -199,7 +199,7 @@ static int splice_tree(const unsigned char *hash1,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; + rewrite_here = oid->hash;break ; }update_tree_entry (&desc);
@@ -215,7 +215,7 @@ static int splice_tree(const unsigned char *hash1, }else rewrite_with = hash2; -hashcpy (rewrite_here, rewrite_with); +replace_tree_entry_hash (&desc, rewrite_with, buf, sz); status =write_sha1_file (buf, sz, tree_type, result);free (buf);return status;
tree-walk.c +11 -0
@@ -164,6 +164,17 @@ int tree_entry_gently(struct tree_desc *desc, struct name_entry *entry)return 1 ; } +void replace_tree_entry_hash (struct tree_desc *desc, +const unsigned char *sha1, +char *buf,unsigned long size) +{ +unsigned long offset = (const char *)desc->buffer - buf; +unsigned char *to_update; + + to_update = (unsigned char *)buf + offset +tree_entry_len (&desc->entry); +hashcpy (to_update, sha1); +} +void setup_traverse_info (struct traverse_info *info,const char *base) {int pathlen =strlen (base);
tree-walk.h +3 -0
@@ -35,6 +35,9 @@ int update_tree_entry_gently(struct tree_desc *);void init_tree_desc (struct tree_desc *desc,const void *buf,unsigned long size);int init_tree_desc_gently (struct tree_desc *desc,const void *buf,unsigned long size); +void replace_tree_entry_hash (struct tree_desc *desc, +const unsigned char *sha1, +char *buf,unsigned long size);/* * Helper function that does both tree_entry_extract() and update_tree_entry() * and returns true for success
-- 8< --
PATCH v2 8/14 commit: convert commit_tree* to object_id
In reply to Patryk ObaraConvert the definitions and declarations of commit_tree and commit_tree_extended to use struct object_id and adjust all usages of these functions.
--- builtin/am.c | 4 ++-- builtin/commit-tree.c | 4 ++-- builtin/commit.c | 5 +++-- builtin/merge.c | 8 ++++---- commit.c | 15 +++++++-------- commit.h | 11 ++++++----- notes-cache.c | 4 ++-- notes-merge.c | 9 ++++----- notes-utils.c | 7 ++++--- notes-utils.h | 3 ++- 10 files changed, 36 insertions(+), 34 deletions(-)
builtin/am.c +2 -2
@@ -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" );
builtin/commit-tree.c +2 -2
@@ -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 ; }
builtin/commit.c +3 -2
@@ -1792,8 +1792,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" )); }
builtin/merge.c +4 -4
@@ -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);
commit.c +7 -8
@@ -1395,9 +1395,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;
@@ -1526,8 +1525,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) {
@@ -1535,7 +1534,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." );
@@ -1544,7 +1543,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
@@ -1583,7 +1582,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_sha1_file (buffer.buf, buffer.len, commit_type, ret->hash); out:strbuf_release (&buffer);return result;
commit.h +6 -5
@@ -263,14 +263,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 **);
notes-cache.c +2 -2
@@ -56,8 +56,8 @@ int notes_cache_write(struct notes_cache *c)if (write_notes_tree (&c->tree, tree_oid.hash))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 )
notes-merge.c +4 -5
@@ -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",
notes-utils.c +4 -3
@@ -6,7 +6,7 @@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;
@@ -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 );
notes-utils.h +2 -1
@@ -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);
Signature · 1 line
2.14.3
PATCH v2 9/14 notes: convert combine_notes_* to object_id
In reply to Patryk ObaraConvert the definition and declarations of combine_notes_* functions to struct object_id and adjust usage of these functions.
--- notes.c | 46 +++++++++++++++++++++++----------------------- notes.h | 25 +++++++++++++++---------- 2 files changed, 38 insertions(+), 33 deletions(-)
notes.c +23 -23
@@ -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);
@@ -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_sha1_file (buf, buf_len, blob_type, cur_oid->hash);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_sha1_file (buf.buf, buf.len, blob_type, cur_oid->hash); out:strbuf_release (&buf);
notes.h +15 -10
@@ -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
Signature · 1 line
2.14.3
PATCH v2 10/14 notes: convert write_notes_tree to object_id
In reply to Patryk ObaraConvert the definition and declaration of write_notes_tree to struct object_id and adjust usage of this function.
Additionally, improve style of small part of this function, as old formatting made it hard to understand at glance what this part of code is doing.
--- notes-cache.c | 2 +- notes-utils.c | 2 +- notes.c | 16 +++++++++------- notes.h | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-)
notes-cache.c +1 -1
@@ -54,7 +54,7 @@ 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,NULL , &commit_oid,NULL ,NULL ) <0 )
notes-utils.c +1 -1
@@ -12,7 +12,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,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) {
notes.c +9 -7
@@ -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,13 @@ 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_sha1_file (root.buf.buf, root.buf.len, tree_type, + result->hash);strbuf_release (&root.buf);return ret; }
notes.h +2 -2
@@ -217,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. *
@@ -225,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
Signature · 1 line
2.14.3
Re: [PATCH v2 10/14] notes: convert write_notes_tree to object_id
Quoted 7 lines · Patryk Obara
notes.c +0
-3@@ -1141,12 +1142,13 @@ 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) ||
notes.c int write_notes_tree(struct notes_tree *t, unsigned char *result) · line 1151
Quoted 10 lines
notes.c +7
-3-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_sha1_file (root.buf.buf, root.buf.len, tree_type, + result->hash);
Hmm.. new indentation style. I'm not complaining though. I think it looks good.
--
Duy
PATCH v2 11/14 sha1_file: convert write_sha1_file to object_id
In reply to Patryk ObaraConvert the definition and declaration of write_sha1_file to struct object_id and adjust usage of this function.
This commit also converts static function write_sha1_file_prepare, as it is closely related.
Rename these functions to write_object_file andwrite_object_file_prepare respectively.
Replace sha1_to_hex, hashcpy and hashclr with their oid equivalents wherever possible.
--- apply.c | 8 ++++---- builtin/checkout.c | 3 +-- builtin/mktag.c | 6 +++--- builtin/mktree.c | 10 +++++----- builtin/notes.c | 8 ++++---- builtin/receive-pack.c | 11 ++++++----- builtin/replace.c | 2 +- builtin/tag.c | 2 +- builtin/unpack-objects.c | 9 ++++++--- cache-tree.c | 5 +++-- cache.h | 4 +++- commit.c | 2 +- match-trees.c | 2 +- merge-recursive.c | 5 +++-- notes-cache.c | 2 +- notes.c | 9 ++++----- read-cache.c | 6 +++--- sha1_file.c | 29 +++++++++++++++-------------- 18 files changed, 65 insertions(+), 58 deletions(-)
apply.c +4 -4
@@ -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);
builtin/checkout.c +1 -2
@@ -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 );
builtin/mktag.c +3 -3
@@ -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 ; }
builtin/mktree.c +5 -5
@@ -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_missint 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 */
builtin/notes.c +4 -4
@@ -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 ]);
builtin/receive-pack.c +6 -5
@@ -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",
builtin/replace.c +1 -1
@@ -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);
builtin/tag.c +1 -1
@@ -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 ; }
builtin/unpack-objects.c +6 -3
@@ -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);
cache-tree.c +3 -2
@@ -406,9 +406,10 @@ static int update_one(struct cache_tree *it,oidcpy (&it->oid, &oid); else to_invalidate =1 ; - }else if (dryrun) + }else if (dryrun) {hash_object_file (buffer.buf, buffer.len, tree_type, &it->oid); -else if (write_sha1_file (buffer.buf, buffer.len, tree_type, it->oid.hash)) { + }else if (write_object_file (buffer.buf, buffer.len, tree_type, + &it->oid)) {strbuf_release (&buffer);return -1 ; }
cache.h +3 -1
@@ -1240,7 +1240,9 @@ extern int sha1_object_info(const unsigned char *, unsigned long *);extern int hash_object_file (const void *buf,unsigned long len,const char *type,struct object_id *oid); -extern int write_sha1_file (const void *buf,unsigned long len,const char *type,unsigned char *return_sha1); +extern int write_object_file (const void *buf,unsigned long len, +const char *type,struct object_id *oid); +extern int hash_sha1_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,
commit.c +1 -1
@@ -1582,7 +1582,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->hash); + result =write_object_file (buffer.buf, buffer.len, commit_type, ret); out:strbuf_release (&buffer);return result;
match-trees.c +1 -1
@@ -214,7 +214,7 @@ static int splice_tree(const struct object_id *hash1, const char *prefix, rewrite_with = hash2; }oidcpy (rewrite_here, rewrite_with); - status =write_sha1_file (buf, sz, tree_type, result->hash); + status =write_object_file (buf, sz, tree_type, result);free (buf);return status; }
merge-recursive.c +3 -2
@@ -1009,8 +1009,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);
notes-cache.c +1 -1
@@ -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 ); }
notes.c +4 -5
@@ -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);
@@ -825,7 +825,7 @@ int combine_notes_concatenate(struct object_id *cur_oid,free (new_msg);/* create a new blob object from buf */ - ret =write_sha1_file (buf, buf_len, blob_type, cur_oid->hash); + ret =write_object_file (buf, buf_len, blob_type, cur_oid);free (buf);return ret; }
@@ -905,7 +905,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid, string_list_join_lines_helper, &buf)) goto out; - ret =write_sha1_file (buf.buf, buf.len, blob_type, cur_oid->hash); + ret =write_object_file (buf.buf, buf.len, blob_type, cur_oid); out:strbuf_release (&buf);
@@ -1147,8 +1147,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result) 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_sha1_file (root.buf.buf, root.buf.len, tree_type, - result->hash); +write_object_file (root.buf.buf, root.buf.len, tree_type, result);strbuf_release (&root.buf);return ret; }
read-cache.c +3 -3
@@ -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)
sha1_file.c +15 -14
@@ -1419,9 +1419,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;
@@ -1432,7 +1432,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); }/*
@@ -1490,7 +1490,7 @@ int hash_object_file(const void *buf, unsigned long len, const char *type, {char hdr[32 ];int hdrlen =sizeof (hdr); -write_sha1_file_prepare (buf, len, type, oid->hash, hdr, &hdrlen); +write_object_file_prepare (buf, len, type, oid, hdr, &hdrlen);return 0 ; }
@@ -1633,7 +1633,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);
@@ -1641,10 +1642,10 @@ 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->hash, hdr, hdrlen, buf, len,0 ); } int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type,
@@ -1656,7 +1657,7 @@ 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;
@@ -1767,7 +1768,7 @@ 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_object_file (buf, size,typename (type), oid);if (re_allocated)
@@ -1789,8 +1790,8 @@ static int index_stream_convert_blob(struct object_id *oid, int fd, get_safe_crlf(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_object_file (sbuf.buf, sbuf.len,typename (OBJ_BLOB ), oid);
@@ -1908,7 +1909,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsignereturn error_errno ("readlink(\"%s\")" , path);if (!(flags &HASH_WRITE_OBJECT ))hash_object_file (sb.buf, sb.len, blob_type, oid); -else if (write_sha1_file (sb.buf, sb.len, blob_type, oid->hash)) +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 ;
Signature · 1 line
2.14.3
PATCH v2 12/14 sha1_file: convert force_object_loose to object_id
In reply to Patryk ObaraConvert the definition and declaration of force_object_loose to struct object_id and adjust usage of this function.
--- builtin/pack-objects.c | 2 +- cache.h | 3 ++- sha1_file.c | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-)
builtin/pack-objects.c +1 -1
@@ -2768,7 +2768,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" ); } }
cache.h +2 -1
@@ -1248,7 +1248,8 @@ extern int hash_sha1_file_literally(const void *buf, unsigned long len, const chextern int pretend_object_file (void *,unsigned long ,enum object_type ,struct object_id *oid); -extern int force_object_loose (const unsigned char *sha1,time_t mtime); +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);
sha1_file.c +5 -5
@@ -1670,7 +1670,7 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typreturn 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;
@@ -1679,13 +1679,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->hash, hdr, hdrlen, buf, len, mtime);free (buf);return ret;
Signature · 1 line
2.14.3
PATCH v2 13/14 sha1_file: convert write_loose_object to object_id
In reply to Patryk ObaraConvert the definition and declaration of statis write_loose_object function to struct object_id.
--- sha1_file.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
sha1_file.c +16 -12
@@ -1548,16 +1548,17 @@ 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 ; -const char *filename =sha1_file_name (sha1); +const char *filename =sha1_file_name (oid->hash); fd =create_tmpfile (&tmp_file, filename);if (fd <0 ) {
@@ -1594,13 +1595,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);
@@ -1645,7 +1649,7 @@ int write_object_file(const void *buf, unsigned long len, const char *type,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 (oid->hash, 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,
@@ -1663,7 +1667,7 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typ 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);
@@ -1685,7 +1689,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)if (!buf)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 (oid->hash, hdr, hdrlen, buf, len, mtime); + ret =write_loose_object (oid, hdr, hdrlen, buf, len, mtime);free (buf);return ret;
Signature · 1 line
2.14.3
PATCH v2 14/14 sha1_file: rename hash_sha1_file_literally
In reply to Patryk ObaraThis function was already converted to use struct object_id earlier.
--- builtin/hash-object.c | 3 ++- cache.h | 4 +++- sha1_file.c | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-)
builtin/hash-object.c +2 -1
@@ -24,7 +24,8 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsigif (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; }
cache.h +3 -1
@@ -1243,7 +1243,9 @@ extern int hash_object_file(const void *buf, unsigned long len,extern int write_object_file (const void *buf,unsigned long len,const char *type,struct object_id *oid); -extern int hash_sha1_file_literally (const void *buf,unsigned long len,const char *type,struct object_id *oid,unsigned flags); +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);
sha1_file.c +3 -2
@@ -1652,8 +1652,9 @@ int write_object_file(const void *buf, unsigned long len, const char *type,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 ;
Signature · 1 line
2.14.3
Quoted 1 line · Patryk Obara
sha1_file.c | 100 ++++++++++++++------------
You have started the invasion to sha1_file.c. Victory is near! (*) 2018 will be the year of something-other-shan-sha1 :)
I've read through the series quickly. It looks good. Patches 1 and 2 should be sent separately though.
(*) Technically the hashing part is still easy. I look forward to seeing you deal with the object reading part, especially from pack files. It's fun ;-)
--
Duy
Quoted 1 line
Patches 1 and 2 should be sent separately though.
I hoped they could be piggy-backed, but since there will be v3 of this patch series... I'll wait for Junio's opinion.
Quoted 1 line
I look forward to seeing you deal with the object reading part …
Yeah, even reading of loose objects does not work on my test branch yet.
Turns out some functions (*) depend on each other during conversion to oid - so they are either refactored together in one BIG commit or I need to deploy some temporary hacks to make it possible to split work into smaller batches.
(*) refactor of sha1_object_info transitively depends on lookup_replace_object and the other way around. verify_object and verify_tag will also cause some problems.
Signature · 2 lines
| ← Ceci n'est pas une pipe Patryk Obara
v3 cover Some fixes and bunch of object_id conversions
In reply to Patryk ObaraCompared to v2:
* rebased to latest master
* patch 1 and 2
I kept them in, but if Junio prefers them separately then I'll send them as separate patches.
* patch 5
- strbuf_add(buf, sha1_to_hex(oid.hash), GIT_SHA1_HEXSZ);
+ strbuf_addstr(buf, oid_to_hex(&oid));
* patch 7
On suggestion from Duy Nguyễn, I renamed parameter names:
'hash1' and 'hash2' with 'oid1' and 'oid2' to avoid e.g. 'hash1->hash'.
I decided *not to* implement suggested replace_tree_entry_hash function (when implemented as in mail, t6026-merge-subtree fails). I think this overwriting of object_id needs to be addressed, but probably at the time of adjusting tree object format for longer hash.
Patryk Obara (14):
http-push: improve error log
clang-format: adjust penalty for return type line break
sha1_file: convert pretend_sha1_file to object_id
dir: convert struct sha1_stat to use object_id
sha1_file: convert hash_sha1_file to object_id
cache: clear whole hash buffer with oidclr
match-trees: convert splice_tree to object_id
commit: convert commit_tree* to object_id
notes: convert combine_notes_* to object_id
notes: convert write_notes_tree to object_id
sha1_file: convert write_sha1_file to object_id
sha1_file: convert force_object_loose to object_id
sha1_file: convert write_loose_object to object_id
sha1_file: rename hash_sha1_file_literally
.clang-format | 2 +- Documentation/technical/api-object-access.txt | 2 +- apply.c | 12 ++-- blame.c | 2 +- builtin/am.c | 4 +- builtin/checkout.c | 3 +- builtin/commit-tree.c | 4 +- builtin/commit.c | 5 +- builtin/hash-object.c | 3 +- builtin/index-pack.c | 5 +- builtin/merge.c | 8 +-- builtin/mktag.c | 6 +- builtin/mktree.c | 10 +-- builtin/notes.c | 8 +-- builtin/pack-objects.c | 2 +- builtin/receive-pack.c | 11 +-- builtin/replace.c | 4 +- builtin/tag.c | 2 +- builtin/unpack-objects.c | 11 +-- cache-tree.c | 16 ++--- cache.h | 25 ++++--- commit.c | 15 ++-- commit.h | 11 +-- convert.c | 6 +- diffcore-rename.c | 4 +- dir.c | 56 +++++++-------- dir.h | 12 ++-- http-push.c | 4 ++ log-tree.c | 2 +- match-trees.c | 46 ++++++------ merge-recursive.c | 5 +- notes-cache.c | 8 +-- notes-merge.c | 9 ++- notes-utils.c | 9 +-- notes-utils.h | 3 +- notes.c | 63 ++++++++-------- notes.h | 29 ++++---- read-cache.c | 6 +- sha1_file.c | 100 ++++++++++++++------------ t/helper/test-dump-untracked-cache.c | 4 +- 40 files changed, 281 insertions(+), 256 deletions(-)
base-commit: 5be1f00a9a701532232f57958efab4be8c959a29
Signature · 1 line
2.14.3
PATCH v3 1/14 http-push: improve error log
When git push fails due to server-side WebDAV error, it's not easy to point to the main culprit. Additional information about exact cURL error and HTTP server response is helpful for debugging purpose.
New error log helped me pinpoint failing test t5540-http-push-webdav to a missing Apache dependency in Fedora 27:
https://bugzilla.redhat.com/show_bug.cgi?id=1491151
--- http-push.c | 4 ++++ 1 file changed, 4 insertions(+)
http-push.c +4 -0
@@ -915,6 +915,10 @@ static struct remote_lock *lock_remote(const char *path, long timeout) lock->timeout =-1 ; }XML_ParserFree (parser); + }else { +fprintf (stderr, +"error: curl result=%d, HTTP code=%ld\n" , + results.curl_result, results.http_code); } }else {fprintf (stderr,"Unable to start LOCK request\n" );
Signature · 1 line
2.14.3
PATCH v3 2/14 clang-format: adjust penalty for return type line break
In reply to Patryk ObaraThe penalty of 5 makes clang-format very eager to put even short type declarations (e.g. "extern int") into a separate line, even when breaking parameters list is sufficient.
--- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.clang-format +1 -1
@@ -163,7 +163,7 @@ PenaltyBreakComment: 10 PenaltyBreakFirstLessLess: 0 PenaltyBreakString: 10 PenaltyExcessCharacter: 100 -PenaltyReturnTypeOnItsOwnLine: 5 +PenaltyReturnTypeOnItsOwnLine: 60 # Don't sort #include's SortIncludes: false
Signature · 1 line
2.14.3
PATCH v3 3/14 sha1_file: convert pretend_sha1_file to object_id
In reply to Patryk ObaraConvert the declaration and definition of pretend_sha1_file to use struct object_id and adjust all usages of this function. Rename it to pretend_object_file.
--- Documentation/technical/api-object-access.txt | 2 +- blame.c | 2 +- cache.h | 5 ++++- sha1_file.c | 10 +++++----- 4 files changed, 11 insertions(+), 8 deletions(-)
Documentation/technical/api-object-access.txt +1 -1
@@ -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
blame.c +1 -1
@@ -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
cache.h +4 -1
@@ -1241,7 +1241,10 @@ 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 pretend_object_file (void *,unsigned long ,enum object_type , +struct object_id *oid); +extern int force_object_loose (const unsigned char *sha1,time_t mtime);extern int git_open_cloexec (const char *name,int flags);#define git_open (name) git_open_cloexec(name, O_RDONLY)
sha1_file.c +5 -5
@@ -1312,13 +1312,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_sha1_file (buf, len,typename (type), oid->hash); +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++];
@@ -1326,7 +1326,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 ; }
Signature · 1 line
2.14.3
PATCH v3 4/14 dir: convert struct sha1_stat to use object_id
In reply to Patryk ObaraConvert the declaration of struct sha1_stat. Adjust all usages of this struct and replace hash{clr,cmp,cpy} with oid{clr,cmp,cpy} wherever possible. Rename it to struct oid_stat.
Remove macro EMPTY_BLOB_SHA1_BIN, as it's no longer used.
--- cache.h | 2 -- dir.c | 56 +++++++++++++++++------------------- dir.h | 12 ++++---- t/helper/test-dump-untracked-cache.c | 4 +-- 4 files changed, 34 insertions(+), 40 deletions(-)
cache.h +0 -2
@@ -1047,8 +1047,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) {
dir.c +26 -30
141 lines not on this page · raw message
dir.h +6 -6
@@ -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; };
t/helper/test-dump-untracked-cache.c +2 -2
@@ -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)
Signature · 1 line
2.14.3
Re: [PATCH v3 04/14] dir: convert struct sha1_stat to use object_id
Quoted 3 lines · Patryk Obara
Convert the declaration of struct
sha1_stat. Adjust all usages of this struct and replace hash{clr,cmp,cpy} with oid{clr,cmp,cpy} wherever possible. Rename it to structoid_stat.
OK, but a hunk like this makes readers wonder...
dir.c int within_depth(const char *name, int namelen, · line 237
Quoted 6 lines
dir.c +2
-4-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 *sha1_stat, +size_t *size_out,char **data_out)
... why the variable is still called sha1_stat, not oid_stat. Is it because it makes the patch too noisy or something?
Quoted 1 line
Remove macro
EMPTY_BLOB_SHA1_BIN, as it's no longer used.
Good.
PATCH v3 5/14 sha1_file: convert hash_sha1_file to object_id
In reply to Patryk ObaraConvert the declaration and definition of hash_sha1_file to use struct object_id and adjust all function calls.
Rename this function to hash_object_file.
--- apply.c | 4 ++-- builtin/index-pack.c | 5 ++--- builtin/replace.c | 2 +- builtin/unpack-objects.c | 2 +- cache-tree.c | 11 +++++------ cache.h | 5 ++++- convert.c | 6 +++--- diffcore-rename.c | 4 ++-- dir.c | 4 ++-- log-tree.c | 2 +- sha1_file.c | 26 +++++++++++++------------- 11 files changed, 36 insertions(+), 35 deletions(-)
apply.c +2 -2
@@ -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));
builtin/index-pack.c +2 -3
@@ -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 ();
builtin/replace.c +1 -1
@@ -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);
builtin/unpack-objects.c +1 -1
@@ -258,7 +258,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);
cache-tree.c +5 -6
@@ -400,15 +400,14 @@ 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); +hash_object_file (buffer.buf, buffer.len, tree_type, &it->oid);else if (write_sha1_file (buffer.buf, buffer.len, tree_type, it->oid.hash)) {strbuf_release (&buffer);return -1 ;
cache.h +4 -1
@@ -1236,7 +1236,10 @@ 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 hash_object_file (const void *buf,unsigned long len, +const char *type,struct object_id *oid); +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);
convert.c +3 -3
@@ -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);
diffcore-rename.c +2 -2
@@ -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); }
dir.c +2 -2
@@ -846,8 +846,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,oidcpy (&sha1_stat->oid, &istate->cache[pos]->oid); else - hash_sha1_file(buf, size, "blob", - sha1_stat->oid.hash); + hash_object_file(buf, size, "blob", + &sha1_stat->oid);fill_stat_data (&sha1_stat->stat, &st); sha1_stat->valid =1 ; }
log-tree.c +1 -1
@@ -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 */
sha1_file.c +13 -13
@@ -788,7 +788,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;
@@ -796,8 +796,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 );
@@ -822,9 +822,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)
@@ -1317,7 +1317,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type, {struct cached_object *co; -hash_sha1_file (buf, len,typename (type), oid->hash); +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);
@@ -1485,12 +1485,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_sha1_file_prepare (buf, len, type, oid->hash, hdr, &hdrlen);return 0 ; }
@@ -1769,7 +1769,7 @@ 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);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;
@@ -1792,8 +1792,8 @@ static int index_stream_convert_blob(struct object_id *oid, int fd, ret =write_sha1_file (sbuf.buf, sbuf.len,typename (OBJ_BLOB ), oid->hash); 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; }
@@ -1907,7 +1907,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigneif (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); +hash_object_file (sb.buf, sb.len, blob_type, oid);else if (write_sha1_file (sb.buf, sb.len, blob_type, oid->hash)) rc =error ("%s: failed to insert into database" , path);strbuf_release (&sb);
Signature · 1 line
2.14.3
PATCH v3 6/14 cache: clear whole hash buffer with oidclr
In reply to Patryk ObaraAs long as GIT_SHA1_RAWSZ is equal to GIT_MAX_RAWSZ there's no problem, but when new hashing algorithm will be in place this memset will clear only 20-byte prefix of hash buffer.
Alternatively, hashclr implementation could be adjusted, but this function is almost removed from codebase already. Separate implementation of oidclr prevents potential buffer overrun in case someone incorrectly used hashclr on object_id in future.
--- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cache.h +1 -1
@@ -1029,7 +1029,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 ); }
Signature · 1 line
2.14.3
PATCH v3 7/14 match-trees: convert splice_tree to object_id
In reply to Patryk ObaraConvert the definition of static recursive splice_tree function to use struct object_id and adjust single caller.
--- match-trees.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-)
match-trees.c +22 -24
@@ -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_sha1_file (buf, sz, tree_type, result->hash);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
Signature · 1 line
2.14.3
PATCH v3 8/14 commit: convert commit_tree* to object_id
In reply to Patryk ObaraConvert the definitions and declarations of commit_tree and commit_tree_extended to use struct object_id and adjust all usages of these functions.
--- builtin/am.c | 4 ++-- builtin/commit-tree.c | 4 ++-- builtin/commit.c | 5 +++-- builtin/merge.c | 8 ++++---- commit.c | 15 +++++++-------- commit.h | 11 ++++++----- notes-cache.c | 4 ++-- notes-merge.c | 9 ++++----- notes-utils.c | 7 ++++--- notes-utils.h | 3 ++- 10 files changed, 36 insertions(+), 34 deletions(-)
builtin/am.c +2 -2
@@ -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" );
builtin/commit-tree.c +2 -2
@@ -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 ; }
builtin/commit.c +3 -2
@@ -1794,8 +1794,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" )); }
builtin/merge.c +4 -4
@@ -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);
commit.c +7 -8
@@ -1380,9 +1380,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;
@@ -1511,8 +1510,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) {
@@ -1520,7 +1519,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." );
@@ -1529,7 +1528,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
@@ -1568,7 +1567,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_sha1_file (buffer.buf, buffer.len, commit_type, ret->hash); out:strbuf_release (&buffer);return result;
commit.h +6 -5
@@ -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 **);
notes-cache.c +2 -2
@@ -56,8 +56,8 @@ int notes_cache_write(struct notes_cache *c)if (write_notes_tree (&c->tree, tree_oid.hash))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 )
notes-merge.c +4 -5
@@ -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",
notes-utils.c +4 -3
@@ -6,7 +6,7 @@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;
@@ -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 );
notes-utils.h +2 -1
@@ -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);
Signature · 1 line
2.14.3
PATCH v3 9/14 notes: convert combine_notes_* to object_id
In reply to Patryk ObaraConvert the definition and declarations of combine_notes_* functions to struct object_id and adjust usage of these functions.
--- notes.c | 46 +++++++++++++++++++++++----------------------- notes.h | 25 +++++++++++++++---------- 2 files changed, 38 insertions(+), 33 deletions(-)
notes.c +23 -23
@@ -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);
@@ -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_sha1_file (buf, buf_len, blob_type, cur_oid->hash);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_sha1_file (buf.buf, buf.len, blob_type, cur_oid->hash); out:strbuf_release (&buf);
notes.h +15 -10
@@ -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
Signature · 1 line
2.14.3
PATCH v3 10/14 notes: convert write_notes_tree to object_id
In reply to Patryk ObaraConvert the definition and declaration of write_notes_tree to struct object_id and adjust usage of this function.
Additionally, improve style of small part of this function, as old formatting made it hard to understand at glance what this part of code is doing.
--- notes-cache.c | 2 +- notes-utils.c | 2 +- notes.c | 16 +++++++++------- notes.h | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-)
notes-cache.c +1 -1
@@ -54,7 +54,7 @@ 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,NULL , &commit_oid,NULL ,NULL ) <0 )
notes-utils.c +1 -1
@@ -12,7 +12,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,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) {
notes.c +9 -7
@@ -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,13 @@ 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_sha1_file (root.buf.buf, root.buf.len, tree_type, + result->hash);strbuf_release (&root.buf);return ret; }
notes.h +2 -2
@@ -217,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. *
@@ -225,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
Signature · 1 line
2.14.3
PATCH v3 11/14 sha1_file: convert write_sha1_file to object_id
In reply to Patryk ObaraConvert the definition and declaration of write_sha1_file to struct object_id and adjust usage of this function.
This commit also converts static function write_sha1_file_prepare, as it is closely related.
Rename these functions to write_object_file andwrite_object_file_prepare respectively.
Replace sha1_to_hex, hashcpy and hashclr with their oid equivalents wherever possible.
--- apply.c | 8 ++++---- builtin/checkout.c | 3 +-- builtin/mktag.c | 6 +++--- builtin/mktree.c | 10 +++++----- builtin/notes.c | 8 ++++---- builtin/receive-pack.c | 11 ++++++----- builtin/replace.c | 2 +- builtin/tag.c | 2 +- builtin/unpack-objects.c | 9 ++++++--- cache-tree.c | 5 +++-- cache.h | 4 +++- commit.c | 2 +- match-trees.c | 2 +- merge-recursive.c | 5 +++-- notes-cache.c | 2 +- notes.c | 9 ++++----- read-cache.c | 6 +++--- sha1_file.c | 29 +++++++++++++++-------------- 18 files changed, 65 insertions(+), 58 deletions(-)
apply.c +4 -4
@@ -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);
builtin/checkout.c +1 -2
@@ -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 );
builtin/mktag.c +3 -3
@@ -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 ; }
builtin/mktree.c +5 -5
@@ -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_missint 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 */
builtin/notes.c +4 -4
@@ -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 ]);
builtin/receive-pack.c +6 -5
@@ -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",
builtin/replace.c +1 -1
@@ -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);
builtin/tag.c +1 -1
@@ -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 ; }
builtin/unpack-objects.c +6 -3
@@ -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);
cache-tree.c +3 -2
@@ -406,9 +406,10 @@ static int update_one(struct cache_tree *it,oidcpy (&it->oid, &oid); else to_invalidate =1 ; - }else if (dryrun) + }else if (dryrun) {hash_object_file (buffer.buf, buffer.len, tree_type, &it->oid); -else if (write_sha1_file (buffer.buf, buffer.len, tree_type, it->oid.hash)) { + }else if (write_object_file (buffer.buf, buffer.len, tree_type, + &it->oid)) {strbuf_release (&buffer);return -1 ; }
cache.h +3 -1
@@ -1240,7 +1240,9 @@ extern int sha1_object_info(const unsigned char *, unsigned long *);extern int hash_object_file (const void *buf,unsigned long len,const char *type,struct object_id *oid); -extern int write_sha1_file (const void *buf,unsigned long len,const char *type,unsigned char *return_sha1); +extern int write_object_file (const void *buf,unsigned long len, +const char *type,struct object_id *oid); +extern int hash_sha1_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,
commit.c +1 -1
@@ -1567,7 +1567,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->hash); + result =write_object_file (buffer.buf, buffer.len, commit_type, ret); out:strbuf_release (&buffer);return result;
match-trees.c +1 -1
@@ -214,7 +214,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, rewrite_with = oid2; }oidcpy (rewrite_here, rewrite_with); - status =write_sha1_file (buf, sz, tree_type, result->hash); + status =write_object_file (buf, sz, tree_type, result);free (buf);return status; }
merge-recursive.c +3 -2
@@ -1009,8 +1009,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);
notes-cache.c +1 -1
@@ -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 ); }
notes.c +4 -5
@@ -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);
@@ -825,7 +825,7 @@ int combine_notes_concatenate(struct object_id *cur_oid,free (new_msg);/* create a new blob object from buf */ - ret =write_sha1_file (buf, buf_len, blob_type, cur_oid->hash); + ret =write_object_file (buf, buf_len, blob_type, cur_oid);free (buf);return ret; }
@@ -905,7 +905,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid, string_list_join_lines_helper, &buf)) goto out; - ret =write_sha1_file (buf.buf, buf.len, blob_type, cur_oid->hash); + ret =write_object_file (buf.buf, buf.len, blob_type, cur_oid); out:strbuf_release (&buf);
@@ -1147,8 +1147,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result) 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_sha1_file (root.buf.buf, root.buf.len, tree_type, - result->hash); +write_object_file (root.buf.buf, root.buf.len, tree_type, result);strbuf_release (&root.buf);return ret; }
read-cache.c +3 -3
@@ -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)
sha1_file.c +15 -14
@@ -1419,9 +1419,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;
@@ -1432,7 +1432,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); }/*
@@ -1490,7 +1490,7 @@ int hash_object_file(const void *buf, unsigned long len, const char *type, {char hdr[32 ];int hdrlen =sizeof (hdr); -write_sha1_file_prepare (buf, len, type, oid->hash, hdr, &hdrlen); +write_object_file_prepare (buf, len, type, oid, hdr, &hdrlen);return 0 ; }
@@ -1633,7 +1633,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);
@@ -1641,10 +1642,10 @@ 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->hash, hdr, hdrlen, buf, len,0 ); } int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type,
@@ -1656,7 +1657,7 @@ 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;
@@ -1767,7 +1768,7 @@ 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_object_file (buf, size,typename (type), oid);if (re_allocated)
@@ -1789,8 +1790,8 @@ static int index_stream_convert_blob(struct object_id *oid, int fd, get_safe_crlf(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_object_file (sbuf.buf, sbuf.len,typename (OBJ_BLOB ), oid);
@@ -1908,7 +1909,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsignereturn error_errno ("readlink(\"%s\")" , path);if (!(flags &HASH_WRITE_OBJECT ))hash_object_file (sb.buf, sb.len, blob_type, oid); -else if (write_sha1_file (sb.buf, sb.len, blob_type, oid->hash)) +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 ;
Signature · 1 line
2.14.3
PATCH v3 12/14 sha1_file: convert force_object_loose to object_id
In reply to Patryk ObaraConvert the definition and declaration of force_object_loose to struct object_id and adjust usage of this function.
--- builtin/pack-objects.c | 2 +- cache.h | 3 ++- sha1_file.c | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-)
builtin/pack-objects.c +1 -1
@@ -2768,7 +2768,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" ); } }
cache.h +2 -1
@@ -1248,7 +1248,8 @@ extern int hash_sha1_file_literally(const void *buf, unsigned long len, const chextern int pretend_object_file (void *,unsigned long ,enum object_type ,struct object_id *oid); -extern int force_object_loose (const unsigned char *sha1,time_t mtime); +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);
sha1_file.c +5 -5
@@ -1670,7 +1670,7 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typreturn 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;
@@ -1679,13 +1679,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->hash, hdr, hdrlen, buf, len, mtime);free (buf);return ret;
Signature · 1 line
2.14.3
PATCH v3 13/14 sha1_file: convert write_loose_object to object_id
In reply to Patryk ObaraConvert the definition and declaration of statis write_loose_object function to struct object_id.
--- sha1_file.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
sha1_file.c +16 -12
@@ -1548,16 +1548,17 @@ 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 ; -const char *filename =sha1_file_name (sha1); +const char *filename =sha1_file_name (oid->hash); fd =create_tmpfile (&tmp_file, filename);if (fd <0 ) {
@@ -1594,13 +1595,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);
@@ -1645,7 +1649,7 @@ int write_object_file(const void *buf, unsigned long len, const char *type,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 (oid->hash, 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,
@@ -1663,7 +1667,7 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typ 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);
@@ -1685,7 +1689,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)if (!buf)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 (oid->hash, hdr, hdrlen, buf, len, mtime); + ret =write_loose_object (oid, hdr, hdrlen, buf, len, mtime);free (buf);return ret;
Signature · 1 line
2.14.3
Re: [PATCH v3 13/14] sha1_file: convert write_loose_object to object_id
Quoted 1 line · Patryk Obara
Convert the definition and declaration of statis
write_loose_object
s/statis/static/
Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US https://www.crustytoothpaste.net/~bmc | My opinion only OpenPGP: https://keybase.io/bk2204
PATCH v3 14/14 sha1_file: rename hash_sha1_file_literally
In reply to Patryk ObaraThis function was already converted to use struct object_id earlier.
--- builtin/hash-object.c | 3 ++- cache.h | 4 +++- sha1_file.c | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-)
builtin/hash-object.c +2 -1
@@ -24,7 +24,8 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsigif (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; }
cache.h +3 -1
@@ -1243,7 +1243,9 @@ extern int hash_object_file(const void *buf, unsigned long len,extern int write_object_file (const void *buf,unsigned long len,const char *type,struct object_id *oid); -extern int hash_sha1_file_literally (const void *buf,unsigned long len,const char *type,struct object_id *oid,unsigned flags); +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);
sha1_file.c +3 -2
@@ -1652,8 +1652,9 @@ int write_object_file(const void *buf, unsigned long len, const char *type,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 ;
Signature · 1 line
2.14.3
Quoted 7 lines · Patryk Obara
Compared to v2:
* rebased to latest master
* patch 1 and 2
I kept them in, but if Junio prefers them separately then I'll send them as separate patches.
It's not just me, but I think they should be separated out (I can just queue them separately, and there is no need to resend them unless/until they need to be updated for their own reason).
Quoted 7 lines · Patryk Obara
Patryk Obara (14):
http-push: improve error log
clang-format: adjust penalty for return type line break
sha1_file: convertpretend_sha1_filetoobject_id
dir: convert structsha1_statto useobject_id
sha1_file: converthash_sha1_filetoobject_id
cache: clear whole hash buffer with oidclr
Quoted 8 lines
match-trees: convert
splice_treetoobject_id
commit: convert commit_tree* toobject_id
notes: convert combine_notes_* toobject_id
notes: convertwrite_notes_treetoobject_id
sha1_file: convertwrite_sha1_filetoobject_id
sha1_file: convertforce_object_loosetoobject_id
sha1_file: convertwrite_loose_objecttoobject_id
sha1_file: renamehash_sha1_file_literally
These were mostly pleasant read. I'll queue these on two topic branches and wait to see what others say.
Thanks.
Quoted 18 lines · Junio C Hamano
Quoted 7 lines · Patryk Obara
Patryk Obara (14):
http-push: improve error log
clang-format: adjust penalty for return type line break
sha1_file: convertpretend_sha1_filetoobject_id
dir: convert structsha1_statto useobject_id
sha1_file: converthash_sha1_filetoobject_id
cache: clear whole hash buffer with oidclrQuoted 8 lines
match-trees: convert
splice_treetoobject_id
commit: convert commit_tree* toobject_id
notes: convert combine_notes_* toobject_id
notes: convertwrite_notes_treetoobject_id
sha1_file: convertwrite_sha1_filetoobject_id
sha1_file: convertforce_object_loosetoobject_id
sha1_file: convertwrite_loose_objecttoobject_id
sha1_file: renamehash_sha1_file_literally
Quoted 2 lines
These were mostly pleasant read. I'll queue these on two topic branches and wait to see what others say.
Looks good to me too.
Signature · 1 line
Duy
Quoted 18 lines · Junio C Hamano
Quoted 7 lines · Patryk Obara
Patryk Obara (14):
http-push: improve error log
clang-format: adjust penalty for return type line break
sha1_file: convertpretend_sha1_filetoobject_id
dir: convert structsha1_statto useobject_id
sha1_file: converthash_sha1_filetoobject_id
cache: clear whole hash buffer with oidclrQuoted 8 lines
match-trees: convert
splice_treetoobject_id
commit: convert commit_tree* toobject_id
notes: convert combine_notes_* toobject_id
notes: convertwrite_notes_treetoobject_id
sha1_file: convertwrite_sha1_filetoobject_id
sha1_file: convertforce_object_loosetoobject_id
sha1_file: convertwrite_loose_objecttoobject_id
sha1_file: renamehash_sha1_file_literally
Quoted 2 lines
These were mostly pleasant read. I'll queue these on two topic branches and wait to see what others say.
Other than the one typo, looks good to me.
Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US https://www.crustytoothpaste.net/~bmc | My opinion only OpenPGP: https://keybase.io/bk2204
v4 cover A bunch of object_id conversions
In reply to Patryk ObaraThank you, everyone, for review and thanks, Junio for queueing two first patches - I removed them from v4, as there were no more comments to them anyway.
Compared to v3:
Patch 2 (formerly 4)
- renamed all parameter names sha1_stat to oid_stat
- renamed static function load sha1_stat to load_oid_stat
- adjusted a comment, that included "sha1_stat" in text
Patch 11 (formerly 13)
- fixed a typo in the commit message
Hopefully, this will be the last iteration on this batch of object_id conversions; I already have next batch prepared (I just need to clean it up before sending).
Patryk Obara (12):
sha1_file: convert pretend_sha1_file to object_id
dir: convert struct sha1_stat to use object_id
sha1_file: convert hash_sha1_file to object_id
cache: clear whole hash buffer with oidclr
match-trees: convert splice_tree to object_id
commit: convert commit_tree* to object_id
notes: convert combine_notes_* to object_id
notes: convert write_notes_tree to object_id
sha1_file: convert write_sha1_file to object_id
sha1_file: convert force_object_loose to object_id
sha1_file: convert write_loose_object to object_id
sha1_file: rename hash_sha1_file_literally
Documentation/technical/api-object-access.txt | 2 +- apply.c | 12 +-- blame.c | 2 +- builtin/am.c | 4 +- builtin/checkout.c | 3 +- builtin/commit-tree.c | 4 +- builtin/commit.c | 5 +- builtin/hash-object.c | 3 +- builtin/index-pack.c | 5 +- builtin/merge.c | 8 +- builtin/mktag.c | 6 +- builtin/mktree.c | 10 +-- builtin/notes.c | 8 +- builtin/pack-objects.c | 2 +- builtin/receive-pack.c | 11 +-- builtin/replace.c | 4 +- builtin/tag.c | 2 +- builtin/unpack-objects.c | 11 ++- cache-tree.c | 16 ++-- cache.h | 25 +++++-- commit.c | 15 ++-- commit.h | 11 +-- convert.c | 6 +- diffcore-rename.c | 4 +- dir.c | 104 +++++++++++++------------- dir.h | 12 +-- log-tree.c | 2 +- match-trees.c | 46 ++++++------ merge-recursive.c | 5 +- notes-cache.c | 8 +- notes-merge.c | 9 +-- notes-utils.c | 9 ++- notes-utils.h | 3 +- notes.c | 63 ++++++++-------- notes.h | 29 ++++--- read-cache.c | 6 +- sha1_file.c | 100 +++++++++++++------------ t/helper/test-dump-untracked-cache.c | 4 +- 38 files changed, 300 insertions(+), 279 deletions(-)
base-commit: 5be1f00a9a701532232f57958efab4be8c959a29
Signature · 1 line
2.14.3
PATCH v4 1/12 sha1_file: convert pretend_sha1_file to object_id
Convert the declaration and definition of pretend_sha1_file to use struct object_id and adjust all usages of this function. Rename it to pretend_object_file.
--- Documentation/technical/api-object-access.txt | 2 +- blame.c | 2 +- cache.h | 5 ++++- sha1_file.c | 10 +++++----- 4 files changed, 11 insertions(+), 8 deletions(-)
Documentation/technical/api-object-access.txt +1 -1
@@ -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
blame.c +1 -1
@@ -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
cache.h +4 -1
@@ -1241,7 +1241,10 @@ 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 pretend_object_file (void *,unsigned long ,enum object_type , +struct object_id *oid); +extern int force_object_loose (const unsigned char *sha1,time_t mtime);extern int git_open_cloexec (const char *name,int flags);#define git_open (name) git_open_cloexec(name, O_RDONLY)
sha1_file.c +5 -5
@@ -1312,13 +1312,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_sha1_file (buf, len,typename (type), oid->hash); +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++];
@@ -1326,7 +1326,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 ; }
Signature · 1 line
2.14.3
PATCH v4 2/12 dir: convert struct sha1_stat to use object_id
In reply to Patryk ObaraConvert the declaration of struct sha1_stat. Adjust all usages of this struct and replace hash{clr,cmp,cpy} with oid{clr,cmp,cpy} wherever possible. Rename it to struct oid_stat.
Rename static function load_sha1_stat to load_oid_stat.
Remove macro EMPTY_BLOB_SHA1_BIN, as it's no longer used.
--- cache.h | 2 - dir.c | 104 +++++++++++++++++------------------ dir.h | 12 ++-- t/helper/test-dump-untracked-cache.c | 4 +- 4 files changed, 58 insertions(+), 64 deletions(-)
cache.h +0 -2
@@ -1047,8 +1047,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) {
dir.c +50 -54
225 lines not on this page · raw message
dir.h +6 -6
@@ -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; };
t/helper/test-dump-untracked-cache.c +2 -2
@@ -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)
Signature · 1 line
2.14.3
PATCH v4 3/12 sha1_file: convert hash_sha1_file to object_id
In reply to Patryk ObaraConvert the declaration and definition of hash_sha1_file to use struct object_id and adjust all function calls.
Rename this function to hash_object_file.
--- apply.c | 4 ++-- builtin/index-pack.c | 5 ++--- builtin/replace.c | 2 +- builtin/unpack-objects.c | 2 +- cache-tree.c | 11 +++++------ cache.h | 5 ++++- convert.c | 6 +++--- diffcore-rename.c | 4 ++-- dir.c | 4 ++-- log-tree.c | 2 +- sha1_file.c | 26 +++++++++++++------------- 11 files changed, 36 insertions(+), 35 deletions(-)
apply.c +2 -2
@@ -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));
builtin/index-pack.c +2 -3
@@ -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 ();
builtin/replace.c +1 -1
@@ -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);
builtin/unpack-objects.c +1 -1
@@ -258,7 +258,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);
cache-tree.c +5 -6
@@ -400,15 +400,14 @@ 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); +hash_object_file (buffer.buf, buffer.len, tree_type, &it->oid);else if (write_sha1_file (buffer.buf, buffer.len, tree_type, it->oid.hash)) {strbuf_release (&buffer);return -1 ;
cache.h +4 -1
@@ -1236,7 +1236,10 @@ 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 hash_object_file (const void *buf,unsigned long len, +const char *type,struct object_id *oid); +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);
convert.c +3 -3
@@ -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);
diffcore-rename.c +2 -2
@@ -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); }
dir.c +2 -2
@@ -846,8 +846,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,oidcpy (&oid_stat->oid, &istate->cache[pos]->oid); else - hash_sha1_file(buf, size, "blob", - oid_stat->oid.hash); + hash_object_file(buf, size, "blob", + &oid_stat->oid);fill_stat_data (&oid_stat->stat, &st); oid_stat->valid =1 ; }
log-tree.c +1 -1
@@ -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 */
sha1_file.c +13 -13
@@ -788,7 +788,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;
@@ -796,8 +796,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 );
@@ -822,9 +822,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)
@@ -1317,7 +1317,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type, {struct cached_object *co; -hash_sha1_file (buf, len,typename (type), oid->hash); +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);
@@ -1485,12 +1485,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_sha1_file_prepare (buf, len, type, oid->hash, hdr, &hdrlen);return 0 ; }
@@ -1769,7 +1769,7 @@ 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);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;
@@ -1792,8 +1792,8 @@ static int index_stream_convert_blob(struct object_id *oid, int fd, ret =write_sha1_file (sbuf.buf, sbuf.len,typename (OBJ_BLOB ), oid->hash); 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; }
@@ -1907,7 +1907,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigneif (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); +hash_object_file (sb.buf, sb.len, blob_type, oid);else if (write_sha1_file (sb.buf, sb.len, blob_type, oid->hash)) rc =error ("%s: failed to insert into database" , path);strbuf_release (&sb);
Signature · 1 line
2.14.3
PATCH v4 4/12 cache: clear whole hash buffer with oidclr
In reply to Patryk ObaraAs long as GIT_SHA1_RAWSZ is equal to GIT_MAX_RAWSZ there's no problem, but when new hashing algorithm will be in place this memset will clear only 20-byte prefix of hash buffer.
Alternatively, hashclr implementation could be adjusted, but this function is almost removed from codebase already. Separate implementation of oidclr prevents potential buffer overrun in case someone incorrectly used hashclr on object_id in future.
--- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cache.h +1 -1
@@ -1029,7 +1029,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 ); }
Signature · 1 line
2.14.3
PATCH v4 5/12 match-trees: convert splice_tree to object_id
In reply to Patryk ObaraConvert the definition of static recursive splice_tree function to use struct object_id and adjust single caller.
--- match-trees.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-)
match-trees.c +22 -24
@@ -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_sha1_file (buf, sz, tree_type, result->hash);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
Signature · 1 line
2.14.3
PATCH v4 6/12 commit: convert commit_tree* to object_id
In reply to Patryk ObaraConvert the definitions and declarations of commit_tree and commit_tree_extended to use struct object_id and adjust all usages of these functions.
--- builtin/am.c | 4 ++-- builtin/commit-tree.c | 4 ++-- builtin/commit.c | 5 +++-- builtin/merge.c | 8 ++++---- commit.c | 15 +++++++-------- commit.h | 11 ++++++----- notes-cache.c | 4 ++-- notes-merge.c | 9 ++++----- notes-utils.c | 7 ++++--- notes-utils.h | 3 ++- 10 files changed, 36 insertions(+), 34 deletions(-)
builtin/am.c +2 -2
@@ -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" );
builtin/commit-tree.c +2 -2
@@ -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 ; }
builtin/commit.c +3 -2
@@ -1794,8 +1794,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" )); }
builtin/merge.c +4 -4
@@ -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);
commit.c +7 -8
@@ -1380,9 +1380,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;
@@ -1511,8 +1510,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) {
@@ -1520,7 +1519,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." );
@@ -1529,7 +1528,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
@@ -1568,7 +1567,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_sha1_file (buffer.buf, buffer.len, commit_type, ret->hash); out:strbuf_release (&buffer);return result;
commit.h +6 -5
@@ -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 **);
notes-cache.c +2 -2
@@ -56,8 +56,8 @@ int notes_cache_write(struct notes_cache *c)if (write_notes_tree (&c->tree, tree_oid.hash))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 )
notes-merge.c +4 -5
@@ -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",
notes-utils.c +4 -3
@@ -6,7 +6,7 @@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;
@@ -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 );
notes-utils.h +2 -1
@@ -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);
Signature · 1 line
2.14.3
PATCH v4 7/12 notes: convert combine_notes_* to object_id
In reply to Patryk ObaraConvert the definition and declarations of combine_notes_* functions to struct object_id and adjust usage of these functions.
--- notes.c | 46 +++++++++++++++++++++++----------------------- notes.h | 25 +++++++++++++++---------- 2 files changed, 38 insertions(+), 33 deletions(-)
notes.c +23 -23
@@ -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);
@@ -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_sha1_file (buf, buf_len, blob_type, cur_oid->hash);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_sha1_file (buf.buf, buf.len, blob_type, cur_oid->hash); out:strbuf_release (&buf);
notes.h +15 -10
@@ -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
Signature · 1 line
2.14.3
PATCH v4 8/12 notes: convert write_notes_tree to object_id
In reply to Patryk ObaraConvert the definition and declaration of write_notes_tree to struct object_id and adjust usage of this function.
Additionally, improve style of small part of this function, as old formatting made it hard to understand at glance what this part of code is doing.
--- notes-cache.c | 2 +- notes-utils.c | 2 +- notes.c | 16 +++++++++------- notes.h | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-)
notes-cache.c +1 -1
@@ -54,7 +54,7 @@ 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,NULL , &commit_oid,NULL ,NULL ) <0 )
notes-utils.c +1 -1
@@ -12,7 +12,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,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) {
notes.c +9 -7
@@ -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,13 @@ 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_sha1_file (root.buf.buf, root.buf.len, tree_type, + result->hash);strbuf_release (&root.buf);return ret; }
notes.h +2 -2
@@ -217,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. *
@@ -225,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
Signature · 1 line
2.14.3
PATCH v4 9/12 sha1_file: convert write_sha1_file to object_id
In reply to Patryk ObaraConvert the definition and declaration of write_sha1_file to struct object_id and adjust usage of this function.
This commit also converts static function write_sha1_file_prepare, as it is closely related.
Rename these functions to write_object_file andwrite_object_file_prepare respectively.
Replace sha1_to_hex, hashcpy and hashclr with their oid equivalents wherever possible.
--- apply.c | 8 ++++---- builtin/checkout.c | 3 +-- builtin/mktag.c | 6 +++--- builtin/mktree.c | 10 +++++----- builtin/notes.c | 8 ++++---- builtin/receive-pack.c | 11 ++++++----- builtin/replace.c | 2 +- builtin/tag.c | 2 +- builtin/unpack-objects.c | 9 ++++++--- cache-tree.c | 5 +++-- cache.h | 4 +++- commit.c | 2 +- match-trees.c | 2 +- merge-recursive.c | 5 +++-- notes-cache.c | 2 +- notes.c | 9 ++++----- read-cache.c | 6 +++--- sha1_file.c | 29 +++++++++++++++-------------- 18 files changed, 65 insertions(+), 58 deletions(-)
apply.c +4 -4
@@ -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);
builtin/checkout.c +1 -2
@@ -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 );
builtin/mktag.c +3 -3
@@ -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 ; }
builtin/mktree.c +5 -5
@@ -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_missint 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 */
builtin/notes.c +4 -4
@@ -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 ]);
builtin/receive-pack.c +6 -5
@@ -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",
builtin/replace.c +1 -1
@@ -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);
builtin/tag.c +1 -1
@@ -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 ; }
builtin/unpack-objects.c +6 -3
@@ -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);
cache-tree.c +3 -2
@@ -406,9 +406,10 @@ static int update_one(struct cache_tree *it,oidcpy (&it->oid, &oid); else to_invalidate =1 ; - }else if (dryrun) + }else if (dryrun) {hash_object_file (buffer.buf, buffer.len, tree_type, &it->oid); -else if (write_sha1_file (buffer.buf, buffer.len, tree_type, it->oid.hash)) { + }else if (write_object_file (buffer.buf, buffer.len, tree_type, + &it->oid)) {strbuf_release (&buffer);return -1 ; }
cache.h +3 -1
@@ -1240,7 +1240,9 @@ extern int sha1_object_info(const unsigned char *, unsigned long *);extern int hash_object_file (const void *buf,unsigned long len,const char *type,struct object_id *oid); -extern int write_sha1_file (const void *buf,unsigned long len,const char *type,unsigned char *return_sha1); +extern int write_object_file (const void *buf,unsigned long len, +const char *type,struct object_id *oid); +extern int hash_sha1_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,
commit.c +1 -1
@@ -1567,7 +1567,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->hash); + result =write_object_file (buffer.buf, buffer.len, commit_type, ret); out:strbuf_release (&buffer);return result;
match-trees.c +1 -1
@@ -214,7 +214,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, rewrite_with = oid2; }oidcpy (rewrite_here, rewrite_with); - status =write_sha1_file (buf, sz, tree_type, result->hash); + status =write_object_file (buf, sz, tree_type, result);free (buf);return status; }
merge-recursive.c +3 -2
@@ -1009,8 +1009,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);
notes-cache.c +1 -1
@@ -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 ); }
notes.c +4 -5
@@ -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);
@@ -825,7 +825,7 @@ int combine_notes_concatenate(struct object_id *cur_oid,free (new_msg);/* create a new blob object from buf */ - ret =write_sha1_file (buf, buf_len, blob_type, cur_oid->hash); + ret =write_object_file (buf, buf_len, blob_type, cur_oid);free (buf);return ret; }
@@ -905,7 +905,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid, string_list_join_lines_helper, &buf)) goto out; - ret =write_sha1_file (buf.buf, buf.len, blob_type, cur_oid->hash); + ret =write_object_file (buf.buf, buf.len, blob_type, cur_oid); out:strbuf_release (&buf);
@@ -1147,8 +1147,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result) 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_sha1_file (root.buf.buf, root.buf.len, tree_type, - result->hash); +write_object_file (root.buf.buf, root.buf.len, tree_type, result);strbuf_release (&root.buf);return ret; }
read-cache.c +3 -3
@@ -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)
sha1_file.c +15 -14
@@ -1419,9 +1419,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;
@@ -1432,7 +1432,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); }/*
@@ -1490,7 +1490,7 @@ int hash_object_file(const void *buf, unsigned long len, const char *type, {char hdr[32 ];int hdrlen =sizeof (hdr); -write_sha1_file_prepare (buf, len, type, oid->hash, hdr, &hdrlen); +write_object_file_prepare (buf, len, type, oid, hdr, &hdrlen);return 0 ; }
@@ -1633,7 +1633,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);
@@ -1641,10 +1642,10 @@ 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->hash, hdr, hdrlen, buf, len,0 ); } int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type,
@@ -1656,7 +1657,7 @@ 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;
@@ -1767,7 +1768,7 @@ 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_object_file (buf, size,typename (type), oid);if (re_allocated)
@@ -1789,8 +1790,8 @@ static int index_stream_convert_blob(struct object_id *oid, int fd, get_safe_crlf(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_object_file (sbuf.buf, sbuf.len,typename (OBJ_BLOB ), oid);
@@ -1908,7 +1909,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsignereturn error_errno ("readlink(\"%s\")" , path);if (!(flags &HASH_WRITE_OBJECT ))hash_object_file (sb.buf, sb.len, blob_type, oid); -else if (write_sha1_file (sb.buf, sb.len, blob_type, oid->hash)) +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 ;
Signature · 1 line
2.14.3
PATCH v4 10/12 sha1_file: convert force_object_loose to object_id
In reply to Patryk ObaraConvert the definition and declaration of force_object_loose to struct object_id and adjust usage of this function.
--- builtin/pack-objects.c | 2 +- cache.h | 3 ++- sha1_file.c | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-)
builtin/pack-objects.c +1 -1
@@ -2768,7 +2768,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" ); } }
cache.h +2 -1
@@ -1248,7 +1248,8 @@ extern int hash_sha1_file_literally(const void *buf, unsigned long len, const chextern int pretend_object_file (void *,unsigned long ,enum object_type ,struct object_id *oid); -extern int force_object_loose (const unsigned char *sha1,time_t mtime); +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);
sha1_file.c +5 -5
@@ -1670,7 +1670,7 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typreturn 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;
@@ -1679,13 +1679,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->hash, hdr, hdrlen, buf, len, mtime);free (buf);return ret;
Signature · 1 line
2.14.3
PATCH v4 11/12 sha1_file: convert write_loose_object to object_id
In reply to Patryk ObaraConvert the definition and declaration of static write_loose_object function to struct object_id.
--- sha1_file.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
sha1_file.c +16 -12
@@ -1548,16 +1548,17 @@ 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 ; -const char *filename =sha1_file_name (sha1); +const char *filename =sha1_file_name (oid->hash); fd =create_tmpfile (&tmp_file, filename);if (fd <0 ) {
@@ -1594,13 +1595,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);
@@ -1645,7 +1649,7 @@ int write_object_file(const void *buf, unsigned long len, const char *type,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 (oid->hash, 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,
@@ -1663,7 +1667,7 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typ 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);
@@ -1685,7 +1689,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)if (!buf)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 (oid->hash, hdr, hdrlen, buf, len, mtime); + ret =write_loose_object (oid, hdr, hdrlen, buf, len, mtime);free (buf);return ret;
Signature · 1 line
2.14.3
PATCH v4 12/12 sha1_file: rename hash_sha1_file_literally
In reply to Patryk ObaraThis function was already converted to use struct object_id earlier.
--- builtin/hash-object.c | 3 ++- cache.h | 4 +++- sha1_file.c | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-)
builtin/hash-object.c +2 -1
@@ -24,7 +24,8 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsigif (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; }
cache.h +3 -1
@@ -1243,7 +1243,9 @@ extern int hash_object_file(const void *buf, unsigned long len,extern int write_object_file (const void *buf,unsigned long len,const char *type,struct object_id *oid); -extern int hash_sha1_file_literally (const void *buf,unsigned long len,const char *type,struct object_id *oid,unsigned flags); +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);
sha1_file.c +3 -2
@@ -1652,8 +1652,9 @@ int write_object_file(const void *buf, unsigned long len, const char *type,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 ;
Signature · 1 line
2.14.3