From: brian m. carlson <hidden> Date: 2018-05-02 00:26:23
This is the thirteenth series of patches to convert to struct object_id
and the_hash_algo.
The series adds an oidread function to read object IDs from a buffer,
removes unused structure members (which therefore don't require
conversion), converts various functions to struct object_id, and
improves usage of the_hash_algo. It also makes empty_blob_oid and
empty_tree_oid static, exposed only through the hash algorithm
abstraction, and updates all the hard-coded instances of the empty blob
and empty tree object IDs in scripts (excepting the testsuite).
Changes from v1:
* Add missing sign-off.
* Removed unneeded braces from init_pack_info.
* Express 51 in terms of the_hash_algo->hexsz.
* Fix comments referring to SHA-1.
* Update commit messages as suggested.
* Add and use empty_tree_oid_hex and empty_blob_oid_hex.
brian m. carlson (42):
cache: add a function to read an object ID from a buffer
server-info: remove unused members from struct pack_info
Remove unused member in struct object_context
packfile: remove unused member from struct pack_entry
packfile: convert has_sha1_pack to object_id
sha1-file: convert freshen functions to object_id
packfile: convert find_pack_entry to object_id
packfile: abstract away hash constant values
pack-objects: abstract away hash algorithm
pack-redundant: abstract away hash algorithm
tree-walk: avoid hard-coded 20 constant
tree-walk: convert get_tree_entry_follow_symlinks to object_id
fsck: convert static functions to struct object_id
submodule-config: convert structures to object_id
split-index: convert struct split_index to object_id
Update struct index_state to use struct object_id
pack-redundant: convert linked lists to use struct object_id
index-pack: abstract away hash function constant
commit: convert uses of get_sha1_hex to get_oid_hex
dir: convert struct untracked_cache_dir to object_id
http: eliminate hard-coded constants
revision: replace use of hard-coded constants
upload-pack: replace use of several hard-coded constants
diff: specify abbreviation size in terms of the_hash_algo
builtin/receive-pack: avoid hard-coded constants for push certs
sha1-file: add functions for hex empty tree and blob OIDs
builtin/am: convert uses of EMPTY_TREE_SHA1_BIN to the_hash_algo
builtin/merge: switch tree functions to use object_id
merge: convert empty tree constant to the_hash_algo
sequencer: convert one use of EMPTY_TREE_SHA1_HEX
submodule: convert several uses of EMPTY_TREE_SHA1_HEX
wt-status: convert two uses of EMPTY_TREE_SHA1_HEX
builtin/receive-pack: convert one use of EMPTY_TREE_SHA1_HEX
builtin/reset: convert use of EMPTY_TREE_SHA1_BIN
sha1_file: convert cached object code to struct object_id
cache-tree: use is_empty_tree_oid
sequencer: use the_hash_algo for empty tree object ID
dir: use the_hash_algo for empty blob object ID
sha1_file: only expose empty object constants through git_hash_algo
Update shell scripts to compute empty tree object ID
add--interactive: compute the empty tree value
merge-one-file: compute empty blob object ID
builtin/am.c | 8 +--
builtin/count-objects.c | 2 +-
builtin/fsck.c | 2 +-
builtin/index-pack.c | 3 +-
builtin/merge.c | 14 ++---
builtin/pack-objects.c | 32 +++++------
builtin/pack-redundant.c | 62 +++++++++++----------
builtin/prune-packed.c | 2 +-
builtin/receive-pack.c | 8 +--
builtin/reset.c | 2 +-
builtin/rev-parse.c | 4 +-
cache-tree.c | 4 +-
cache.h | 28 ++++------
commit.c | 4 +-
diff.c | 20 ++++---
dir.c | 25 ++++-----
dir.h | 5 +-
fsck.c | 20 +++----
git-add--interactive.perl | 11 +++-
git-filter-branch.sh | 4 +-
git-merge-one-file.sh | 2 +-
git-rebase--interactive.sh | 4 +-
http.c | 13 ++---
merge.c | 5 +-
packfile.c | 79 ++++++++++++++-------------
packfile.h | 4 +-
read-cache.c | 34 ++++++------
resolve-undo.c | 2 +-
revision.c | 7 +--
sequencer.c | 4 +-
server-info.c | 9 +---
sha1-file.c | 81 +++++++++++++++++-----------
sha1-name.c | 5 +-
split-index.c | 10 ++--
split-index.h | 4 +-
submodule-config.c | 66 +++++++++++------------
submodule-config.h | 7 +--
submodule.c | 6 +--
t/helper/test-dump-split-index.c | 4 +-
t/helper/test-dump-untracked-cache.c | 2 +-
templates/hooks--pre-commit.sample | 2 +-
tree-walk.c | 18 +++----
tree-walk.h | 2 +-
unpack-trees.c | 2 +-
upload-pack.c | 18 +++----
wt-status.c | 4 +-
46 files changed, 348 insertions(+), 306 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:30
In various places throughout the codebase, we need to read data into a
struct object_id from a pack or other unsigned char buffer. Add an
inline function that does this based on the current hash algorithm in
use, and use it in several places.
Signed-off-by: brian m. carlson <redacted>
---
cache-tree.c | 2 +-
cache.h | 5 +++++
resolve-undo.c | 2 +-
3 files changed, 7 insertions(+), 2 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:30
The head member of struct pack_info is completely unused and the
nr_heads member is used only in one place, which is an assignment. This
member was last usefully used in 3e15c67c90 (server-info: throw away T
computation as well, 2005-12-04).
Since this structure member is not useful, remove it.
Signed-off-by: brian m. carlson <redacted>
---
server-info.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:33
Convert the various functions for freshening objects and
has_loose_object_nonlocal to use struct object_id.
Signed-off-by: brian m. carlson <redacted>
---
builtin/pack-objects.c | 2 +-
cache.h | 2 +-
sha1-file.c | 36 ++++++++++++++++++------------------
3 files changed, 20 insertions(+), 20 deletions(-)
@@ -709,42 +709,42 @@ int check_and_freshen_file(const char *fn, int freshen)return1;}-staticintcheck_and_freshen_local(constunsignedchar*sha1,intfreshen)+staticintcheck_and_freshen_local(conststructobject_id*oid,intfreshen){staticstructstrbufbuf=STRBUF_INIT;strbuf_reset(&buf);-sha1_file_name(the_repository,&buf,sha1);+sha1_file_name(the_repository,&buf,oid->hash);returncheck_and_freshen_file(buf.buf,freshen);}-staticintcheck_and_freshen_nonlocal(constunsignedchar*sha1,intfreshen)+staticintcheck_and_freshen_nonlocal(conststructobject_id*oid,intfreshen){structalternate_object_database*alt;prepare_alt_odb(the_repository);for(alt=the_repository->objects->alt_odb_list;alt;alt=alt->next){-constchar*path=alt_sha1_path(alt,sha1);+constchar*path=alt_sha1_path(alt,oid->hash);if(check_and_freshen_file(path,freshen))return1;}return0;}-staticintcheck_and_freshen(constunsignedchar*sha1,intfreshen)+staticintcheck_and_freshen(conststructobject_id*oid,intfreshen){-returncheck_and_freshen_local(sha1,freshen)||-check_and_freshen_nonlocal(sha1,freshen);+returncheck_and_freshen_local(oid,freshen)||+check_and_freshen_nonlocal(oid,freshen);}-inthas_loose_object_nonlocal(constunsignedchar*sha1)+inthas_loose_object_nonlocal(conststructobject_id*oid){-returncheck_and_freshen_nonlocal(sha1,0);+returncheck_and_freshen_nonlocal(oid,0);}-staticinthas_loose_object(constunsignedchar*sha1)+staticinthas_loose_object(conststructobject_id*oid){-returncheck_and_freshen(sha1,0);+returncheck_and_freshen(oid,0);}staticvoidmmap_limit_check(size_tlength)
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:34
Convert find_pack_entry and the static function fill_pack_entry to take
pointers to struct object_id.
Signed-off-by: brian m. carlson <redacted>
---
packfile.c | 12 ++++++------
packfile.h | 2 +-
sha1-file.c | 6 +++---
3 files changed, 10 insertions(+), 10 deletions(-)
@@ -1281,7 +1281,7 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi/* Not a loose object; someone else may have just packed it. */if(!(flags&OBJECT_INFO_QUICK)){reprepare_packed_git(the_repository);-if(find_pack_entry(the_repository,real->hash,&e))+if(find_pack_entry(the_repository,real,&e))break;}
@@ -1669,7 +1669,7 @@ static int freshen_loose_object(const struct object_id *oid)staticintfreshen_packed_object(conststructobject_id*oid){structpack_entrye;-if(!find_pack_entry(the_repository,oid->hash,&e))+if(!find_pack_entry(the_repository,oid,&e))return0;if(e.p->freshened)return1;
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:36
Use the_hash_algo to look up the length of our current hash instead of
hard-coding the value 20.
Signed-off-by: brian m. carlson <redacted>
---
tree-walk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:37
Convert this function to take a pointer to struct object_id and rename
it has_object_pack for consistency with has_object_file.
Signed-off-by: brian m. carlson <redacted>
---
builtin/count-objects.c | 2 +-
builtin/fsck.c | 2 +-
builtin/prune-packed.c | 2 +-
diff.c | 2 +-
packfile.c | 4 ++--
packfile.h | 2 +-
revision.c | 2 +-
7 files changed, 8 insertions(+), 8 deletions(-)
@@ -227,7 +227,7 @@ static void check_reachable_object(struct object *obj)if(!(obj->flags&HAS_OBJ)){if(is_promisor_object(&obj->oid))return;-if(has_sha1_pack(obj->oid.hash))+if(has_object_pack(&obj->oid))return;/* it is in pack - forget about it */printf("missing %s %s\n",printable_type(obj),describe_object(obj));
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:39
Convert two static functions to use struct object_id and parse_oid_hex,
instead of relying on harcoded 20 and 40-based constants.
Signed-off-by: brian m. carlson <redacted>
---
fsck.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
@@ -711,30 +711,31 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_optionstaticintfsck_commit_buffer(structcommit*commit,constchar*buffer,unsignedlongsize,structfsck_options*options){-unsignedchartree_sha1[20],sha1[20];+structobject_idtree_oid,oid;structcommit_graft*graft;unsignedparent_count,parent_line_count=0,author_count;interr;constchar*buffer_begin=buffer;+constchar*p;if(verify_headers(buffer,size,&commit->object,options))return-1;if(!skip_prefix(buffer,"tree ",&buffer))returnreport(options,&commit->object,FSCK_MSG_MISSING_TREE,"invalid format - expected 'tree' line");-if(get_sha1_hex(buffer,tree_sha1)||buffer[40]!='\n'){+if(parse_oid_hex(buffer,&tree_oid,&p)||*p!='\n'){err=report(options,&commit->object,FSCK_MSG_BAD_TREE_SHA1,"invalid 'tree' line format - bad sha1");if(err)returnerr;}-buffer+=41;+buffer=p+1;while(skip_prefix(buffer,"parent ",&buffer)){-if(get_sha1_hex(buffer,sha1)||buffer[40]!='\n'){+if(parse_oid_hex(buffer,&oid,&p)||*p!='\n'){err=report(options,&commit->object,FSCK_MSG_BAD_PARENT_SHA1,"invalid 'parent' line format - bad sha1");if(err)returnerr;}-buffer+=41;+buffer=p+1;parent_line_count++;}graft=lookup_commit_graft(&commit->object.oid);
@@ -773,7 +774,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,if(err)returnerr;if(!commit->tree){-err=report(options,&commit->object,FSCK_MSG_BAD_TREE,"could not load commit's tree %s",sha1_to_hex(tree_sha1));+err=report(options,&commit->object,FSCK_MSG_BAD_TREE,"could not load commit's tree %s",oid_to_hex(&tree_oid));if(err)returnerr;}
@@ -834,12 +836,12 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,ret=report(options,&tag->object,FSCK_MSG_MISSING_OBJECT,"invalid format - expected 'object' line");gotodone;}-if(get_sha1_hex(buffer,sha1)||buffer[40]!='\n'){+if(parse_oid_hex(buffer,&oid,&p)||*p!='\n'){ret=report(options,&tag->object,FSCK_MSG_BAD_OBJECT_SHA1,"invalid 'object' line format - bad sha1");if(ret)gotodone;}-buffer+=41;+buffer=p+1;if(!skip_prefix(buffer,"type ",&buffer)){ret=report(options,&tag->object,FSCK_MSG_MISSING_TYPE_ENTRY,"invalid format - expected 'type' line");
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:45
Convert struct llist_item and the rest of the linked list code to use
struct object_id. Add a use of GIT_MAX_HEXSZ to avoid a dependency on a
hard-coded constant.
Signed-off-by: brian m. carlson <redacted>
---
builtin/pack-redundant.c | 50 +++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 24 deletions(-)
@@ -131,21 +131,21 @@ static inline struct llist_item *llist_insert(struct llist *list,}staticinlinestructllist_item*llist_insert_back(structllist*list,-constunsignedchar*sha1)+conststructobject_id*oid){-returnllist_insert(list,list->back,sha1);+returnllist_insert(list,list->back,oid);}staticinlinestructllist_item*llist_insert_sorted_unique(structllist*list,-constunsignedchar*sha1,structllist_item*hint)+conststructobject_id*oid,structllist_item*hint){structllist_item*prev=NULL,*l;l=(hint==NULL)?list->front:hint;while(l){-intcmp=hashcmp(l->sha1,sha1);+intcmp=oidcmp(l->oid,oid);if(cmp>0){/* we insert before this entry */-returnllist_insert(list,prev,sha1);+returnllist_insert(list,prev,oid);}if(!cmp){/* already exists */returnl;
@@ -154,11 +154,11 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,l=l->next;}/* insert at the end */-returnllist_insert_back(list,sha1);+returnllist_insert_back(list,oid);}/* returns a pointer to an item in front of sha1 */-staticinlinestructllist_item*llist_sorted_remove(structllist*list,constunsignedchar*sha1,structllist_item*hint)+staticinlinestructllist_item*llist_sorted_remove(structllist*list,conststructobject_id*oid,structllist_item*hint){structllist_item*prev,*l;
@@ -166,7 +166,7 @@ static inline struct llist_item * llist_sorted_remove(struct llist *list, constl=(hint==NULL)?list->front:hint;prev=NULL;while(l){-intcmp=hashcmp(l->sha1,sha1);+intcmp=oidcmp(l->oid,oid);if(cmp>0)/* not in list, since sorted */returnprev;if(!cmp){/* found */
@@ -562,7 +564,7 @@ static struct pack_list * add_pack(struct packed_git *p)base+=256*4+((p->index_version<2)?4:8);step=the_hash_algo->rawsz+((p->index_version<2)?4:0);while(off<p->num_objects*step){-llist_insert_back(l.all_objects,base+off);+llist_insert_back(l.all_objects,(conststructobject_id*)(base+off));off+=step;}/* this list will be pruned in cmp_two_packs later */
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:49
Convert the base_sha1 member of struct split_index to use struct
object_id and rename it base_oid. Include cache.h to make the structure
visible.
Signed-off-by: brian m. carlson <redacted>
---
builtin/rev-parse.c | 4 ++--
read-cache.c | 22 +++++++++++-----------
split-index.c | 10 +++++-----
split-index.h | 4 +++-
t/helper/test-dump-split-index.c | 2 +-
5 files changed, 22 insertions(+), 20 deletions(-)
@@ -2595,7 +2595,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,/* Freshen the shared index only if the split-index was written */if(!ret&&!new_shared_index){constchar*shared_index=git_path("sharedindex.%s",-sha1_to_hex(si->base_sha1));+oid_to_hex(&si->base_oid));freshen_shared_index(shared_index,1);}
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:51
Convert struct submodule and struct parse_config_parameter to use struct
object_id. Adjust the functions which take members of these structures
as arguments to also use struct object_id. Include cache.h into
submodule-config.h to make struct object_id visible.
Signed-off-by: brian m. carlson <redacted>
---
submodule-config.c | 66 +++++++++++++++++++++++-----------------------
submodule-config.h | 7 ++---
2 files changed, 37 insertions(+), 36 deletions(-)
@@ -341,12 +341,12 @@ int parse_push_recurse_submodules_arg(const char *opt, const char *arg)returnparse_push_recurse(opt,arg,1);}-staticvoidwarn_multiple_config(constunsignedchar*treeish_name,+staticvoidwarn_multiple_config(conststructobject_id*treeish_name,constchar*name,constchar*option){constchar*commit_string="WORKTREE";if(treeish_name)-commit_string=sha1_to_hex(treeish_name);+commit_string=oid_to_hex(treeish_name);warning("%s:.gitmodules, multiple configurations found for ""'submodule.%s.%s'. Skipping second one!",commit_string,name,option);
@@ -389,7 +389,7 @@ static int parse_config(const char *var, const char *value, void *data)}}elseif(!strcmp(item.buf,"fetchrecursesubmodules")){/* when parsing worktree configurations we can die early */-intdie_on_error=is_null_sha1(me->gitmodules_sha1);+intdie_on_error=is_null_oid(me->gitmodules_oid);if(!me->overwrite&&submodule->fetch_recurse!=RECURSE_SUBMODULES_NONE)warn_multiple_config(me->treeish_name,submodule->name,
@@ -526,8 +526,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,/* fill the submodule config into the cache */parameter.cache=cache;-parameter.treeish_name=treeish_name->hash;-parameter.gitmodules_sha1=oid.hash;+parameter.treeish_name=treeish_name;+parameter.gitmodules_oid=&oid;parameter.overwrite=0;git_config_from_mem(parse_config,CONFIG_ORIGIN_SUBMODULE_BLOB,rev.buf,config,config_size,¶meter);
@@ -17,13 +18,13 @@ struct submodule {constchar*ignore;constchar*branch;structsubmodule_update_strategyupdate_strategy;-/* the sha1 blob id of the responsible .gitmodules file */-unsignedchargitmodules_sha1[20];+/* the object id of the responsible .gitmodules file */+structobject_idgitmodules_oid;intrecommend_shallow;};#define SUBMODULE_INIT { NULL, NULL, NULL, RECURSE_SUBMODULES_NONE, \-NULL,NULL,SUBMODULE_UPDATE_STRATEGY_INIT,{0},-1};+NULL,NULL,SUBMODULE_UPDATE_STRATEGY_INIT,{{0}},-1};structsubmodule_cache;structrepository;
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:54
The code for reading certain pack v2 offsets had a hard-coded 5
representing the number of uint32_t words that we needed to skip over.
Specify this value in terms of a value from the_hash_algo.
Signed-off-by: brian m. carlson <redacted>
---
builtin/index-pack.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:57
Since the only caller of this function already uses struct object_id,
update get_tree_entry_follow_symlinks to use it in parameters and
internally.
Signed-off-by: brian m. carlson <redacted>
---
sha1-name.c | 4 ++--
tree-walk.c | 16 ++++++++--------
tree-walk.h | 2 +-
3 files changed, 11 insertions(+), 11 deletions(-)
@@ -663,7 +663,7 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s/* We could end up here via a symlink to dir/.. */if(namebuf.buf[0]=='\0'){-hashcpy(result,parents[parents_nr-1].sha1);+oidcpy(result,&parents[parents_nr-1].oid);retval=FOUND;gotodone;}
From: brian m. carlson <hidden> Date: 2018-05-02 00:26:58
Instead of using hard-coded instances of the constant 20, use
the_hash_algo to look up the correct constant.
Signed-off-by: brian m. carlson <redacted>
---
builtin/pack-redundant.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:00
Instead of using hard-coded instances of the constant 20, use
the_hash_algo to look up the correct constant.
Signed-off-by: brian m. carlson <redacted>
---
builtin/pack-objects.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:03
Convert several uses of EMPTY_TREE_SHA1_BIN to use the_hash_algo
and struct object_id instead.
Signed-off-by: brian m. carlson <redacted>
---
builtin/am.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:06
The read_empty and reset_hard functions are static and their callers
have already changed to use struct object_id, so convert them as well.
To avoid dependency on the hash algorithm in use, switch from using
EMPTY_TREE_SHA1_HEX to using empty_tree_oid_hex.
Signed-off-by: brian m. carlson <redacted>
---
builtin/merge.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:11
Use the GIT_SHA1_RAWSZ and GIT_SHA1_HEXSZ macros instead of hard-coding
the constants 20 and 40. Switch one use of 20 with a format specifier
for a hex value to use the hex constant instead, as the original appears
to have been a typo.
At this point, avoid converting the hard-coded use of SHA-1 to use
the_hash_algo. SHA-1, even if not collision resistant, is secure in the
context in which it is used here, and the hash algorithm of the repo
need not match what is used here. When we adopt a new hash algorithm,
we can simply adopt the new algorithm wholesale here, as the nonce is
opaque and its length and validity are entirely controlled by the
server. Consequently, defer updating this code until that point.
Signed-off-by: brian m. carlson <redacted>
---
builtin/receive-pack.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:12
Convert the code that looks up cached objects to use struct object_id.
Adjust the lookup for empty trees to use the_hash_algo. Note that we
don't need to be concerned about the hard-coded object ID in the
empty_tree object since we never use it.
Signed-off-by: brian m. carlson <redacted>
---
sha1-file.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:16
To ensure that we are hash algorithm agnostic, use the_hash_algo to look
up the object ID for the empty blob instead of using the empty_tree_oid
variable.
Signed-off-by: brian m. carlson <redacted>
---
dir.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:17
To ensure that we are hash algorithm agnostic, use the_hash_algo to look
up the object ID for the empty tree instead of using the empty_tree_oid
variable.
Signed-off-by: brian m. carlson <redacted>
---
sequencer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:20
When comparing an object ID against that of the empty tree, use the
is_empty_tree_oid function to ensure that we abstract over the hash
algorithm properly. In addition, this is more readable than a plain
oidcmp.
Signed-off-by: brian m. carlson <redacted>
---
cache-tree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:23
The interactive add script hard-codes the object ID of the empty tree.
To avoid any problems when changing hashes, compute this value when used
and cache it for any future uses.
Signed-off-by: brian m. carlson <redacted>
---
git-add--interactive.perl | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:25
There really isn't any case in which we want to expose the constants for
empty trees and blobs outside of using the hash algorithm abstraction.
Make these constants static and stop exposing the defines in cache.h.
Remove the constants which are no longer in use.
Signed-off-by: brian m. carlson <redacted>
---
cache.h | 16 ----------------
sha1-file.c | 13 +++++++++++--
2 files changed, 11 insertions(+), 18 deletions(-)
@@ -35,12 +35,21 @@/* The maximum size for an object header. */#define MAX_HEADER_LEN 32++#define EMPTY_TREE_SHA1_BIN_LITERAL \+"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60"\+"\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"++#define EMPTY_BLOB_SHA1_BIN_LITERAL \+"\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b"\+"\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91"+constunsignedcharnull_sha1[GIT_MAX_RAWSZ];conststructobject_idnull_oid;-conststructobject_idempty_tree_oid={+staticconststructobject_idempty_tree_oid={EMPTY_TREE_SHA1_BIN_LITERAL};-conststructobject_idempty_blob_oid={+staticconststructobject_idempty_blob_oid={EMPTY_BLOB_SHA1_BIN_LITERAL};
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:30
Oftentimes, we'll want to refer to an empty tree or empty blob by its
hex name without having to call oid_to_hex or explicitly refer to
the_hash_algo. Add helper functions that format these values into
static buffers and return them for easy use.
Signed-off-by: brian m. carlson <redacted>
---
cache.h | 3 +++
sha1-file.c | 12 ++++++++++++
2 files changed, 15 insertions(+)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:31
This script hard-codes the object ID of the empty blob. To avoid any
problems when changing hashes, compute this value by calling git
hash-object.
Signed-off-by: brian m. carlson <redacted>
---
git-merge-one-file.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -120,7 +120,7 @@ case "${1:-.}${2:-.}${3:-.}" incase"$1"in'')echo"Added $4 in both, but differently."-orig=$(gitunpack-filee69de29bb2d1d6434b8b29ae775ad8c2e48c5391)+orig=$(gitunpack-file$(githash-object/dev/null));;*)echo"Auto-merging $4"
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:32
Several of our shell scripts hard-code the object ID of the empty tree.
To avoid any problems when changing hashes, compute this value on
startup of the script. For performance, store the value in a variable
and reuse it throughout the life of the script.
Signed-off-by: brian m. carlson <redacted>
---
git-filter-branch.sh | 4 +++-
git-rebase--interactive.sh | 4 +++-
templates/hooks--pre-commit.sample | 2 +-
3 files changed, 7 insertions(+), 3 deletions(-)
@@ -11,6 +11,8 @@# The following functions will also be available in the commit filter:functions=$(cat<<\EOF+EMPTY_TREE=$(githash-object-ttree/dev/null)+ warn(){echo"$*">&2}
@@ -81,6 +81,8 @@ rewritten_pending="$state_dir"/rewritten-pending# and leaves CR at the end instead.cr=$(printf"\015")+empty_tree=$(githash-object-ttree/dev/null)+strategy_args=${strategy:+--strategy=$strategy}test-n"$strategy_opts"&&eval'
@@ -238,7 +240,7 @@ is_empty_commit() {die"$(eval_gettext"\$sha1: not a commit that can be picked")"}ptree=$(gitrev-parse-q--verify"$1"^^{tree}2>/dev/null)||-ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904+ptree=$empty_treetest"$tree"="$ptree"}
@@ -12,7 +12,7 @@ then against=HEAD else # Initial commit: diff against an empty tree object- against=4b825dc642cb6eb9a060e54bf8d69288fbee4904+ against=$(git hash-object -t tree /dev/null) fi # If you want to allow non-ASCII filenames set this variable to true.
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:38
Convert the last use of EMPTY_TREE_SHA1_BIN to use a direct copy from
the_hash_algo->empty_tree to avoid a dependency on a given hash
algorithm.
Signed-off-by: brian m. carlson <redacted>
---
builtin/reset.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -314,7 +314,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)unborn=!strcmp(rev,"HEAD")&&get_oid("HEAD",&oid);if(unborn){/* reset on unborn branch: treat as reset to empty tree */-hashcpy(oid.hash,EMPTY_TREE_SHA1_BIN);+oidcpy(&oid,the_hash_algo->empty_tree);}elseif(!pathspec.nr){structcommit*commit;if(get_oid_committish(rev,&oid))
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:40
Convert one use of EMPTY_TREE_SHA1_HEX to use empty_tree_oid_hex to
avoid a dependency on a given hash algorithm.
Signed-off-by: brian m. carlson <redacted>
---
builtin/receive-pack.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -968,7 +968,7 @@ static const char *push_to_deploy(unsigned char *sha1,return"Working directory has unstaged changes";/* diff-index with either HEAD or an empty tree */-diff_index[4]=head_has_history()?"HEAD":EMPTY_TREE_SHA1_HEX;+diff_index[4]=head_has_history()?"HEAD":empty_tree_oid_hex();child_process_init(&child);child.argv=diff_index;
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:41
Convert two uses of EMPTY_TREE_SHA1_HEX to use empty_tree_oid_hex to
avoid a dependency on a given hash algorithm.
Signed-off-by: brian m. carlson <redacted>
---
wt-status.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:44
Convert several uses of EMPTY_TREE_SHA1_HEX to use empty_tree_oid_hex to
avoid a dependency on a given hash algorithm.
Signed-off-by: brian m. carlson <redacted>
---
submodule.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:50
Convert one use of EMPTY_TREE_SHA1_HEX to use empty_tree_oid_hex to
avoid a dependency on a given hash algorithm.
Signed-off-by: brian m. carlson <redacted>
---
sequencer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:53
To avoid dependency on a particular hash algorithm, convert a use of
EMPTY_TREE_SHA1_HEX to use the_hash_algo->empty_tree instead. Since
both branches now use oid_to_hex, condense the if statement into a
ternary.
Signed-off-by: brian m. carlson <redacted>
---
merge.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:27:59
Update several uses of hard-coded 40-based constants to use either
the_hash_algo or GIT_MAX_HEXSZ, as appropriate. Replace a combined use
of oid_to_hex and memcpy with oid_to_hex_r, which not only avoids the
need for a constant, but is more efficient. Make use of parse_oid_hex
to eliminate the need for constants and simplify the code at the same
time. Update some comments to no longer refer to SHA-1 as well.
Signed-off-by: brian m. carlson <redacted>
---
upload-pack.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
@@ -820,11 +822,9 @@ static void receive_needs(void)continue;}if(!skip_prefix(line,"want ",&arg)||-get_oid_hex(arg,&oid_buf))+parse_oid_hex(arg,&oid_buf,&features))die("git upload-pack: protocol error, "-"expected to get sha, not '%s'",line);--features=arg+40;+"expected to get object ID, not '%s'",line);if(parse_feature_request(features,"deepen-relative"))deepen_relative=1;
From: brian m. carlson <hidden> Date: 2018-05-02 00:28:00
Replace two uses of the hard-coded constant 40 with references to
the_hash_algo.
Signed-off-by: brian m. carlson <redacted>
---
revision.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:28:02
Instead of using hard-coded 40 constants, refer to the_hash_algo for the
current hash size.
Signed-off-by: brian m. carlson <redacted>
---
diff.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
@@ -2373,7 +2373,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,return-1;}-if(ce_flush(&c,newfd,istate->sha1))+if(ce_flush(&c,newfd,istate->oid.hash))return-1;if(close_tempfile_gently(tempfile)){error(_("could not close '%s'"),tempfile->filename.buf);
@@ -2497,10 +2497,10 @@ static int write_shared_index(struct index_state *istate,returnret;}ret=rename_tempfile(temp,-git_path("sharedindex.%s",sha1_to_hex(si->base->sha1)));+git_path("sharedindex.%s",oid_to_hex(&si->base->oid)));if(!ret){-hashcpy(si->base_oid.hash,si->base->sha1);-clean_shared_index_files(sha1_to_hex(si->base->sha1));+oidcpy(&si->base_oid,&si->base->oid);+clean_shared_index_files(oid_to_hex(&si->base->oid));}returnret;
From: brian m. carlson <hidden> Date: 2018-05-02 00:28:07
Use the_hash_algo to find the right size for parsing pack names.
Signed-off-by: brian m. carlson <redacted>
---
http.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:28:09
Convert the exclude_sha1 member of struct untracked_cache_dir and rename
it to exclude_oid. Eliminate several hard-coded integral constants, and
update a function name that referred to SHA-1.
Signed-off-by: brian m. carlson <redacted>
---
dir.c | 23 ++++++++++++-----------
dir.h | 5 +++--
t/helper/test-dump-untracked-cache.c | 2 +-
3 files changed, 16 insertions(+), 14 deletions(-)
@@ -3,6 +3,7 @@/* See Documentation/technical/api-directory-listing.txt */+#include"cache.h"#include"strbuf.h"structdir_entry{
@@ -118,8 +119,8 @@ struct untracked_cache_dir {/* all data except 'dirs' in this struct are good */unsignedintvalid:1;unsignedintrecurse:1;-/* null SHA-1 means this directory does not have .gitignore */-unsignedcharexclude_sha1[20];+/* null object ID means this directory does not have .gitignore */+structobject_idexclude_oid;charname[FLEX_ARRAY];};
From: brian m. carlson <hidden> Date: 2018-05-02 00:28:16
There are several instances of the constant 20 and 20-based values in
the packfile code. Abstract away dependence on SHA-1 by using the
values from the_hash_algo instead.
Use unsigned values for temporary constants to provide the compiler with
more information about what kinds of values it should expect.
Signed-off-by: brian m. carlson <redacted>
---
packfile.c | 66 ++++++++++++++++++++++++++++++------------------------
1 file changed, 37 insertions(+), 29 deletions(-)
@@ -444,10 +445,11 @@ static int open_packed_git_1(struct packed_git *p){structstatst;structpack_headerhdr;-unsignedcharsha1[20];-unsignedchar*idx_sha1;+unsignedcharhash[GIT_MAX_RAWSZ];+unsignedchar*idx_hash;longfd_flag;ssize_tread_result;+constunsignedhashsz=the_hash_algo->rawsz;if(!p->index_data&&open_pack_index(p))returnerror("packfile %s index unavailable",p->pack_name);
@@ -507,15 +509,15 @@ static int open_packed_git_1(struct packed_git *p)" while index indicates %"PRIu32" objects",p->pack_name,ntohl(hdr.hdr_entries),p->num_objects);-if(lseek(p->pack_fd,p->pack_size-sizeof(sha1),SEEK_SET)==-1)+if(lseek(p->pack_fd,p->pack_size-hashsz,SEEK_SET)==-1)returnerror("end of packfile %s is unavailable",p->pack_name);-read_result=read_in_full(p->pack_fd,sha1,sizeof(sha1));+read_result=read_in_full(p->pack_fd,hash,hashsz);if(read_result<0)returnerror_errno("error reading from %s",p->pack_name);-if(read_result!=sizeof(sha1))+if(read_result!=hashsz)returnerror("packfile %s signature is unavailable",p->pack_name);-idx_sha1=((unsignedchar*)p->index_data)+p->index_size-40;-if(hashcmp(sha1,idx_sha1))+idx_hash=((unsignedchar*)p->index_data)+p->index_size-hashsz*2;+if(hashcmp(hash,idx_hash))returnerror("packfile %s does not match index",p->pack_name);return0;}
@@ -530,7 +532,7 @@ static int open_packed_git(struct packed_git *p)staticintin_window(structpack_window*win,off_toffset){-/* We must promise at least 20 bytes (one hash) after the+/* We must promise at least one full hash after the*offsetisavailablefromthiswindow,otherwisetheoffset*isnotactuallyinthiswindowandadifferentwindow(which*hasthatonehashexcess)mustbeused.Thisistosupport
@@ -555,7 +557,7 @@ unsigned char *use_pack(struct packed_git *p,*/if(!p->pack_size&&p->pack_fd==-1&&open_packed_git(p))die("packfile %s cannot be accessed",p->pack_name);-if(offset>(p->pack_size-20))+if(offset>(p->pack_size-the_hash_algo->rawsz))die("offset beyond end of packfile (truncated pack?)");if(offset<0)die(_("offset before end of packfile (broken .idx?)"));
@@ -1066,7 +1070,7 @@ static off_t get_delta_base(struct packed_git *p,}elseif(type==OBJ_REF_DELTA){/* The base entry _must_ be in the same pack */base_offset=find_pack_entry_one(base_info,p);-*curpos+=20;+*curpos+=the_hash_algo->rawsz;}elsedie("I am totally screwed");returnbase_offset;
From: brian m. carlson <hidden> Date: 2018-05-02 00:28:21
The sha1 member in struct pack_entry is unused except for one instance
in which we store a value in it. Since nobody ever reads this value,
don't bother to compute it and remove the member from struct pack_entry.
Signed-off-by: brian m. carlson <redacted>
---
cache.h | 1 -
packfile.c | 1 -
2 files changed, 2 deletions(-)
From: brian m. carlson <hidden> Date: 2018-05-02 00:28:23
The tree member of struct object_context is unused except in one place
where we write to it. Since there are no users of this member, remove
it.
Signed-off-by: brian m. carlson <redacted>
---
cache.h | 1 -
sha1-name.c | 1 -
2 files changed, 2 deletions(-)
On Wed, May 02, 2018 at 12:25:28AM +0000, brian m. carlson wrote:
Changes from v1:
* Add missing sign-off.
* Removed unneeded braces from init_pack_info.
* Express 51 in terms of the_hash_algo->hexsz.
* Fix comments referring to SHA-1.
* Update commit messages as suggested.
* Add and use empty_tree_oid_hex and empty_blob_oid_hex.
Interdiff for people who don't have time to read 42 patches yet
@@ -968,7 +968,7 @@ static const char *push_to_deploy(unsigned char *sha1,return"Working directory has unstaged changes";/* diff-index with either HEAD or an empty tree */-diff_index[4]=head_has_history()?"HEAD":oid_to_hex(the_hash_algo->empty_tree);+diff_index[4]=head_has_history()?"HEAD":empty_tree_oid_hex();child_process_init(&child);child.argv=diff_index;
From: brian m. carlson <hidden> Date: 2018-05-02 23:42:51
On Wed, May 02, 2018 at 05:32:24PM +0200, Duy Nguyen wrote:
Interdiff for people who don't have time to read 42 patches yet
Thanks for this. I had intended to include tbdiff output in my series
but had forgotten when I reformatted the patches.
--
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204