read_tree(): pass "int stage" as context to read_tree_recursive()
PATCH v4 20/29 tree-walk.h API: rename get_tree_entry() to get_tree_entry_mode()
In reply to Ævar Arnfjörð BjarmasonRename the get_tree_entry() function to get_tree_entry_mode(). This change is only a search-replacement of the name and indentation of the argument lists.
A subsequent commits will add get_tree_entry_type() and get_tree_entry_all() functions. Those changes will be much easier to read if we do this rename first.
--- archive.c | 8 ++++---- blame.c | 6 +++--- builtin/rm.c | 2 +- builtin/update-index.c | 2 +- line-log.c | 2 +- match-trees.c | 6 +++--- merge-recursive.c | 18 +++++++++--------- notes.c | 2 +- object-name.c | 6 +++--- tree-walk.c | 14 +++++++------- tree-walk.h | 6 +++--- 11 files changed, 36 insertions(+), 36 deletions(-)
archive.c +4 -4
@@ -478,10 +478,10 @@ static void parse_treeish_arg(const char **argv,unsigned short mode;int err; - err =get_tree_entry (ar_args->repo, - &tree->object.oid, - prefix, &tree_oid, - &mode); + err =get_tree_entry_mode (ar_args->repo, + &tree->object.oid, + prefix, &tree_oid, + &mode);if (err || !S_ISDIR (mode))die (_ ("current working directory is untracked" ));
blame.c +3 -3
@@ -102,8 +102,8 @@ static void verify_working_tree_path(struct repository *r,const struct object_id *commit_oid = &parents->item->object.oid;struct object_id blob_oid;unsigned short mode; -int ret =get_tree_entry (r, commit_oid, path, &blob_oid, - &mode); +int ret =get_tree_entry_mode (r, commit_oid, path, &blob_oid, + &mode);if (!ret &&oid_object_info (r, &blob_oid,NULL ) ==OBJ_BLOB )return ;
@@ -1239,7 +1239,7 @@ static int fill_blob_sha1_and_mode(struct repository *r, {if (!is_null_oid (&origin->blob_oid))return 0 ; -if (get_tree_entry (r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode)) +if (get_tree_entry_mode (r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode)) goto error_out;if (oid_object_info (r, &origin->blob_oid,NULL ) !=OBJ_BLOB ) goto error_out;
builtin/rm.c +1 -1
@@ -179,7 +179,7 @@ static int check_local_mod(struct object_id *head, int index_only)* way as changed from the HEAD. */ if (no_head - ||get_tree_entry (the_repository, head, name, &oid, &mode) + ||get_tree_entry_mode (the_repository, head, name, &oid, &mode) || ce->ce_mode !=create_ce_mode (mode) || !oideq (&ce->oid, &oid)) staged_changes =1 ;
builtin/update-index.c +1 -1
@@ -603,7 +603,7 @@ static struct cache_entry *read_one_ent(const char *which,struct object_id oid;struct cache_entry *ce; -if (get_tree_entry (the_repository, ent, path, &oid, &mode)) { +if (get_tree_entry_mode (the_repository, ent, path, &oid, &mode)) {if (which)error ("%s: not in %s branch." , path, which);return NULL ;
line-log.c +1 -1
@@ -503,7 +503,7 @@ static void fill_blob_sha1(struct repository *r, struct commit *commit,unsigned short mode;struct object_id oid; -if (get_tree_entry (r, &commit->object.oid, spec->path, &oid, &mode)) +if (get_tree_entry_mode (r, &commit->object.oid, spec->path, &oid, &mode))die ("There is no path %s in the commit" , spec->path);fill_filespec (spec, &oid,1 , mode);
match-trees.c +3 -3
@@ -293,7 +293,7 @@ void shift_tree(struct repository *r,if (!*del_prefix)return ; -if (get_tree_entry (r, hash2, del_prefix, shifted, &mode)) +if (get_tree_entry_mode (r, hash2, del_prefix, shifted, &mode))die ("cannot find path %s in tree %s" , del_prefix,oid_to_hex (hash2));return ;
@@ -321,12 +321,12 @@ void shift_tree_by(struct repository *r,unsigned candidate =0 ;/* Can hash2 be a tree at shift_prefix in tree hash1? */ -if (!get_tree_entry (r, hash1, shift_prefix, &sub1, &mode1) && +if (!get_tree_entry_mode (r, hash1, shift_prefix, &sub1, &mode1) &&S_ISDIR (mode1)) candidate |=1 ;/* Can hash1 be a tree at shift_prefix in tree hash2? */ -if (!get_tree_entry (r, hash2, shift_prefix, &sub2, &mode2) && +if (!get_tree_entry_mode (r, hash2, shift_prefix, &sub2, &mode2) &&S_ISDIR (mode2)) candidate |=2 ;
merge-recursive.c +9 -9
@@ -487,7 +487,7 @@ static int get_tree_entry_if_blob(struct repository *r, {int ret; - ret =get_tree_entry (r, tree, path, &dfs->oid, &dfs->mode); + ret =get_tree_entry_mode (r, tree, path, &dfs->oid, &dfs->mode);if (S_ISDIR (dfs->mode)) {oidcpy (&dfs->oid, &null_oid); dfs->mode =0 ;
@@ -1886,9 +1886,9 @@ static int tree_has_path(struct repository *r, struct tree *tree,struct object_id hashy;unsigned short mode_o; -return !get_tree_entry (r, - &tree->object.oid, path, - &hashy, &mode_o); +return !get_tree_entry_mode (r, + &tree->object.oid, path, + &hashy, &mode_o); }/*
@@ -2540,11 +2540,11 @@ static void apply_directory_rename_modifications(struct merge_options *opt,* the various handle_rename_*() functions update the index * explicitly rather than relying on unpack_trees() to have done it. */ -get_tree_entry (opt->repo, - &tree->object.oid, - pair->two->path, - &re->dst_entry->stages[stage].oid, - &re->dst_entry->stages[stage].mode); +get_tree_entry_mode (opt->repo, + &tree->object.oid, + pair->two->path, + &re->dst_entry->stages[stage].oid, + &re->dst_entry->stages[stage].mode);/* * Record the original change status (or 'type' of change). If it
notes.c +1 -1
@@ -1021,7 +1021,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,return ;if (flags &NOTES_INIT_WRITABLE &&read_ref (notes_ref, &object_oid))die ("Cannot use notes ref %s" , notes_ref); -if (get_tree_entry (the_repository, &object_oid,"" , &oid, &mode)) +if (get_tree_entry_mode (the_repository, &object_oid,"" , &oid, &mode))die ("Failed to read notes tree referenced by %s (%s)" , notes_ref,oid_to_hex (&object_oid));
object-name.c +3 -3
@@ -1704,7 +1704,7 @@ static void diagnose_invalid_oid_path(struct repository *r,if (is_missing_file_error (errno)) {char *fullname =xstrfmt ("%s%s" , prefix, filename); -if (!get_tree_entry (r, tree_oid, fullname, &oid, &mode)) { +if (!get_tree_entry_mode (r, tree_oid, fullname, &oid, &mode)) { die(_("path '%s' exists, but not '%s'\n" "hint: Did you mean '%.*s:%s' aka '%.*s:./%s'?"), fullname,
@@ -1903,8 +1903,8 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, filename, oid, &oc->symlink_path, &oc->mode); }else { - ret =get_tree_entry (repo, &tree_oid, filename, oid, - &oc->mode); + ret =get_tree_entry_mode (repo, &tree_oid, filename, oid, + &oc->mode);if (ret && only_to_die) { diagnose_invalid_oid_path(repo, prefix, filename,
tree-walk.c +7 -7
@@ -591,17 +591,17 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t,oidcpy (result, &oid);return 0 ; } -return get_tree_entry (r, &oid, name + entrylen, result, - mode); +return get_tree_entry_mode (r, &oid, name + entrylen, result, + mode); }return -1 ; } -int get_tree_entry (struct repository *r, -const struct object_id *tree_oid, -const char *name, -struct object_id *oid, -unsigned short *mode) +int get_tree_entry_mode (struct repository *r, +const struct object_id *tree_oid, +const char *name, +struct object_id *oid, +unsigned short *mode) {int retval;void *tree;
tree-walk.h +3 -3
@@ -174,9 +174,9 @@ struct traverse_info {* The third and fourth parameters are set to the entry's sha1 and * mode respectively. */ -int get_tree_entry (struct repository *,const struct object_id *,const char *, -struct object_id *, -unsigned short *); +int get_tree_entry_mode (struct repository *,const struct object_id *,const char *, +struct object_id *, +unsigned short *);/** * Generate the full pathname of a tree entry based from the root of the
Signature · 1 line
2.31.0.286.gc175f2cb894
PATCH v4 21/29 match-trees: use "tmp" for mode in shift_tree_by()
In reply to Ævar Arnfjörð BjarmasonRefactor code added in 85e51b783c3 (Make "subtree" part more orthogonal to the rest of merge-recursive., 2008-06-30) to make it obvious that we don't care about the "mode" here outside of the if statement it appears in.
That's opposed to the sub1 & sub2 variables, where we use the two object ids later in this function.
--- match-trees.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
match-trees.c +5 -5
@@ -317,17 +317,17 @@ void shift_tree_by(struct repository *r, const char *shift_prefix) {struct object_id sub1, sub2; -unsigned short mode1, mode2; +unsigned short tmp;unsigned candidate =0 ;/* Can hash2 be a tree at shift_prefix in tree hash1? */ -if (!get_tree_entry_mode (r, hash1, shift_prefix, &sub1, &mode1) && -S_ISDIR (mode1)) +if (!get_tree_entry_mode (r, hash1, shift_prefix, &sub1, &tmp) && +S_ISDIR (tmp)) candidate |=1 ;/* Can hash1 be a tree at shift_prefix in tree hash2? */ -if (!get_tree_entry_mode (r, hash2, shift_prefix, &sub2, &mode2) && -S_ISDIR (mode2)) +if (!get_tree_entry_mode (r, hash2, shift_prefix, &sub2, &tmp) && +S_ISDIR (tmp)) candidate |=2 ;if (candidate ==3 ) {
Signature · 1 line
2.31.0.286.gc175f2cb894
PATCH v4 22/29 tree-walk.h API: add get_tree_entry_type()
In reply to Ævar Arnfjörð BjarmasonAdd a get_tree_entry_type() helper function to compliment the existing get_tree_entry(), and a static get_tree_entry_all() which it uses internally.
Move those users of get_tree_entry_type() who didn't care about the mode specifically, but just want to know whether the tree entry is one of OBJ_{BLOB,COMMIT,TREE} over to the new get_tree_entry_type().
The get_tree_entry_all() function itself will be made non-static in a subsequent commit. I'm leaving its argument list indented accordingly to reduce churn when I do so.
--- archive.c | 8 ++++---- match-trees.c | 10 +++++----- tree-walk.c | 54 ++++++++++++++++++++++++++++++++++++++++----------- tree-walk.h | 11 +++++++++-- 4 files changed, 61 insertions(+), 22 deletions(-)
archive.c +4 -4
@@ -475,14 +475,14 @@ static void parse_treeish_arg(const char **argv,if (prefix) {struct object_id tree_oid; -unsigned short mode; +enum object_type object_type;int err; - err =get_tree_entry_mode (ar_args->repo, + err =get_tree_entry_type (ar_args->repo, &tree->object.oid, prefix, &tree_oid, - &mode); -if (err || !S_ISDIR (mode)) + &object_type); +if (err || object_type !=OBJ_TREE )die (_ ("current working directory is untracked" )); tree =parse_tree_indirect (&tree_oid);
match-trees.c +5 -5
@@ -317,17 +317,17 @@ void shift_tree_by(struct repository *r, const char *shift_prefix) {struct object_id sub1, sub2; -unsigned short tmp; +enum object_type tmp;unsigned candidate =0 ;/* Can hash2 be a tree at shift_prefix in tree hash1? */ -if (!get_tree_entry_mode (r, hash1, shift_prefix, &sub1, &tmp) && -S_ISDIR (tmp)) +if (!get_tree_entry_type (r, hash1, shift_prefix, &sub1, &tmp) && + tmp ==OBJ_TREE ) candidate |=1 ;/* Can hash1 be a tree at shift_prefix in tree hash2? */ -if (!get_tree_entry_mode (r, hash2, shift_prefix, &sub2, &tmp) && -S_ISDIR (tmp)) +if (!get_tree_entry_type (r, hash2, shift_prefix, &sub2, &tmp) && + tmp ==OBJ_TREE ) candidate |=2 ;if (candidate ==3 ) {
tree-walk.c +43 -11
100 lines not on this page · raw message
tree-walk.h +9 -2
@@ -171,12 +171,19 @@ struct traverse_info {* Find an entry in a tree given a pathname and the sha1 of a tree to * search. Returns 0 if the entry is found and -1 otherwise. * -* The third and fourth parameters are set to the entry's sha1 and -* mode respectively. +* There are variants of this function depending on what fields in the +* "struct name_entry" you'd like. You always need a pointer to an +* appropriate variable to fill in (NULL won't do!): +* +* get_tree_entry_mode(): unsigned int mode +* get_tree_entry_type(): enum object_type */ int get_tree_entry_mode (struct repository *,const struct object_id *,const char *,struct object_id *,unsigned short *); +int get_tree_entry_type (struct repository *,const struct object_id *,const char *, +struct object_id *, +enum object_type *);/** * Generate the full pathname of a tree entry based from the root of the
Signature · 1 line
2.31.0.286.gc175f2cb894
PATCH v4 23/29 tree-walk.h API: document and format tree_entry_extract()
In reply to Ævar Arnfjörð BjarmasonDocument and format the argument list of the tree_entry_extract() function in preparation for adding a sister function.
--- tree-walk.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
tree-walk.h +10 -4
@@ -40,11 +40,17 @@ struct tree_desc {/** * Decode the entry currently being visited (the one pointed to by -* `tree_desc's` `entry` member) and return the sha1 of the entry. The -* `pathp` and `modep` arguments are set to the entry's pathname and mode -* respectively. +* `tree_desc's` `entry` member) and return the OID of the entry. +* +* There are variants of this function depending on what fields in the +* "struct name_entry" you'd like. You always need a pointer to an +* appropriate variable to fill in (NULL won't do!): +* +* tree_entry_extract_mode(): const char *path, unsigned int mode */ -static inline const struct object_id *tree_entry_extract (struct tree_desc *desc,const char **pathp,unsigned short *modep) +static inline const struct object_id *tree_entry_extract (struct tree_desc *desc, +const char **pathp, +unsigned short *modep) { *pathp = desc->entry.path; *modep = desc->entry.mode;
Signature · 1 line
2.31.0.286.gc175f2cb894
PATCH v4 24/29 tree-entry.h API: rename tree_entry_extract() to tree_entry_extract_mode()
In reply to Ævar Arnfjörð BjarmasonAs with the recent split of the get_tree_entry() function, rename the tree_entry_extract() function to *_mode() in preparation for adding other variants of it.
--- fsck.c | 2 +- match-trees.c | 4 ++-- tree-diff.c | 4 ++-- tree-walk.h | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-)
fsck.c +1 -1
@@ -670,7 +670,7 @@ static int fsck_tree(const struct object_id *oid,const char *name, *backslash;const struct object_id *oid; - oid =tree_entry_extract (&desc, &name, &mode); + oid =tree_entry_extract_mode (&desc, &name, &mode); has_null_sha1 |=is_null_oid (oid); has_full_path |= !!strchr (name,'/' );
match-trees.c +2 -2
@@ -146,7 +146,7 @@ static void match_trees(const struct object_id *hash1,unsigned short mode;int score; - elem =tree_entry_extract (&one, &path, &mode); + elem =tree_entry_extract_mode (&one, &path, &mode);if (!S_ISDIR (mode)) goto next; score =score_trees (elem, hash2);
@@ -202,7 +202,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,unsigned short mode;int len =tree_entry_len (&desc.entry); -tree_entry_extract (&desc, &name, &mode); +tree_entry_extract_mode (&desc, &name, &mode);if (len == toplen && !memcmp (name, prefix, toplen)) {if (!S_ISDIR (mode))
tree-diff.c +2 -2
@@ -196,7 +196,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,if (t) {/* path present in resulting tree */ - oid =tree_entry_extract (t, &path, &mode); + oid =tree_entry_extract_mode (t, &path, &mode); pathlen =tree_entry_len (&t->entry); isdir =S_ISDIR (mode); }else {
@@ -207,7 +207,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,* 1) all modes for tp[i]=tp[imin] should be the same wrt * S_ISDIR, thanks to base_name_compare(). */ -tree_entry_extract (&tp[imin], &path, &mode); +tree_entry_extract_mode (&tp[imin], &path, &mode); pathlen =tree_entry_len (&tp[imin].entry); isdir =S_ISDIR (mode);
tree-walk.h +3 -3
@@ -48,9 +48,9 @@ struct tree_desc {* * tree_entry_extract_mode(): const char *path, unsigned int mode */ -static inline const struct object_id *tree_entry_extract (struct tree_desc *desc, -const char **pathp, -unsigned short *modep) +static inline const struct object_id *tree_entry_extract_mode (struct tree_desc *desc, +const char **pathp, +unsigned short *modep) { *pathp = desc->entry.path; *modep = desc->entry.mode;
Signature · 1 line
2.31.0.286.gc175f2cb894
PATCH v4 25/29 tree-walk.h API: add a tree_entry_extract_all() function
In reply to Ævar Arnfjörð BjarmasonAdd a tree_entry_extract_all() sibling function to the existing tree_entry_extract_mode().
Having the OBJ_{BLOB,TREE,COMMIT} when you have the "mode" is strictly speaking redundant, but hopefully makes it easier to read the code. We'll now see which parts of the code are checking the types, v.s. those that care about the mode specifically.
Only the first use of tree_entry_extract_mode() in emit_path() is converted here, the other branch will use a new get_tree_entry_mode_type() introduced in a subsequent commit.
--- tree-diff.c | 5 +++-- tree-walk.c | 2 +- tree-walk.h | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-)
tree-diff.c +3 -2
@@ -195,10 +195,11 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,assert (t || tp);if (t) { +enum object_type object_type;/* path present in resulting tree */ - oid =tree_entry_extract_mode (t, &path, &mode); + oid =tree_entry_extract_all (t, &path, &mode, &object_type); pathlen =tree_entry_len (&t->entry); - isdir =S_ISDIR (mode); + isdir = (object_type ==OBJ_TREE ); }else {/* * a path was removed - take path from imin parent. Also take
tree-walk.c +1 -1
@@ -577,7 +577,7 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t,struct object_id oid;int entrylen, cmp; -oidcpy (&oid,tree_entry_extract (t, &entry, mode)); +oidcpy (&oid,tree_entry_extract_all (t, &entry, mode, object_type)); entrylen =tree_entry_len (&t->entry);update_tree_entry (t);if (entrylen > namelen)
tree-walk.h +12 -0
@@ -47,6 +47,7 @@ struct tree_desc {* appropriate variable to fill in (NULL won't do!): * * tree_entry_extract_mode(): const char *path, unsigned int mode +* tree_entry_extract_all(): const char *path, unsigned int mode, enum object_type */ static inline const struct object_id *tree_entry_extract_mode(struct tree_desc *desc, const char **pathp,
@@ -57,6 +58,17 @@ static inline const struct object_id *tree_entry_extract_mode(struct tree_desc *return &desc->entry.oid; } +static inline const struct object_id *tree_entry_extract_all (struct tree_desc *desc, +const char **pathp, +unsigned short *modep, +enum object_type *object_typep) +{ + *pathp = desc->entry.path; + *modep = desc->entry.mode; + *object_typep = desc->entry.object_type; +return &desc->entry.oid; +} +/** * Calculate the length of a tree entry's pathname. This utilizes the * memory structure of a tree entry to avoid the overhead of using a
Signature · 1 line
2.31.0.286.gc175f2cb894
PATCH v4 26/29 tree-walk.h API: add get_tree_entry_all()
In reply to Ævar Arnfjörð BjarmasonAdd a get_tree_entry_all() function and use it in the one caller who cares about both the mode and the object type. Refactor it accordingly to make it clear which parts care about the mode, and which about the object_type.
--- builtin/update-index.c | 6 ++++-- tree-walk.c | 9 +-------- tree-walk.h | 4 ++++ 3 files changed, 9 insertions(+), 10 deletions(-)
builtin/update-index.c +4 -2
@@ -599,16 +599,18 @@ static struct cache_entry *read_one_ent(const char *which, struct object_id *ent, const char *path, int namelen, int stage) { + enum object_type object_type;unsigned short mode;struct object_id oid;struct cache_entry *ce; -if (get_tree_entry_mode (the_repository, ent, path, &oid, &mode)) { +if (get_tree_entry_all (the_repository, ent, path, &oid, + &mode, &object_type)) {if (which)error ("%s: not in %s branch." , path, which);return NULL ; } -if (mode ==S_IFDIR ) { +if (object_type ==OBJ_TREE ) {if (which)error ("%s: not a blob in %s branch." , path, which);return NULL ;
tree-walk.c +1 -8
@@ -559,13 +559,6 @@ struct dir_state {struct object_id oid; }; -static int get_tree_entry_all (struct repository *r, -const struct object_id *tree_oid, -const char *name, -struct object_id *oid, -unsigned short *mode, -enum object_type *object_type); - static int find_tree_entry(struct repository *r, struct tree_desc *t, const char *name, struct object_id *result, unsigned short *mode,
@@ -605,7 +598,7 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t,return -1 ; } -static int get_tree_entry_all(struct repository *r, +int get_tree_entry_all(struct repository *r, const struct object_id *tree_oid, const char *name, struct object_id *oid,
tree-walk.h +4 -0
@@ -195,6 +195,7 @@ struct traverse_info {* * get_tree_entry_mode(): unsigned int mode * get_tree_entry_type(): enum object_type +* get_tree_entry_all(): unsigned int mode, enum object_type */ int get_tree_entry_mode(struct repository *, const struct object_id *, const char *, struct object_id *,
@@ -202,6 +203,9 @@ int get_tree_entry_mode(struct repository *, const struct object_id *, const chaint get_tree_entry_type (struct repository *,const struct object_id *,const char *,struct object_id *,enum object_type *); +int get_tree_entry_all (struct repository *,const struct object_id *,const char *, +struct object_id *, +unsigned short *,enum object_type *);/** * Generate the full pathname of a tree entry based from the root of the
Signature · 1 line
2.31.0.286.gc175f2cb894
PATCH v4 27/29 tree-walk.h API: add a get_tree_entry_path() function
In reply to Ævar Arnfjörð BjarmasonAdd a get_tree_entry_path() variant in addition to get_tree_entry_path_{mode,type,all}(). This is for those callers that need neither the mode nor "enum object_type" parameters filled for them.
There are callers here which don't need the "struct object_id" filled; forcing callers to pass one just requires they create a throwaway variable.
See the following commits for the introduction of such code that's being modified here:
- shift_tree(): 68faf68938e (A new merge stragety[sic] 'subtree'.,
2007-02-15) for the shift_tree()
- tree_has_path(): 96e7ffbdc31 (merge-recursive: check for directory level conflicts, 2018-04-19)
- init_notes(): fd53c9eb445 (Speed up git notes lookup, 2009-10-09)
- diagnose_invalid_oid_path(): 009fee4774d (Detailed diagnosis when parsing an object name fails., 2009-12-07)
Those could potentially be refactored too, but I've got to stop at some point, and right now I'm focusing downstream code that depends on "mode" (or "enum object_type").
--- match-trees.c | 4 +--- merge-recursive.c | 6 ++---- notes.c | 3 +-- object-name.c | 3 +-- tree-walk.c | 11 +++++++++++ tree-walk.h | 3 +++ 6 files changed, 19 insertions(+), 11 deletions(-)
match-trees.c +1 -3
@@ -288,12 +288,10 @@ void shift_tree(struct repository *r,if (add_score < del_score) {/* We need to pick a subtree of two */ -unsigned short mode; -if (!*del_prefix)return ; -if (get_tree_entry_mode (r, hash2, del_prefix, shifted, &mode)) +if (get_tree_entry_path (r, hash2, del_prefix, shifted))die ("cannot find path %s in tree %s" , del_prefix,oid_to_hex (hash2));return ;
merge-recursive.c +2 -4
@@ -1884,11 +1884,9 @@ static int tree_has_path(struct repository *r, struct tree *tree, const char *path) {struct object_id hashy; -unsigned short mode_o; - -return !get_tree_entry_mode (r, +return !get_tree_entry_path (r, &tree->object.oid, path, - &hashy, &mode_o); + &hashy); }/*
notes.c +1 -2
@@ -994,7 +994,6 @@ void init_notes(struct notes_tree *t, const char *notes_ref, combine_notes_fn combine_notes, int flags) {struct object_id oid, object_oid; -unsigned short mode;struct leaf_node root_tree;if (!t)
@@ -1021,7 +1020,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,return ;if (flags &NOTES_INIT_WRITABLE &&read_ref (notes_ref, &object_oid))die ("Cannot use notes ref %s" , notes_ref); -if (get_tree_entry_mode (the_repository, &object_oid,"" , &oid, &mode)) +if (get_tree_entry_path (the_repository, &object_oid,"" , &oid))die ("Failed to read notes tree referenced by %s (%s)" , notes_ref,oid_to_hex (&object_oid));
object-name.c +1 -2
@@ -1693,7 +1693,6 @@ static void diagnose_invalid_oid_path(struct repository *r, int object_name_len) {struct object_id oid; -unsigned short mode;if (!prefix) prefix ="" ;
@@ -1704,7 +1703,7 @@ static void diagnose_invalid_oid_path(struct repository *r,if (is_missing_file_error (errno)) {char *fullname =xstrfmt ("%s%s" , prefix, filename); -if (!get_tree_entry_mode (r, tree_oid, fullname, &oid, &mode)) { +if (!get_tree_entry_path (r, tree_oid, fullname, &oid)) { die(_("path '%s' exists, but not '%s'\n" "hint: Did you mean '%.*s:%s' aka '%.*s:./%s'?"), fullname,
tree-walk.c +11 -0
@@ -632,6 +632,17 @@ int get_tree_entry_all(struct repository *r,return retval; } +int get_tree_entry_path (struct repository *r, +const struct object_id *tree_oid, +const char *name, +struct object_id *oid) +{ +unsigned short mode; +enum object_type object_type; +return get_tree_entry_all (r, tree_oid, name, oid, + &mode, &object_type); +} + int get_tree_entry_mode(struct repository *r, const struct object_id *tree_oid, const char *name,
tree-walk.h +3 -0
@@ -193,10 +193,13 @@ struct traverse_info {* "struct name_entry" you'd like. You always need a pointer to an * appropriate variable to fill in (NULL won't do!): * +* get_tree_entry_path(): <no extra argument, just get the common 'path'> * get_tree_entry_mode(): unsigned int mode * get_tree_entry_type(): enum object_type * get_tree_entry_all(): unsigned int mode, enum object_type */ +int get_tree_entry_path (struct repository *,const struct object_id *,const char *, +struct object_id *);int get_tree_entry_mode (struct repository *,const struct object_id *,const char *,struct object_id *,unsigned short *);
Signature · 1 line
2.31.0.286.gc175f2cb894
PATCH v4 28/29 blame: emit a better error on 'git blame directory'
In reply to Ævar Arnfjörð BjarmasonChange an early check for non-blobs in verify_working_tree_path() to let any such objects pass, and instead die shortly thereafter in the fake_working_tree_commit() caller's type check.
Now e.g. doing "git blame t" in git.git emits:
fatal: unsupported file type t
Instead of:
fatal: no such path 't' in HEAD
The main point of this test is to assert that we're not doing something uniquely bad when in a conflicted merge. See cd8ae20195 (git-blame shouldn't crash if run in an unmerged tree, 2007-10-18) and 9aeaab6811 (blame: allow "blame file" in the middle of a conflicted merge, 2012-09-11) for the bug the t8004 test was originally meant to address.
But when extending it let's grep out the specific error message for good measure. Having to change it in the future (e.g. as part of my parallel series to improve such 'OID does not match type' messages) is a small price for ensuring it doesn't regress.
--- blame.c | 8 ++------ t/t8004-blame-with-conflicts.sh | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-)
blame.c +2 -6
@@ -100,12 +100,8 @@ static void verify_working_tree_path(struct repository *r,for (parents = work_tree->parents; parents; parents = parents->next) {const struct object_id *commit_oid = &parents->item->object.oid; -struct object_id blob_oid; -unsigned short mode; -int ret =get_tree_entry_mode (r, commit_oid, path, &blob_oid, - &mode); - -if (!ret &&oid_object_info (r, &blob_oid,NULL ) ==OBJ_BLOB ) +struct object_id oid; +if (!get_tree_entry_path (r, commit_oid, path, &oid))return ; }
t/t8004-blame-with-conflicts.sh +21 -0
@@ -73,4 +73,25 @@ test_expect_success 'blame does not crash with conflicted file in stages 1,3' ' git blame file1 ' +test_expect_success 'setup second case' ' + git merge --abort +' + +test_expect_success 'blame on directory/file conflict' ' + mkdir d && + test_commit second && + test_commit d/file && + test_must_fail git blame d 2>expected && + grep "unsupported file type d" expected && + + git reset --hard second && + >d && + git add d && + git commit -m"a not-a-dir" && + test_must_fail git merge d/file && + + test_must_fail git blame d 2>actual && + test_cmp expected actual +' + test_done
Signature · 1 line
2.31.0.286.gc175f2cb894
PATCH v4 29/29 tree-walk.h API: add a tree_entry_extract_type() function
In reply to Ævar Arnfjörð BjarmasonAdd and use a tree_entry_extract_type() function. There were callers of tree_entry_extract() which didn't care about the mode, but just the type in the tree entry.
In emit_path() the "mode" variable was not used after the "isdir" assignment, as can be seen in the diff with it being set to 0.
--- match-trees.c | 12 ++++++------ tree-diff.c | 5 +++-- tree-walk.h | 11 +++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-)
match-trees.c +6 -6
@@ -143,11 +143,11 @@ static void match_trees(const struct object_id *hash1,while (one.size) {const char *path;const struct object_id *elem; -unsigned short mode; +enum object_type object_type;int score; - elem =tree_entry_extract_mode (&one, &path, &mode); -if (!S_ISDIR (mode)) + elem =tree_entry_extract_type (&one, &path, &object_type); +if (object_type !=OBJ_TREE ) goto next; score =score_trees (elem, hash2);if (*best_score < score) {
@@ -198,14 +198,14 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, rewrite_here =NULL ;while (desc.size) { +enum object_type object_type;const char *name; -unsigned short mode;int len =tree_entry_len (&desc.entry); -tree_entry_extract_mode (&desc, &name, &mode); +tree_entry_extract_type (&desc, &name, &object_type);if (len == toplen && !memcmp (name, prefix, toplen)) { -if (!S_ISDIR (mode)) +if (object_type !=OBJ_TREE )die ("entry %s in tree %s is not a tree" , name,oid_to_hex (oid1));
tree-diff.c +3 -2
@@ -208,10 +208,11 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,* 1) all modes for tp[i]=tp[imin] should be the same wrt * S_ISDIR, thanks to base_name_compare(). */ -tree_entry_extract_mode (&tp[imin], &path, &mode); +enum object_type object_type; +tree_entry_extract_type (&tp[imin], &path, &object_type); pathlen =tree_entry_len (&tp[imin].entry); - isdir =S_ISDIR (mode); + isdir = object_type ==OBJ_TREE ; oid =NULL ; mode =0 ; }
tree-walk.h +11 -0
@@ -47,6 +47,7 @@ struct tree_desc {* appropriate variable to fill in (NULL won't do!): * * tree_entry_extract_mode(): const char *path, unsigned int mode +* tree_entry_extract_type(): const char *path, enum object_type * tree_entry_extract_all(): const char *path, unsigned int mode, enum object_type */ static inline const struct object_id *tree_entry_extract_mode(struct tree_desc *desc,
@@ -58,6 +59,16 @@ static inline const struct object_id *tree_entry_extract_mode(struct tree_desc *return &desc->entry.oid; } +static inline const struct object_id *tree_entry_extract_type (struct tree_desc *desc, +const char **pathp, +enum object_type *object_typep) +{ + *pathp = desc->entry.path; + *object_typep = desc->entry.object_type; +return &desc->entry.oid; +} + + static inline const struct object_id *tree_entry_extract_all(struct tree_desc *desc, const char **pathp, unsigned short *modep,
Signature · 1 line
2.31.0.286.gc175f2cb894
Re: [PATCH v4 00/29] tree-walk: mostly replace "mode" with "enum object_type"
In reply to Ævar Arnfjörð BjarmasonQuoted 8 lines · Ævar Arnfjörð Bjarmason
A re-roll of v3 of this series[1] and on top of (and requires) my just-submitted v5 re-roll of the
read_tree()refactoring series[2].There was a regression in 1/32 of the old series. Removing the
canon_mode()call indiff.cdidn't account for us needing to canonicalize "diff --no-index" modes. There were no tests for this, and it failed or not depending on the FS modes in the git.git checkout being tested. This fixes the CI smoke coming from this series.
Sorry, but quite honestly, I am not quite sure what value this entire code churn is trying to add to the codebase.
The function signature of read_tree_fn_t callback function gets changed from the mode bits (which is capable to express differences between regular files, executable files and symbolic links) to "enum object_type" (which can only say "this is a blob"), which is a regression, no?
A callback can no longer do things like this, for example:
static int add_path_to_index(const struct object_id *oid,
struct strbuf *base, const char *path, unsigned int mode, void *context)
{
struct index_state *istate = (struct index_state *)context;
struct cache_entry *ce;
size_t len = base->len;
if (S_ISDIR(mode))
return READ_TREE_RECURSIVE;
strbuf_addstr(base, path);
ce = make_cache_entry(istate, mode, oid, base->buf, 0, 0);
ce->ce_flags |= CE_SKIP_WORKTREE;
set_index_entry(istate, istate->cache_nr++, ce);
strbuf_setlen(base, len);
return 0;
}where executableness or symlinkshood is lost.
This probably is the third time I caught similar "let's lose information passed through the call chain as nobody seems to need it" mistakes in the iterations of this series, and that is two times too many. We should learn from our earlier mistakes---tweaking of the API that happens to be still OK with the current codebase can be either a needless churn that loses useful expressiveness from the API, or a useful clean-up to kill dead parameter or excess flexibility.
And these three incidents we have seen so far are the former.
Thanks.
Re: [PATCH v4 00/29] tree-walk: mostly replace "mode" with "enum object_type"
Quoted 43 lines · Junio C Hamano
Quoted 8 lines · Ævar Arnfjörð Bjarmason
A re-roll of v3 of this series[1] and on top of (and requires) my just-submitted v5 re-roll of the
read_tree()refactoring series[2].There was a regression in 1/32 of the old series. Removing the
canon_mode()call indiff.cdidn't account for us needing to canonicalize "diff --no-index" modes. There were no tests for this, and it failed or not depending on the FS modes in the git.git checkout being tested. This fixes the CI smoke coming from this series.Sorry, but quite honestly, I am not quite sure what value this entire code churn is trying to add to the codebase.
The function signature of
read_tree_fn_tcallback function gets changed from the mode bits (which is capable to express differences between regular files, executable files and symbolic links) to "enumobject_type" (which can only say "this is a blob"), which is a regression, no?A callback can no longer do things like this, for example:
static int add_path_to_index(const struct
object_id*oid,
struct strbuf *base, const char *path, unsigned int mode, void *context){ struct index_state *istate = (struct index_state *)context; struct cache_entry *ce; size_t len = base->len; if (S_ISDIR(mode)) return READ_TREE_RECURSIVE; strbuf_addstr(base, path); ce = make_cache_entry(istate, mode, oid, base->buf, 0, 0); ce->ce_flags |= CE_SKIP_WORKTREE; set_index_entry(istate, istate->cache_nr++, ce); strbuf_setlen(base, len); return 0; }
Quoted 1 line
where executableness or symlinkshood is lost.
Yes, that would be a serious regression. I agree that all these functions/callbacks etc. should have a way to get at the mode bits.
I'm adding "enum object_type", not removing the "mode" parameter in read_tree_fn_t. This function (which is in "seen" as 03316f20347 (sparse-index: implement ensure_full_index(), 2021-03-16)) works just fine in combination with this series.
The other APIs modified here all retain the ability to give you the mode bit, they (the tree-walk.h changes) just optionally give you the option of getting just the type (or just the path), and as it turns out most users of the API can be converted over to that.
Quoted 10 lines
This probably is the third time I caught similar "let's lose information passed through the call chain as nobody seems to need it" mistakes in the iterations of this series, and that is two times too many. We should learn from our earlier mistakes---tweaking of the API that happens to be still OK with the current codebase can be either a needless churn that loses useful expressiveness from the API, or a useful clean-up to kill dead parameter or excess flexibility.
And these three incidents we have seen so far are the former.
The current codebase will allow you to stick arbitrary mode bits in trees, we have an fsck check to prevent that which doesn't work. I had a summary of this in v1, but should probably have provided a recap[1].
This series is an admittedly long journey towards fixing that. I've got unsubmitted patchen on top that make that fsck check work again.
I think the root cause of these bugs and other ones I've found along the way (some of which I'm not quite comfortable discussing the details of on the public list yet) is that the tree walking API is unnecessarily low-level for most callers.
Most of those callers don't care about the details of the mode bits, but are just traversing a tree and doing something with one the object types.
As opposed to having a mode, but do you want a mode as-is from a tree, normalized to canon_mode() (for writing?) etc. I think being able to clearly tell apart those callers from the simpler ones is a clear win.
So I'm hoping you'll bear with me & this series, sorry about the breakages so far, in my slight defense they were all subtle testing blind spots (but we now have tests!).
cover diff --no-index: fix test blind spots
A trivial series to add tests for "git diff --no-index"'s mode handling, and a missing test for how --exit-code behaves in combination with --no-index while I was at it.
This would have caught the regression I inadvertently introduced in[1]. It's related to my much larger tree-walk.h series[2], but applies independently of that. I wanted to split it off as there were no conflicts or behavior changes related to canon_mode() in that series anymore.
1. https://lore.kernel.org/git/[email protected]/
2. https://lore.kernel.org/git/[email protected]/
Ævar Arnfjörð Bjarmason (2):
diff --no-index tests: add test for --exit-code
diff --no-index tests: test mode normalization
t/t4053-diff-no-index.sh | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.0.282.gcc1ec606501
PATCH 1/2 diff --no-index tests: add test for --exit-code
Add a test for --exit-code working with --no-index. There's no reason to suppose it wouldn't, but we weren't testing for it anywhere in our tests. Let's fix that blind spot.
--- t/t4053-diff-no-index.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
t/t4053-diff-no-index.sh +6 -1
@@ -16,7 +16,12 @@ test_expect_success 'setup' ' echo 1 >non/git/b ' -test_expect_success 'git diff --no-index directories' ' +test_expect_success 'git diff --no-index --exit-code' ' + git diff --no-index --exit-code a/1 non/git/a && + test_expect_code 1 git diff --no-index --exit-code a/1 a/2 +' + +Test_expect_success 'git diff --no-index directories' ' test_expect_code 1 git diff --no-index a b >cnt && test_line_count = 14 cnt '
Signature · 1 line
2.31.0.282.gcc1ec606501
PATCH 2/2 diff --no-index tests: test mode normalization
In reply to Ævar Arnfjörð BjarmasonWhen "git diff --no-index X Y" is run the modes of the files being differ are normalized by canon_mode() in fill_filespec().
I recently broke that behavior in a patch of mine[1] which would pass all tests, or not, depending on the umask of the git.git checkout.
Let's test for this explicitly. Arguably this should not be the behavior of "git diff --no-index". We aren't diffing our own objects or the index, so it might be useful to show mode differences between files.
On the other hand diff(1) does not do that, and it would be needlessly distracting when e.g. diffing an extracted tar archive whose contents is the same, but whose file modes are different.
1. https://lore.kernel.org/git/[email protected]/
--- t/t4053-diff-no-index.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
t/t4053-diff-no-index.sh +30 -0
@@ -149,4 +149,34 @@ test_expect_success 'diff --no-index allows external diff' ' test_cmp expect actual ' +test_expect_success 'diff --no-index normalizes mode: no changes' ' + echo foo >x && + cp x y && + git diff --no-index x y >out && + test_must_be_empty out +' + +test_expect_success 'diff --no-index normalizes mode: chmod +x' ' + chmod +x y && + cat >expected <<-\EOF && + diff --git a/x b/y + old mode 100644 + new mode 100755 + EOF + test_expect_code 1 git diff --no-index x y >actual && + test_cmp expected actual +' + +test_expect_success 'diff --no-index normalizes: mode not like git mode' ' + chmod 666 x && + chmod 777 y && + cat >expected <<-\EOF && + diff --git a/x b/y + old mode 100644 + new mode 100755 + EOF + test_expect_code 1 git diff --no-index x y >actual && + test_cmp expected actual +' + test_done
Signature · 1 line
2.31.0.282.gcc1ec606501
Re: [PATCH v4 00/29] tree-walk: mostly replace "mode" with "enum object_type"
In reply to Ævar Arnfjörð BjarmasonQuoted 8 lines · Ævar Arnfjörð Bjarmason
Yes, that would be a serious regression. I agree that all these functions/callbacks etc. should have a way to get at the mode bits.
I'm adding "enum
object_type", not removing the "mode" parameter inread_tree_fn_t. This function (which is in "seen" as03316f20347(sparse-index: implementensure_full_index(), 2021-03-16)) works just fine in combination with this series.
Quoted 4 lines
The other APIs modified here all retain the ability to give you the mode bit, they (the
tree-walk.hchanges) just optionally give you the option of getting just the type (or just the path), and as it turns out most users of the API can be converted over to that.
I have a vague feeling that such an approach may be still repeating the same mistake.
If the original premise is that "unsigned mode" bit can be abused to feed impossible values like 0100653 to the system and the code should catch it, ...
Quoted 2 lines
The current codebase will allow you to stick arbitrary mode bits in trees, ...
... then I would understand it if the approach is to introduce a distinct type that enumerates all possible mode bit values (and nothing else), and have the compiler validate the callchain, so that nobody can pass bogus mode bits (and when reading mode bits fields in existing objects, the one that converts from the series of octal bytes to that distsinct type would notice and complain). And we've already seen from this particular breakages that the "distinct type" appropriate to be used for that purpose is not "enum object_type". It is not expressive enough to enumerate all possible mode bit values (besides, an enum is interchangeable with an int, so there isn't much protection we would be getting from the compiler---we could use a small struct of a new type, and have one static const instance for each possible mode bit combination, I guess, but the point here is that insisting on using "enum object_type" seems to be the source of the problem).
I am afraid that it is even worse to pass both object type and "unsigned mode" together. It would still leave room for a bug to pass nonsense mode bits, which we said we wanted to catch in our original mission statement. In addition, we now have a new room for a bug, which is to pass an inconsistent pair of object type and mode to the callchain. Somebody would need to say "yuck, we got a mode 100644 but the type says TREE" now, in addition to validating if the mode is sensible, which we should be doing somehow, no?
So, I am not sure how these changes are making anything better.
Quoted 2 lines
... I had a
summary of this in v1, but should probably have provided a recap[1].
Oh, absolutely. When we iterate, we should be welcoming to those who missed earlier iterations.
Re: [PATCH 1/2] diff --no-index tests: add test for --exit-code
In reply to Ævar Arnfjörð BjarmasonQuoted 14 lines · Ævar Arnfjörð Bjarmason
Add a test for --exit-code working with --no-index. There's no reason to suppose it wouldn't, but we weren't testing for it anywhere in our tests. Let's fix that blind spot.
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- t/t4053-diff-no-index.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)t/t4053-diff-no-index.sh +0
-0
t/t4053-diff-no-index.sh test_expect_success 'setup' ' · line 24
Quoted 10 lines
t/t4053-diff-no-index.sh +6
-1@@ -16,7 +16,12 @@ test_expect_success 'setup' ' echo 1 >non/git/b ' -test_expect_success 'git diff --no-index directories' ' +test_expect_success 'git diff --no-index --exit-code' ' + git diff --no-index --exit-code a/1 non/git/a && + test_expect_code 1 git diff --no-index --exit-code a/1 a/2 +' + +Test_expect_success 'git diff --no-index directories' '
I assume that s/test/Test/ was not intended. ;-)
ATB,
Ramsay Jones
Quoted 4 lines
t/t4053-diff-no-index.sh +0
-0test_expect_code 1 git diff --no-index a b >cnt && test_line_count = 14 cnt '
Re: [PATCH v4 00/29] tree-walk: mostly replace "mode" with "enum object_type"
In reply to Junio C HamanoQuoted 25 lines · Junio C Hamano
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Yes, that would be a serious regression. I agree that all these functions/callbacks etc. should have a way to get at the mode bits.
I'm adding "enum
object_type", not removing the "mode" parameter inread_tree_fn_t. This function (which is in "seen" as03316f20347(sparse-index: implementensure_full_index(), 2021-03-16)) works just fine in combination with this series.Quoted 4 lines
The other APIs modified here all retain the ability to give you the mode bit, they (the
tree-walk.hchanges) just optionally give you the option of getting just the type (or just the path), and as it turns out most users of the API can be converted over to that.I have a vague feeling that such an approach may be still repeating the same mistake.
If the original premise is that "unsigned mode" bit can be abused to feed impossible values like 0100653 to the system and the code should catch it, ...
Quoted 2 lines
The current codebase will allow you to stick arbitrary mode bits in trees, ...
Quoted 15 lines
... then I would understand it if the approach is to introduce a distinct type that enumerates all possible mode bit values (and nothing else), and have the compiler validate the callchain, so that nobody can pass bogus mode bits (and when reading mode bits fields in existing objects, the one that converts from the series of octal bytes to that distsinct type would notice and complain). And we've already seen from this particular breakages that the "distinct type" appropriate to be used for that purpose is not "enum
object_type". It is not expressive enough to enumerate all possible mode bit values (besides, an enum is interchangeable with an int, so there isn't much protection we would be getting from the compiler---we could use a small struct of a new type, and have one static const instance for each possible mode bit combination, I guess, but the point here is that insisting on using "enumobject_type" seems to be the source of the problem).
Yes, this is a good suggestion, but one which'll be much easier to do after this series. Since the majority of callers don't care about the raw mode bits or anything except if the entry is a blob/tree/commit.
Quoted 8 lines
I am afraid that it is even worse to pass both object type and "unsigned mode" together. It would still leave room for a bug to pass nonsense mode bits, which we said we wanted to catch in our original mission statement. In addition, we now have a new room for a bug, which is to pass an inconsistent pair of object type and mode to the callchain. Somebody would need to say "yuck, we got a mode 100644 but the type says TREE" now, in addition to validating if the mode is sensible, which we should be doing somehow, no?
Indeed. This goes back to my "bear with me" comment upthread. I'm planning to fix these cases too, and starting by moving most things to "enum object_type" makes that a lot easier.
Right now we simply trust the mode bits, but that opens the door to the same sort of bug I'm fixing in another series (that I need to re-roll) where we have a "type commit" and "object ID" in a tag, but the ID is really a tree or whatever.
We then get confused because we trusted the invalid metadata over checking the type of the object ID we have in the object store.
So this particular series doesn't fix this bug at the end of it, the "object_type" in tree-walk.c is just a function of deriving it from the mode bits.
But once I've audited the cases where we're really just acting on the type and don't have or use the mode (so we know we're not re-writing the mode somewhere) then we would set the object_type to the actual type, as in what we'd get from oid_object_info(ID).
Then we can e.g. scream murder about a mode/type mismatch in fsck, but still be able to list/diff/inspect etc. that object in any codepath that just wants to e.g. recursively iterate over the tree.
Quoted 7 lines
So, I am not sure how these changes are making anything better.
Quoted 2 lines
... I had a
summary of this in v1, but should probably have provided a recap[1].Oh, absolutely. When we iterate, we should be welcoming to those who missed earlier iterations.
Re: [PATCH 1/2] diff --no-index tests: add test for --exit-code
In reply to Ramsay JonesQuoted 18 lines · Ramsay Jones
Quoted 17 lines · Ævar Arnfjörð Bjarmason
Add a test for --exit-code working with --no-index. There's no reason to suppose it wouldn't, but we weren't testing for it anywhere in our tests. Let's fix that blind spot.
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- t/t4053-diff-no-index.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)t/t4053-diff-no-index.sh +0
-0@@ -16,7 +16,12 @@ test_expect_success 'setup' ' echo 1 >non/git/b '
Quoted 9 lines
t/t4053-diff-no-index.sh test_expect_success 'setup' ' · line 24
Quoted 7 lines
t/t4053-diff-no-index.sh +6
-1-test_expect_success 'git diff --no-index directories' ' +test_expect_success 'git diff --no-index --exit-code' ' + git diff --no-index --exit-code a/1 non/git/a && + test_expect_code 1 git diff --no-index --exit-code a/1 a/2 +' + +Test_expect_success 'git diff --no-index directories' 'I assume that s/test/Test/ was not intended. ;-)
;-)
Love to see reviewers are more careful than submitters' shells that are too lenient to allow such a test to pass before such a patch gets submitted.
v2 cover diff --no-index: fix test blind spots
In reply to Ævar Arnfjörð BjarmasonFixes a stupid s/Test/test/ typo in v1. Thanks Ramsey. I also noticed a failure on one of the Windows CI's (curiously, not all?), so POSIXPERM for these tests is another thing I forgot.
I've also added a symlink diff test for good measure. I'm testing the full output, but using the the approprite variables, so it passes under both GIT_TEST_DEFAULT_HASH=sha1 & sha256.
Ævar Arnfjörð Bjarmason (2):
diff --no-index tests: add test for --exit-code
diff --no-index tests: test mode normalization
t/t4053-diff-no-index.sh | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
Range-diff:
1: a6e4ed6c3f1 ! 1: 2dbc6c253e2 diff --no-index tests: add test for --exit-code
@@ t/t4053-diff-no-index.sh: test_expect_success 'setup' '
echo 1 >non/git/b
'
--test_expect_success 'git diff --no-index directories' '
+test_expect_success 'git diff --no-index --exit-code' '
+ git diff --no-index --exit-code a/1 non/git/a &&
+ test_expect_code 1 git diff --no-index --exit-code a/1 a/2
+'
+
-+Test_expect_success 'git diff --no-index directories' '
+ test_expect_success 'git diff --no-index directories' '
test_expect_code 1 git diff --no-index a b >cnt &&
test_line_count = 14 cnt
- '
2: 2dcc8bccf97 ! 2: a1ab6a323f2 diff --no-index tests: test mode normalization
@@ t/t4053-diff-no-index.sh: test_expect_success 'diff --no-index allows external d
+ test_must_be_empty out
+'
+
-+test_expect_success 'diff --no-index normalizes mode: chmod +x' '
++test_expect_success POSIXPERM 'diff --no-index normalizes mode: chmod +x' '
+ chmod +x y &&
+ cat >expected <<-\EOF &&
+ diff --git a/x b/y
@@ t/t4053-diff-no-index.sh: test_expect_success 'diff --no-index allows external d
+ test_cmp expected actual
+'
+
-+test_expect_success 'diff --no-index normalizes: mode not like git mode' '
++test_expect_success POSIXPERM 'diff --no-index normalizes: mode not like git mode' '
+ chmod 666 x &&
+ chmod 777 y &&
+ cat >expected <<-\EOF &&
@@ t/t4053-diff-no-index.sh: test_expect_success 'diff --no-index allows external d
+ test_expect_code 1 git diff --no-index x y >actual &&
+ test_cmp expected actual
+'
++
++test_expect_success POSIXPERM,SYMLINKS 'diff --no-index normalizes: mode not like git mode (symlink)' '
++ ln -s y z &&
++ X_OID=$(git hash-object --stdin <x) &&
++ Z_OID=$(echo -n y | git hash-object --stdin) &&
++ cat >expected <<-EOF &&
++ diff --git a/x b/x
++ deleted file mode 100644
++ index $X_OID..$ZERO_OID
++ --- a/x
++ +++ /dev/null
++ @@ -1 +0,0 @@
++ -foo
++ diff --git a/z b/z
++ new file mode 120000
++ index $ZERO_OID..$Z_OID
++ --- /dev/null
++ +++ b/z
++ @@ -0,0 +1 @@
++ +y
++ \ No newline at end of file
++ EOF
++ test_expect_code 1 git -c core.abbrev=no diff --no-index x z >actual &&
++ test_cmp expected actual
++'
+
test_doneSignature · 1 line
2.31.0.285.gb40d23e604f
PATCH v2 1/2 diff --no-index tests: add test for --exit-code
Add a test for --exit-code working with --no-index. There's no reason to suppose it wouldn't, but we weren't testing for it anywhere in our tests. Let's fix that blind spot.
--- t/t4053-diff-no-index.sh | 5 +++++ 1 file changed, 5 insertions(+)
t/t4053-diff-no-index.sh +5 -0
@@ -16,6 +16,11 @@ test_expect_success 'setup' ' echo 1 >non/git/b ' +test_expect_success 'git diff --no-index --exit-code' ' + git diff --no-index --exit-code a/1 non/git/a && + test_expect_code 1 git diff --no-index --exit-code a/1 a/2 +' + test_expect_success 'git diff --no-index directories' ' test_expect_code 1 git diff --no-index a b >cnt && test_line_count = 14 cnt
Signature · 1 line
2.31.0.285.gb40d23e604f
PATCH v2 2/2 diff --no-index tests: test mode normalization
In reply to Ævar Arnfjörð BjarmasonWhen "git diff --no-index X Y" is run the modes of the files being differ are normalized by canon_mode() in fill_filespec().
I recently broke that behavior in a patch of mine[1] which would pass all tests, or not, depending on the umask of the git.git checkout.
Let's test for this explicitly. Arguably this should not be the behavior of "git diff --no-index". We aren't diffing our own objects or the index, so it might be useful to show mode differences between files.
On the other hand diff(1) does not do that, and it would be needlessly distracting when e.g. diffing an extracted tar archive whose contents is the same, but whose file modes are different.
1. https://lore.kernel.org/git/[email protected]/
--- t/t4053-diff-no-index.sh | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
t/t4053-diff-no-index.sh +55 -0
@@ -149,4 +149,59 @@ test_expect_success 'diff --no-index allows external diff' ' test_cmp expect actual ' +test_expect_success 'diff --no-index normalizes mode: no changes' ' + echo foo >x && + cp x y && + git diff --no-index x y >out && + test_must_be_empty out +' + +test_expect_success POSIXPERM 'diff --no-index normalizes mode: chmod +x' ' + chmod +x y && + cat >expected <<-\EOF && + diff --git a/x b/y + old mode 100644 + new mode 100755 + EOF + test_expect_code 1 git diff --no-index x y >actual && + test_cmp expected actual +' + +test_expect_success POSIXPERM 'diff --no-index normalizes: mode not like git mode' ' + chmod 666 x && + chmod 777 y && + cat >expected <<-\EOF && + diff --git a/x b/y + old mode 100644 + new mode 100755 + EOF + test_expect_code 1 git diff --no-index x y >actual && + test_cmp expected actual +' + +test_expect_success POSIXPERM,SYMLINKS 'diff --no-index normalizes: mode not like git mode (symlink)' ' + ln -s y z && + X_OID=$(git hash-object --stdin <x) && + Z_OID=$(echo -n y | git hash-object --stdin) && + cat >expected <<-EOF && + diff --git a/x b/x + deleted file mode 100644 + index $X_OID..$ZERO_OID + --- a/x + +++ /dev/null + @@ -1 +0,0 @@ + -foo + diff --git a/z b/z + new file mode 120000 + index $ZERO_OID..$Z_OID + --- /dev/null + +++ b/z + @@ -0,0 +1 @@ + +y + \ No newline at end of file + EOF + test_expect_code 1 git -c core.abbrev=no diff --no-index x z >actual && + test_cmp expected actual +' + test_done
Signature · 1 line
2.31.0.285.gb40d23e604f
Re: [PATCH 1/2] diff --no-index tests: add test for --exit-code
In reply to Junio C HamanoQuoted 30 lines · Junio C Hamano
Quoted 18 lines · Ramsay Jones
Quoted 17 lines · Ævar Arnfjörð Bjarmason
Add a test for --exit-code working with --no-index. There's no reason to suppose it wouldn't, but we weren't testing for it anywhere in our tests. Let's fix that blind spot.
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- t/t4053-diff-no-index.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)t/t4053-diff-no-index.sh +0
-0@@ -16,7 +16,12 @@ test_expect_success 'setup' ' echo 1 >non/git/b 'Quoted 9 lines
t/t4053-diff-no-index.sh test_expect_success 'setup' ' · line 24
Quoted 7 lines
t/t4053-diff-no-index.sh +6
-1-test_expect_success 'git diff --no-index directories' ' +test_expect_success 'git diff --no-index --exit-code' ' + git diff --no-index --exit-code a/1 non/git/a && + test_expect_code 1 git diff --no-index --exit-code a/1 a/2 +' + +Test_expect_success 'git diff --no-index directories' 'I assume that s/test/Test/ was not intended. ;-)
Quoted 5 lines
;-)
Love to see reviewers are more careful than submitters' shells that are too lenient to allow such a test to pass before such a patch gets submitted.
Sorry about that, and thanks Ramsey for spotting it.
FWIW I don't think there's any shell you can run the tests with that would catch this. We won't run the tests at all with "set -e"[1], and we don't use "set -e" in the tests themselves by convention.
So you'll see a notice about an unknown Test_expect_success function in the output if you're not blind to it as I apparently was, but the the test will succeed, CI will pass etc.
1. In this case the thing holding it back is the structure of the sanity check added in 2006f0adaee (t/test-lib: make sure Git has already been built, 2012-09-17), we'd proceed if it was part of the "if", hrm...
Re: [PATCH v2 0/2] diff --no-index: fix test blind spots
In reply to Ævar Arnfjörð BjarmasonQuoted 3 lines · Ævar Arnfjörð Bjarmason
Fixes a stupid s/Test/test/ typo in v1. Thanks Ramsey. I also noticed a failure on one of the Windows CI's (curiously, not all?), so POSIXPERM for these tests is another thing I forgot.
Nice. Thanks for a quick reroll.
Re: [PATCH v2 2/2] diff --no-index tests: test mode normalization
In reply to Ævar Arnfjörð Bjarmasont/t4053-diff-no-index.sh test_expect_success 'diff --no-index allows external diff' ' · line 185
Quoted 4 lines · Ævar Arnfjörð Bjarmason
t/t4053-diff-no-index.sh +4
-0+test_expect_success POSIXPERM,SYMLINKS 'diff --no-index normalizes: mode not like git mode (symlink)' ' + ln -s y z && + X_OID=$(git hash-object --stdin <x) && + Z_OID=$(echo -n y | git hash-object --stdin) &&
s/echo -n/printf/
t4053-diff-no-index.sh:185: error: echo with option is not portable (use printf): Z_OID=$(echo -n y | git hash-object --stdin) && gmake[1]: *** [Makefile:95: test-lint-shell-syntax] Error 1 gmake[1]: Leaving directory '/home/jch/w/buildfarm/jch/t'
gmake: *** [Makefile:2855: test] Error 2
v3 cover diff --no-index: fix test blind spots
In reply to Ævar Arnfjörð BjarmasonSince v2[1]: s/echo -n/printf/ (and I re-adjusted my test setup to run the linting..)
1. https://lore.kernel.org/git/[email protected]/
Ævar Arnfjörð Bjarmason (2):
diff --no-index tests: add test for --exit-code
diff --no-index tests: test mode normalization
t/t4053-diff-no-index.sh | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
Range-diff:
1: 2dbc6c253e2 = 1: 7dd5c309a70 diff --no-index tests: add test for --exit-code
2: a1ab6a323f2 ! 2: e5bb094b783 diff --no-index tests: test mode normalization
@@ t/t4053-diff-no-index.sh: test_expect_success 'diff --no-index allows external d
+test_expect_success POSIXPERM,SYMLINKS 'diff --no-index normalizes: mode not like git mode (symlink)' '
+ ln -s y z &&
+ X_OID=$(git hash-object --stdin <x) &&
-+ Z_OID=$(echo -n y | git hash-object --stdin) &&
++ Z_OID=$(printf "y" | git hash-object --stdin) &&
+ cat >expected <<-EOF &&
+ diff --git a/x b/x
+ deleted file mode 100644Signature · 1 line
2.31.0.366.g871543fb182
PATCH v3 1/2 diff --no-index tests: add test for --exit-code
Add a test for --exit-code working with --no-index. There's no reason to suppose it wouldn't, but we weren't testing for it anywhere in our tests. Let's fix that blind spot.
--- t/t4053-diff-no-index.sh | 5 +++++ 1 file changed, 5 insertions(+)
t/t4053-diff-no-index.sh +5 -0
@@ -16,6 +16,11 @@ test_expect_success 'setup' ' echo 1 >non/git/b ' +test_expect_success 'git diff --no-index --exit-code' ' + git diff --no-index --exit-code a/1 non/git/a && + test_expect_code 1 git diff --no-index --exit-code a/1 a/2 +' + test_expect_success 'git diff --no-index directories' ' test_expect_code 1 git diff --no-index a b >cnt && test_line_count = 14 cnt
Signature · 1 line
2.31.0.366.g871543fb182
PATCH v3 2/2 diff --no-index tests: test mode normalization
In reply to Ævar Arnfjörð BjarmasonWhen "git diff --no-index X Y" is run the modes of the files being differ are normalized by canon_mode() in fill_filespec().
I recently broke that behavior in a patch of mine[1] which would pass all tests, or not, depending on the umask of the git.git checkout.
Let's test for this explicitly. Arguably this should not be the behavior of "git diff --no-index". We aren't diffing our own objects or the index, so it might be useful to show mode differences between files.
On the other hand diff(1) does not do that, and it would be needlessly distracting when e.g. diffing an extracted tar archive whose contents is the same, but whose file modes are different.
1. https://lore.kernel.org/git/[email protected]/
--- t/t4053-diff-no-index.sh | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
t/t4053-diff-no-index.sh +55 -0
@@ -149,4 +149,59 @@ test_expect_success 'diff --no-index allows external diff' ' test_cmp expect actual ' +test_expect_success 'diff --no-index normalizes mode: no changes' ' + echo foo >x && + cp x y && + git diff --no-index x y >out && + test_must_be_empty out +' + +test_expect_success POSIXPERM 'diff --no-index normalizes mode: chmod +x' ' + chmod +x y && + cat >expected <<-\EOF && + diff --git a/x b/y + old mode 100644 + new mode 100755 + EOF + test_expect_code 1 git diff --no-index x y >actual && + test_cmp expected actual +' + +test_expect_success POSIXPERM 'diff --no-index normalizes: mode not like git mode' ' + chmod 666 x && + chmod 777 y && + cat >expected <<-\EOF && + diff --git a/x b/y + old mode 100644 + new mode 100755 + EOF + test_expect_code 1 git diff --no-index x y >actual && + test_cmp expected actual +' + +test_expect_success POSIXPERM,SYMLINKS 'diff --no-index normalizes: mode not like git mode (symlink)' ' + ln -s y z && + X_OID=$(git hash-object --stdin <x) && + Z_OID=$(printf "y" | git hash-object --stdin) && + cat >expected <<-EOF && + diff --git a/x b/x + deleted file mode 100644 + index $X_OID..$ZERO_OID + --- a/x + +++ /dev/null + @@ -1 +0,0 @@ + -foo + diff --git a/z b/z + new file mode 120000 + index $ZERO_OID..$Z_OID + --- /dev/null + +++ b/z + @@ -0,0 +1 @@ + +y + \ No newline at end of file + EOF + test_expect_code 1 git -c core.abbrev=no diff --no-index x z >actual && + test_cmp expected actual +' + test_done
Signature · 1 line
2.31.0.366.g871543fb182
Re: [PATCH v3 0/2] diff --no-index: fix test blind spots
In reply to Ævar Arnfjörð BjarmasonQuoted 13 lines · Ævar Arnfjörð Bjarmason
Since v2[1]: s/echo -n/printf/ (and I re-adjusted my test setup to run the linting..)
1. https://lore.kernel.org/git/[email protected]/
Ævar Arnfjörð Bjarmason (2):
diff --no-index tests: add test for --exit-code
diff --no-index tests: test mode normalizationt/t4053-diff-no-index.sh | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)Range-diff:
Quoted 11 lines
1: 2dbc6c253e2 = 1: 7dd5c309a70 diff --no-index tests: add test for --exit-code
2: a1ab6a323f2 ! 2: e5bb094b783 diff --no-index tests: test mode normalization
@@ t/t4053-diff-no-index.sh: test_expect_success 'diff --no-index allows external d
+test_expect_success POSIXPERM,SYMLINKS 'diff --no-index normalizes: mode not like git mode (symlink)' '
+ ln -s y z &&
+ X_OID=$(git hash-object --stdin <x) &&
-+ Z_OID=$(echo -n y | git hash-object --stdin) &&
++ Z_OID=$(printf "y" | git hash-object --stdin) &&
+ cat >expected <<-EOF &&
+ diff --git a/x b/x
+ deleted file mode 100644Thanks for a quick turnaround, and sorry for forgetting to say "locally munged, no need to resend".
v5 cover tree-walk.h: slimmed down
In reply to Ævar Arnfjörð BjarmasonThese are preparatory changes to the tree-walk.h API to eventually fix long-broken git-fsck mode checks.
Per http://lore.kernel.org/git/[email protected] I think the previous round of this was too big.
So here's a slimmed-down version which stops short of migrating anything to "enum object_type". There's just:
* Tests
* Renaming relevant API *() to *_mode() (the next series will propose a *_type())
* Adding *_path() API for those users that don't need the "mode" the *_mode() function provides
* Comment updates, fixes to comments.
* Whitespace changes that would be needed by the next series, but which are a good idea anyway while we're at it, e.g. aligning function declarations.
Ævar Arnfjörð Bjarmason (18):
cache.h: add a comment to object_type()
merge-ort: correct reference to test in 62fdec17a11 cache.h: have base_name_compare() take "is tree?", not "mode" fast-import tests: test for sorting dir/file foo v.s. foo.txt mktree tests: test that "mode" is passed when sorting diff tests: test that "mode" is passed when sorting merge-tree tests: test for the mode comparison in same_entry()
blame: emit a better error on 'git blame directory' notes & match-trees: use name_entry's "pathlen" member tree-walk.h users: use temporary variable(s) for "mode"
match-trees: use "tmp" for mode in shift_tree_by() tree.h: format argument lists of read_tree() users tree-walk.h API: formatting changes for subsequent commit tree-walk.h API doc: improve documentation of get_tree_entry() tree-walk.h API: rename get_tree_entry() to get_tree_entry_mode() tree-walk.h API: add a get_tree_entry_path() function tree-walk.h API: document and format tree_entry_extract() tree-entry.h API: rename tree_entry_extract() to
tree_entry_extract_mode()
archive.c | 21 ++++---- blame.c | 6 +-- builtin/checkout.c | 4 +- builtin/fast-import.c | 12 +++-- builtin/log.c | 5 +- builtin/ls-tree.c | 4 +- builtin/merge-tree.c | 12 +++-- builtin/mktree.c | 4 +- builtin/rm.c | 2 +- builtin/update-index.c | 2 +- cache.h | 11 +++-- combine-diff.c | 8 +-- fsck.c | 2 +- line-log.c | 2 +- match-trees.c | 44 ++++++++--------- merge-ort.c | 11 +++-- merge-recursive.c | 29 ++++++----- notes.c | 10 ++-- object-name.c | 7 ++- read-cache.c | 16 +++--- t/t1450-fsck.sh | 66 +++++++++++++++++++++++++ t/t4300-merge-tree.sh | 44 +++++++++++++++++ t/t8004-blame-with-conflicts.sh | 21 ++++++++ t/t9300-fast-import.sh | 87 +++++++++++++++++++++++++++++++++ tree-diff.c | 24 +++++---- tree-walk.c | 30 ++++++++---- tree-walk.h | 35 +++++++++---- tree.h | 5 +- unpack-trees.c | 18 ++++--- 29 files changed, 410 insertions(+), 132 deletions(-)
Range-diff:
1: c307eb53331 < -: ----------- show tests: add test for "git show <tree>"
2: f37d7705cf0 < -: ----------- ls-files tests: add meaningful --with-tree tests
3: 6291d8a1b5e < -: ----------- tree.c API: move read_tree() into builtin/ls-files.c
4: 466b518e915 < -: ----------- ls-files: don't needlessly pass around stage variable
5: 30c3abfe9b9 < -: ----------- ls-files: refactor away read_tree()
6: 02c42be9249 < -: ----------- archive: stop passing "stage" through read_tree_recursive()
7: d55e8d4042b < -: ----------- tree.h API: expose read_tree_1() as read_tree_at()
8: fa157d8baee < -: ----------- tree.h API: simplify read_tree_recursive() signature
10: 186f7a7a44b = 1: a74e02ff0ba cache.h: add a comment to object_type()
24: 092472f3c8d = 2: 57092359bbb merge-ort: correct reference to test in 62fdec17a11
16: 1b6a10f814c ! 3: 44c3fdd0085 cache.h: have base_name_compare() take "is tree?", not "mode"
@@ Commit message
function to take a boolean argument indicating whether the entry is a
tree or not, instead of having them call S_ISDIR(mode) on their own.
- This makes use of the new "object_type" field in the "name_entry".
+ This introduces no functional change, but makes later (not part of
+ this series) changes to abstract away "object_type" from "mode" more
+ readable.
The API being modified here was originally added way back in
958ba6c96eb (Introduce "base_name_compare()" helper function,
@@ match-trees.c: static void *fill_tree_desc_strict(struct tree_desc *desc,
{
- return base_name_compare(a->path, tree_entry_len(a), a->mode,
- b->path, tree_entry_len(b), b->mode);
-+ int istree_a = (a->object_type == OBJ_TREE);
-+ int istree_b = (b->object_type == OBJ_TREE);
++ int istree_a = S_ISDIR(a->mode);
++ int istree_b = S_ISDIR(b->mode);
+ return base_name_compare(a->path, tree_entry_len(a), istree_a,
+ b->path, tree_entry_len(b), istree_b);
}
@@ tree-diff.c: static int tree_entry_pathcmp(struct tree_desc *t1, struct tree_des
return -1;
e1 = &t1->entry;
-+ istree_e1 = (e1->object_type == OBJ_TREE);
++ istree_e1 = S_ISDIR(e1->mode);
e2 = &t2->entry;
- cmp = base_name_compare(e1->path, tree_entry_len(e1), e1->mode,
- e2->path, tree_entry_len(e2), e2->mode);
-+ istree_e2 = (e2->object_type == OBJ_TREE);
++ istree_e2 = S_ISDIR(e2->mode);
+ cmp = base_name_compare(e1->path, tree_entry_len(e1), istree_e1,
+ e2->path, tree_entry_len(e2), istree_e2);
return cmp;
@@ unpack-trees.c: static int do_compare_entry(const struct cache_entry *ce,
static int compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
{
- int cmp = do_compare_entry(ce, info, n->path, n->pathlen, n->mode);
-+ int istree = (n->object_type == OBJ_TREE);
++ int istree = S_ISDIR(n->mode);
+ int cmp = do_compare_entry(ce, info, n->path, n->pathlen, istree);
if (cmp)
return cmp;
13: 7016008554a = 4: 2ff35f410cd fast-import tests: test for sorting dir/file foo v.s. foo.txt
14: b0546197b1b = 5: b3289f7bbe5 mktree tests: test that "mode" is passed when sorting
15: 73e92ac187d = 6: 0be013e47c4 diff tests: test that "mode" is passed when sorting
23: 592fecb7abc ! 7: 3367850559b merge-tree tests: test for the mode comparison in same_entry() @@ Commit message
but as seen here it's important that we don't think a path with the same content but different modes is the same_entry().
- The rest of this series will touch code that's relevant to this, but
- won't change its behavior. This test is just something I came up with
- in testing whether the mode test in same_entry() was needed at all.
-
## t/t4300-merge-tree.sh ##
36: 81da5490221 ! 8: 3c2ca98716d blame: emit a better error on 'git blame directory'
@@ Commit message
something uniquely bad when in a conflicted merge. See cd8ae20195 (git-blame shouldn't crash if run in an unmerged tree, 2007-10-18) and 9aeaab6811 (blame: allow "blame file" in the middle of
- a conflicted merge, 2012-09-11) for the bug the t8004 test was
- originally meant to address.
+ a conflicted merge, 2012-09-11) for the bug the test was originally
+ meant to address.
But when extending it let's grep out the specific error message for good measure. Having to change it in the future (e.g. as part of my
@@ Commit message
## blame.c ##
@@ blame.c: static void verify_working_tree_path(struct repository *r,
+ struct object_id blob_oid;
+ unsigned short mode;
- for (parents = work_tree->parents; parents; parents = parents->next) {
- const struct object_id *commit_oid = &parents->item->object.oid;
-- struct object_id blob_oid;
-- unsigned short mode;
-- int ret = get_tree_entry_mode(r, commit_oid, path, &blob_oid,
-- &mode);
--
-- if (!ret && oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
-+ struct object_id oid;
-+ if (!get_tree_entry_path(r, commit_oid, path, &oid))
+- if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
+- oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
++ if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode))
return;
}
9: 0390b1e9ded = 9: 749be26bf8e notes & match-trees: use name_entry's "pathlen" member 11: 4fed508f3cb < -: ----------- tree-walk.h: add object_type member to name_entry 12: c557b67231b < -: ----------- tree-walk.c: migrate to using new "object_type" field when possible 17: f8912a409b5 < -: ----------- tree-walk.h users: switch object_type(...) to new .object_type 26: 4babecb7855 ! 10: 5c0a49c188f tree-walk.h users: use temporary variable(s) for "mode"
@@ Commit message
In preparation for an eventual rename of the "mode" field, add temporary variable(s) in those places where it's used more than once.
- This will make a subsequent commits easier to read., since we're only
+ This will make those later commits easier to read, since we're only
going to need to modify the line on which the assignment happens.
@@ builtin/merge-tree.c: static struct merge_list *link_entry(unsigned stage, const
struct merge_list *link;
+ unsigned int link_mode;
- if (n->object_type == OBJ_NONE)
+ if (!n->mode)
return entry;
@@ builtin/merge-tree.c: static struct merge_list *link_entry(unsigned stage, const struct traverse_info
path = entry->path;
29: 40f37e99cd9 ! 11: e190ed39754 match-trees: use "tmp" for mode in shift_tree_by()
@@ match-trees.c: void shift_tree_by(struct repository *r,
unsigned candidate = 0;
/* Can hash2 be a tree at shift_prefix in tree hash1? */
-- if (!get_tree_entry_mode(r, hash1, shift_prefix, &sub1, &mode1) &&
+- if (!get_tree_entry(r, hash1, shift_prefix, &sub1, &mode1) &&
- S_ISDIR(mode1))
-+ if (!get_tree_entry_mode(r, hash1, shift_prefix, &sub1, &tmp) &&
++ if (!get_tree_entry(r, hash1, shift_prefix, &sub1, &tmp) &&
+ S_ISDIR(tmp))
candidate |= 1;
/* Can hash1 be a tree at shift_prefix in tree hash2? */
-- if (!get_tree_entry_mode(r, hash2, shift_prefix, &sub2, &mode2) &&
+- if (!get_tree_entry(r, hash2, shift_prefix, &sub2, &mode2) &&
- S_ISDIR(mode2))
-+ if (!get_tree_entry_mode(r, hash2, shift_prefix, &sub2, &tmp) &&
++ if (!get_tree_entry(r, hash2, shift_prefix, &sub2, &tmp) &&
+ S_ISDIR(tmp))
candidate |= 2;18: df43f1a76ac ! 12: 960e15bc7d5 tree.h: format argument lists of read_tree_recursive() users
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- tree.h: format argument lists of read_tree_recursive() users
+ tree.h: format argument lists of read_tree() users
- In preparation for adding a new argument to read_tree_fn_t re-indent
- and format the argument list of read_tree_recursive() callbacks, and
+ Re-indent and format the argument list of read_tree() callbacks, and
the relevant functions they call.
- This is a whitespace-only change to make reading subsequent commits
- easier. I'll be adding a new argument on the "mode" line, so leave
- space on it.
+ This is a whitespace-only change to make changes in a later series
+ easier to read. In that series I'll be adding a new argument on the
+ "mode" line, so leave space on it for a new argument.
19: 152c6d88542 < -: ----------- tree.h API: make read_tree_fn_t take an "enum object_type" 20: 1c2f65cb674 < -: ----------- tree-walk.h users: migrate "p->mode &&" pattern 21: 163922d427c < -: ----------- tree-walk.h users: refactor chained "mode" if/else into switch 22: 21df7c668be < -: ----------- tree-walk.h users: migrate miscellaneous "mode" to "object_type" 25: 685da1abbdc < -: ----------- fsck.c: switch on "object_type" in fsck_walk_tree() 27: 7251654dd52 ! 13: 9c96d472472 tree-walk.h API: formatting changes for subsequent commit
@@ Commit message
- ## blame.c ##
-@@ blame.c: static void verify_working_tree_path(struct repository *r,
- const struct object_id *commit_oid = &parents->item->object.oid;
- struct object_id blob_oid;
- unsigned short mode;
-+ int ret = get_tree_entry(r, commit_oid, path, &blob_oid,
-+ &mode);
-
-- if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
-- oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
-+ if (!ret && oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
- return;
- }
-
-
## tree-walk.c ##
@@ tree-walk.c: static int find_tree_entry(struct repository *r, struct tree_desc *t,
oidcpy(result, &oid);
30: 7f699bf2d5c ! 14: 44f16d74426 tree-walk.h API: add get_tree_entry_type()
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- tree-walk.h API: add get_tree_entry_type()
+ tree-walk.h API doc: improve documentation of get_tree_entry()
- Add a get_tree_entry_type() helper function to compliment the existing
- get_tree_entry(), and a static get_tree_entry_all() which it uses internally.
-
- Move those users of get_tree_entry_type() who didn't care about the
- mode specifically, but just want to know whether the tree entry is one
- of OBJ_{BLOB,COMMIT,TREE} over to the new get_tree_entry_type().
-
- The get_tree_entry_all() function itself will be made non-static in a
- subsequent commit. I'm leaving its argument list indented accordingly
- to reduce churn when I do so.
+ Change a mention of sha1 to OID and change the comment to a listing of
+ functions discussed below, right now there's only one function, but
+ subsequent commits will add more.
- ## archive.c ##
-@@ archive.c: static void parse_treeish_arg(const char **argv,
-
- if (prefix) {
- struct object_id tree_oid;
-- unsigned short mode;
-+ enum object_type object_type;
- int err;
-
-- err = get_tree_entry_mode(ar_args->repo,
-+ err = get_tree_entry_type(ar_args->repo,
- &tree->object.oid,
- prefix, &tree_oid,
-- &mode);
-- if (err || !S_ISDIR(mode))
-+ &object_type);
-+ if (err || object_type != OBJ_TREE)
- die(_("current working directory is untracked"));
-
- tree = parse_tree_indirect(&tree_oid);
-
- ## match-trees.c ##
-@@ match-trees.c: void shift_tree_by(struct repository *r,
- const char *shift_prefix)
- {
- struct object_id sub1, sub2;
-- unsigned short tmp;
-+ enum object_type tmp;
- unsigned candidate = 0;
-
- /* Can hash2 be a tree at shift_prefix in tree hash1? */
-- if (!get_tree_entry_mode(r, hash1, shift_prefix, &sub1, &tmp) &&
-- S_ISDIR(tmp))
-+ if (!get_tree_entry_type(r, hash1, shift_prefix, &sub1, &tmp) &&
-+ tmp == OBJ_TREE)
- candidate |= 1;
-
- /* Can hash1 be a tree at shift_prefix in tree hash2? */
-- if (!get_tree_entry_mode(r, hash2, shift_prefix, &sub2, &tmp) &&
-- S_ISDIR(tmp))
-+ if (!get_tree_entry_type(r, hash2, shift_prefix, &sub2, &tmp) &&
-+ tmp == OBJ_TREE)
- candidate |= 2;
-
- if (candidate == 3) {
-
- ## tree-walk.c ##
-@@ tree-walk.c: struct dir_state {
- struct object_id oid;
- };
-
-+static int get_tree_entry_all(struct repository *r,
-+ const struct object_id *tree_oid,
-+ const char *name,
-+ struct object_id *oid,
-+ unsigned short *mode,
-+ enum object_type *object_type);
-+
- static int find_tree_entry(struct repository *r, struct tree_desc *t,
- const char *name, struct object_id *result,
-- unsigned short *mode)
-+ unsigned short *mode,
-+ enum object_type *object_type)
- {
- int namelen = strlen(name);
- while (t->size) {
-@@ tree-walk.c: static int find_tree_entry(struct repository *r, struct tree_desc *t,
- }
- if (name[entrylen] != '/')
- continue;
-- if (!S_ISDIR(*mode))
-+ if (*object_type != OBJ_TREE)
- break;
- if (++entrylen == namelen) {
- oidcpy(result, &oid);
- return 0;
- }
-- return get_tree_entry_mode(r, &oid, name + entrylen, result,
-- mode);
-+ return get_tree_entry_all(r, &oid, name + entrylen, result,
-+ mode, object_type);
- }
- return -1;
- }
-
--int get_tree_entry_mode(struct repository *r,
-- const struct object_id *tree_oid,
-- const char *name,
-- struct object_id *oid,
-- unsigned short *mode)
-+static int get_tree_entry_all(struct repository *r,
-+ const struct object_id *tree_oid,
-+ const char *name,
-+ struct object_id *oid,
-+ unsigned short *mode,
-+ enum object_type *object_type)
- {
- int retval;
- void *tree;
-@@ tree-walk.c: int get_tree_entry_mode(struct repository *r,
- struct tree_desc t;
- init_tree_desc(&t, tree, size);
- retval = find_tree_entry(r, &t, name, oid,
-- mode);
-+ mode, object_type);
- }
- free(tree);
- return retval;
- }
-
-+int get_tree_entry_mode(struct repository *r,
-+ const struct object_id *tree_oid,
-+ const char *name,
-+ struct object_id *oid,
-+ unsigned short *mode)
-+{
-+ enum object_type object_type;
-+ return get_tree_entry_all(r, tree_oid, name, oid,
-+ mode, &object_type);
-+}
-+
-+int get_tree_entry_type(struct repository *r,
-+ const struct object_id *tree_oid,
-+ const char *name,
-+ struct object_id *oid,
-+ enum object_type *object_type)
-+{
-+ unsigned short mode;
-+ return get_tree_entry_all(r, tree_oid, name, oid,
-+ &mode, object_type);
-+}
-+
- /*
- * This is Linux's built-in max for the number of symlinks to follow.
- * That limit, of course, does not affect git, but it's a reasonable
-@@ tree-walk.c: enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
- int find_result;
- char *first_slash;
- char *remainder = NULL;
-+ enum object_type object_type;
-
- if (!t.buffer) {
- void *tree;
-@@ tree-walk.c: enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
- /* Look up the first (or only) path component in the tree. */
- find_result = find_tree_entry(r, &t, namebuf.buf,
- ¤t_tree_oid,
-- mode);
-+ mode, &object_type);
- if (find_result) {
- goto done;
- }
-
## tree-walk.h ##
@@ tree-walk.h: struct traverse_info {
- * Find an entry in a tree given a pathname and the sha1 of a tree to
+ };
+
+ /**
+- * Find an entry in a tree given a pathname and the sha1 of a tree to
++ * Find an entry in a tree given a pathname and the OID of a tree to
* search. Returns 0 if the entry is found and -1 otherwise.
*
- * The third and fourth parameters are set to the entry's sha1 and
- * mode respectively.
-+ * There are variants of this function depending on what fields in the
-+ * "struct name_entry" you'd like. You always need a pointer to an
-+ * appropriate variable to fill in (NULL won't do!):
++ * You always need a pointer to an appropriate variable to fill in
++ * (NULL won't do!). That variable is:
+ *
-+ * get_tree_entry_mode(): unsigned int mode
-+ * get_tree_entry_type(): enum object_type
++ * get_tree_entry(): unsigned short mode
*/
- int get_tree_entry_mode(struct repository *, const struct object_id *, const char *,
- struct object_id *,
- unsigned short *);
-+int get_tree_entry_type(struct repository *, const struct object_id *, const char *,
-+ struct object_id *,
-+ enum object_type *);
-
- /**
- * Generate the full pathname of a tree entry based from the root of the
+ int get_tree_entry(struct repository *, const struct object_id *, const char *,
+ struct object_id *,
28: 9e521a3cbf2 ! 15: adbada0ade8 tree-walk.h API: rename get_tree_entry() to get_tree_entry_mode()
@@ Commit message
change is only a search-replacement of the name and indentation of the argument lists.
- A subsequent commits will add get_tree_entry_type() and
- get_tree_entry_all() functions. Those changes will be much easier to
- read if we do this rename first.
+ Subsequent commits will add another get_tree_entry_*() function. Those
+ changes will be much easier to read if we do this rename first.
@@ blame.c: static void verify_working_tree_path(struct repository *r,
const struct object_id *commit_oid = &parents->item->object.oid; struct object_id blob_oid;
unsigned short mode;
-- int ret = get_tree_entry(r, commit_oid, path, &blob_oid,
-- &mode);
-+ int ret = get_tree_entry_mode(r, commit_oid, path, &blob_oid,
-+ &mode);
-
- if (!ret && oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
+-
+- if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode))
++ if (!get_tree_entry_mode(r, commit_oid, path, &blob_oid, &mode))
return;
+ }
+
@@ blame.c: static int fill_blob_sha1_and_mode(struct repository *r,
{
if (!is_null_oid(&origin->blob_oid))
@@ match-trees.c: void shift_tree_by(struct repository *r,
unsigned candidate = 0;
/* Can hash2 be a tree at shift_prefix in tree hash1? */
-- if (!get_tree_entry(r, hash1, shift_prefix, &sub1, &mode1) &&
-+ if (!get_tree_entry_mode(r, hash1, shift_prefix, &sub1, &mode1) &&
- S_ISDIR(mode1))
+- if (!get_tree_entry(r, hash1, shift_prefix, &sub1, &tmp) &&
++ if (!get_tree_entry_mode(r, hash1, shift_prefix, &sub1, &tmp) &&
+ S_ISDIR(tmp))
candidate |= 1;
/* Can hash1 be a tree at shift_prefix in tree hash2? */
-- if (!get_tree_entry(r, hash2, shift_prefix, &sub2, &mode2) &&
-+ if (!get_tree_entry_mode(r, hash2, shift_prefix, &sub2, &mode2) &&
- S_ISDIR(mode2))
+- if (!get_tree_entry(r, hash2, shift_prefix, &sub2, &tmp) &&
++ if (!get_tree_entry_mode(r, hash2, shift_prefix, &sub2, &tmp) &&
+ S_ISDIR(tmp))
candidate |= 2;
@@ tree-walk.c: static int find_tree_entry(struct repository *r, struct tree_desc *
## tree-walk.h ##
@@ tree-walk.h: struct traverse_info {
- * The third and fourth parameters are set to the entry's sha1 and
- * mode respectively.
+ * You always need a pointer to an appropriate variable to fill in
+ * (NULL won't do!). That variable is:
+ *
+- * get_tree_entry(): unsigned short mode
++ * get_tree_entry_mode(): unsigned short mode
*/
-int get_tree_entry(struct repository *, const struct object_id *, const char *,
- struct object_id *,
35: a2a34fd3e2d ! 16: 3ba77fd3a47 tree-walk.h API: add a get_tree_entry_path() function
@@ Commit message
tree-walk.h API: add a get_tree_entry_path() function
Add a get_tree_entry_path() variant in addition to
- get_tree_entry_path_{mode,type,all}(). This is for those callers that
- need neither the mode nor "enum object_type" parameters filled for
- them.
+ get_tree_entry_path_mode(). This is for those callers that don't need
+ the "mode" filled for them.
- There are callers here which don't need the "struct object_id" filled;
- forcing callers to pass one just requires they create a throwaway
- variable.
+ There are callers here which don't need the "struct object_id" filled
+ either, but let's leave that for now. I'm focusing downstream code
+ that depends on "mode" (or "enum object_type").
- See the following commits for the introduction of such code that's
- being modified here:
+ The code being modified here was introduced in:
- shift_tree(): 68faf68938e (A new merge stragety[sic] 'subtree'., 2007-02-15) for the shift_tree()
@@ Commit message
- diagnose_invalid_oid_path(): 009fee4774d (Detailed diagnosis when parsing an object name fails., 2009-12-07)
- Those could potentially be refactored too, but I've got to stop at
- some point, and right now I'm focusing downstream code that depends on
- "mode" (or "enum object_type").
-
## match-trees.c ##
@@ object-name.c: static void diagnose_invalid_oid_path(struct repository *r,
fullname,
## tree-walk.c ##
-@@ tree-walk.c: int get_tree_entry_all(struct repository *r, +@@ tree-walk.c: int get_tree_entry_mode(struct repository *r,
return retval;
}
@@ tree-walk.c: int get_tree_entry_all(struct repository *r,
+ struct object_id *oid)
+{
+ unsigned short mode;
-+ enum object_type object_type;
-+ return get_tree_entry_all(r, tree_oid, name, oid,
-+ &mode, &object_type);
++ return get_tree_entry_mode(r, tree_oid, name, oid, &mode);
+}
+
- int get_tree_entry_mode(struct repository *r,
- const struct object_id *tree_oid,
- const char *name,
+ /*
+ * This is Linux's built-in max for the number of symlinks to follow.
+ * That limit, of course, does not affect git, but it's a reasonable
## tree-walk.h ##
@@ tree-walk.h: struct traverse_info {
- * "struct name_entry" you'd like. You always need a pointer to an
- * appropriate variable to fill in (NULL won't do!):
+ * You always need a pointer to an appropriate variable to fill in
+ * (NULL won't do!). That variable is:
*
+ * get_tree_entry_path(): <no extra argument, just get the common 'path'>
- * get_tree_entry_mode(): unsigned int mode
- * get_tree_entry_type(): enum object_type
- * get_tree_entry_all(): unsigned int mode, enum object_type
+ * get_tree_entry_mode(): unsigned short mode
*/
+int get_tree_entry_path(struct repository *, const struct object_id *, const char *,
+ struct object_id *);
31: 7ab7576cb16 ! 17: dc895822828 tree-walk.h API: document and format tree_entry_extract()
@@ Commit message
tree-walk.h API: document and format tree_entry_extract()
Document and format the argument list of the tree_entry_extract()
- function in preparation for adding a sister function.
+ function in preparation for eventually adding a sister function.
@@ tree-walk.h: struct tree_desc {
+ * "struct name_entry" you'd like. You always need a pointer to an
+ * appropriate variable to fill in (NULL won't do!):
+ *
-+ * tree_entry_extract_mode(): const char *path, unsigned int mode
++ * tree_entry_extract(): const char *path, unsigned int mode
*/
-static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned short *modep) +static inline const struct object_id *tree_entry_extract(struct tree_desc *desc,
32: a1bd81d64aa ! 18: e961a0e8b5b tree-entry.h API: rename tree_entry_extract() to tree_entry_extract_mode()
@@ tree-diff.c: static struct combine_diff_path *emit_path(struct combine_diff_path
isdir = S_ISDIR(mode);
+ ## tree-walk.c ##
+@@ tree-walk.c: static int find_tree_entry(struct repository *r, struct tree_desc *t,
+ struct object_id oid;
+ int entrylen, cmp;
+
+- oidcpy(&oid, tree_entry_extract(t, &entry, mode));
++ oidcpy(&oid, tree_entry_extract_mode(t, &entry, mode));
+ entrylen = tree_entry_len(&t->entry);
+ update_tree_entry(t);
+ if (entrylen > namelen)
+
## tree-walk.h ##
@@ tree-walk.h: struct tree_desc {
+ * "struct name_entry" you'd like. You always need a pointer to an
+ * appropriate variable to fill in (NULL won't do!):
*
- * tree_entry_extract_mode(): const char *path, unsigned int mode
+- * tree_entry_extract(): const char *path, unsigned int mode
++ * tree_entry_extract_mode(): const char *path, unsigned int mode
*/
-static inline const struct object_id *tree_entry_extract(struct tree_desc *desc,
- const char **pathp,
33: ce7c19ad39c < -: ----------- tree-walk.h API: add a tree_entry_extract_all() function 34: 95eec961be8 < -: ----------- tree-walk.h API: add get_tree_entry_all() 37: 4d51da4ea39 < -: ----------- tree-walk.h API: add a tree_entry_extract_type() function
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 1/18 cache.h: add a comment to object_type()
Add a comment to the object_type() function to explain what it returns, and what the "mode" is in the "else" case.
The object_type() function dates back to 4d1012c3709 (Fix rev-list when showing objects involving submodules, 2007-11-11). It's not immediately obvious to someone looking at its history and how it's come to be used.
Despite what Linus noted in 4d1012c3709 (Fix rev-list when showing objects involving submodules, 2007-11-11) about wanting to move away from users of object_type() relying on S_ISLNK(mode) being true here we do currently rely on that. If this is changed to a condition to only return OBJ_BLOB on S_ISREG(mode) then t4008, t4023 and t7415 will have failing tests.
--- cache.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
cache.h +6 -1
@@ -451,11 +451,16 @@ enum object_type { OBJ_MAX }; +/* +* object_type() returns an object of a type that'll appear in a tree, +* so no OBJ_TAG is possible. This is mostly (and dates back to) +* consumers of the tree-walk.h API's "mode" field. +*/ static inline enum object_type object_type (unsigned int mode) {return S_ISDIR (mode) ?OBJ_TREE :S_ISGITLINK (mode) ?OBJ_COMMIT : -OBJ_BLOB ; +OBJ_BLOB ;/* S_ISREG(mode) || S_ISLNK(mode) */ }/* Double-check local_repo_env below if you add to this list. */
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 2/18 merge-ort: correct reference to test in 62fdec17a11
In reply to Ævar Arnfjörð BjarmasonFix a comment added in 62fdec17a11 (merge-ort: flesh out implementation of handle_content_merge(), 2021-01-01).
The test being referred to here was moved from t6036 in 919df319555 (Collect merge-related tests to t64xx, 2020-08-10).
It has also had the plural of "mode" in the name ever since being introduced in 5d1daf30cce (t6036: add a failed conflict detection
case: regular files, different modes, 2018-06-30).
--- merge-ort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
merge-ort.c +1 -1
@@ -1073,7 +1073,7 @@ static int handle_content_merge(struct merge_options *opt,/* * FIXME: If opt->priv->call_depth && !clean, then we really * should not make result->mode match either a->mode or -* b->mode; that causes t6036 "check conflicting mode for +* b->mode; that causes t6416 "check conflicting modes for * regular file" to fail. It would be best to use some other * mode, but we'll confuse all kinds of stuff if we use one * where S_ISREG(result->mode) isn't true, and if we use
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 3/18 cache.h: have base_name_compare() take "is tree?", not "mode"
In reply to Ævar Arnfjörð BjarmasonChange the base_name_compare() API and the related df_name_compare() function to take a boolean argument indicating whether the entry is a tree or not, instead of having them call S_ISDIR(mode) on their own.
This introduces no functional change, but makes later (not part of this series) changes to abstract away "object_type" from "mode" more readable.
The API being modified here was originally added way back in 958ba6c96eb (Introduce "base_name_compare()" helper function, 2005-05-20).
None of these comparison functions used to have tests, but with preceding commits some of them now do. I thought the remainder was trivial enough to review without tests, and didn't want to spend more time on them.
--- builtin/fast-import.c | 12 ++++++++---- builtin/mktree.c | 4 ++-- cache.h | 4 ++-- combine-diff.c | 8 +++++--- match-trees.c | 6 ++++-- merge-ort.c | 4 ++-- merge-recursive.c | 6 +++--- read-cache.c | 16 ++++++++-------- tree-diff.c | 7 +++++-- unpack-trees.c | 15 ++++++++------- 10 files changed, 47 insertions(+), 35 deletions(-)
builtin/fast-import.c +8 -4
@@ -1287,18 +1287,22 @@ static int tecmp0 (const void *_a, const void *_b) {struct tree_entry *a = *((struct tree_entry **)_a);struct tree_entry *b = *((struct tree_entry **)_b); +int istree_a =S_ISDIR (a->versions[0 ].mode); +int istree_b =S_ISDIR (b->versions[0 ].mode);return base_name_compare ( - a->name->str_dat, a->name->str_len, a->versions[0 ].mode, - b->name->str_dat, b->name->str_len, b->versions[0 ].mode); + a->name->str_dat, a->name->str_len, istree_a, + b->name->str_dat, b->name->str_len, istree_b); }static int tecmp1 (const void *_a,const void *_b) {struct tree_entry *a = *((struct tree_entry **)_a);struct tree_entry *b = *((struct tree_entry **)_b); +int istree_a =S_ISDIR (a->versions[1 ].mode); +int istree_b =S_ISDIR (b->versions[1 ].mode);return base_name_compare ( - a->name->str_dat, a->name->str_len, a->versions[1 ].mode, - b->name->str_dat, b->name->str_len, b->versions[1 ].mode); + a->name->str_dat, a->name->str_len, istree_a, + b->name->str_dat, b->name->str_len, istree_b); }static void mktree (struct tree_content *t,int v,struct strbuf *b)
builtin/mktree.c +2 -2
@@ -37,8 +37,8 @@ static int ent_compare(const void *a_, const void *b_) {struct treeent *a = *(struct treeent **)a_;struct treeent *b = *(struct treeent **)b_; -return base_name_compare (a->name, a->len, a->mode, - b->name, b->len, b->mode); +return base_name_compare (a->name, a->len,S_ISDIR (a->mode), + b->name, b->len,S_ISDIR (b->mode)); }static void write_tree (struct object_id *oid)
cache.h +2 -2
@@ -1506,8 +1506,8 @@ int repo_interpret_branch_name(struct repository *r,int validate_headref (const char *ref); -int base_name_compare (const char *name1,int len1,int mode1,const char *name2,int len2,int mode2); -int df_name_compare (const char *name1,int len1,int mode1,const char *name2,int len2,int mode2); +int base_name_compare (const char *name1,int len1,int istree1,const char *name2,int len2,int istree2); +int df_name_compare (const char *name1,int len1,int istree1,const char *name2,int len2,int istree2);int name_compare (const char *name1,size_t len1,const char *name2,size_t len2);int cache_name_stage_compare (const char *name1,int len1,int stage1,const char *name2,int len2,int stage2);
combine-diff.c +5 -3
@@ -16,11 +16,13 @@static int compare_paths (const struct combine_diff_path *one,const struct diff_filespec *two) { -if (!S_ISDIR (one->mode) && !S_ISDIR (two->mode)) +int istree_one =S_ISDIR (one->mode); +int istree_two =S_ISDIR (two->mode); +if (!istree_one && !istree_two)return strcmp (one->path, two->path); -return base_name_compare (one->path,strlen (one->path), one->mode, - two->path,strlen (two->path), two->mode); +return base_name_compare (one->path,strlen (one->path), istree_one, + two->path,strlen (two->path), istree_two); }static int filename_changed (char status)
match-trees.c +4 -2
@@ -67,8 +67,10 @@ static void *fill_tree_desc_strict(struct tree_desc *desc,static int base_name_entries_compare (const struct name_entry *a,const struct name_entry *b) { -return base_name_compare (a->path,tree_entry_len (a), a->mode, - b->path,tree_entry_len (b), b->mode); +int istree_a =S_ISDIR (a->mode); +int istree_b =S_ISDIR (b->mode); +return base_name_compare (a->path,tree_entry_len (a), istree_a, + b->path,tree_entry_len (b), istree_b); }/*
merge-ort.c +2 -2
@@ -2257,8 +2257,8 @@ static int tree_entry_order(const void *a_, const void *b_)const struct merged_info *ami = a->util;const struct merged_info *bmi = b->util; -return base_name_compare (a->string,strlen (a->string), ami->result.mode, - b->string,strlen (b->string), bmi->result.mode); +return base_name_compare (a->string,strlen (a->string),S_ISDIR (ami->result.mode), + b->string,strlen (b->string),S_ISDIR (bmi->result.mode)); } static void write_tree(struct object_id *result_oid,
merge-recursive.c +3 -3
@@ -554,12 +554,12 @@ static int string_list_df_name_compare(const char *one, const char *two)* * To achieve this, we sort with df_name_compare and provide * the mode S_IFDIR so that D/F conflicts will sort correctly. -* We use the mode S_IFDIR for everything else for simplicity, +* We say we have a directory for everything else for simplicity, * since in other cases any changes in their order due to * sorting cause no problems for us. */ -int cmp =df_name_compare (one, onelen,S_IFDIR , - two, twolen,S_IFDIR ); +int cmp =df_name_compare (one, onelen,1 , two, twolen,1 ); +/* * Now that 'foo' and 'foo/bar' compare equal, we have to make sure * that 'foo' comes before 'foo/bar'.
read-cache.c +8 -8
@@ -462,8 +462,8 @@ int ie_modified(struct index_state *istate,return 0 ; } -int base_name_compare (const char *name1,int len1,int mode1, -const char *name2,int len2,int mode2) +int base_name_compare (const char *name1,int len1,int istree1, +const char *name2,int len2,int istree2) {unsigned char c1, c2;int len = len1 < len2 ? len1 : len2;
@@ -474,9 +474,9 @@ int base_name_compare(const char *name1, int len1, int mode1,return cmp; c1 = name1[len]; c2 = name2[len]; -if (!c1 &&S_ISDIR (mode1)) +if (!c1 && istree1) c1 ='/' ; -if (!c2 &&S_ISDIR (mode2)) +if (!c2 && istree2) c2 ='/' ;return (c1 < c2) ?-1 : (c1 > c2) ?1 :0 ; }
@@ -491,8 +491,8 @@ int base_name_compare(const char *name1, int len1, int mode1,* This is used by routines that want to traverse the git namespace * but then handle conflicting entries together when possible. */ -int df_name_compare (const char *name1,int len1,int mode1, -const char *name2,int len2,int mode2) +int df_name_compare (const char *name1,int len1,int istree1, +const char *name2,int len2,int istree2) {int len = len1 < len2 ? len1 : len2, cmp;unsigned char c1, c2;
@@ -504,10 +504,10 @@ int df_name_compare(const char *name1, int len1, int mode1,if (len1 == len2)return 0 ; c1 = name1[len]; -if (!c1 &&S_ISDIR (mode1)) +if (!c1 && istree1) c1 ='/' ; c2 = name2[len]; -if (!c2 &&S_ISDIR (mode2)) +if (!c2 && istree2) c2 ='/' ;if (c1 =='/' && !c2)return 0 ;
tree-diff.c +5 -2
@@ -50,6 +50,7 @@ static int tree_entry_pathcmp(struct tree_desc *t1, struct tree_desc *t2) {struct name_entry *e1, *e2;int cmp; +int istree_e1, istree_e2;/* empty descriptors sort after valid tree entries */ if (!t1->size)
@@ -58,9 +59,11 @@ static int tree_entry_pathcmp(struct tree_desc *t1, struct tree_desc *t2)return -1 ; e1 = &t1->entry; + istree_e1 =S_ISDIR (e1->mode); e2 = &t2->entry; - cmp =base_name_compare (e1->path,tree_entry_len (e1), e1->mode, - e2->path,tree_entry_len (e2), e2->mode); + istree_e2 =S_ISDIR (e2->mode); + cmp =base_name_compare (e1->path,tree_entry_len (e1), istree_e1, + e2->path,tree_entry_len (e2), istree_e2);return cmp; }
unpack-trees.c +8 -7
@@ -925,7 +925,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,static int do_compare_entry_piecewise (const struct cache_entry *ce,const struct traverse_info *info,const char *name,size_t namelen, -unsigned mode) +unsigned istree) {int pathlen, ce_len;const char *ce_name;
@@ -933,7 +933,7 @@ static int do_compare_entry_piecewise(const struct cache_entry *ce,if (info->prev) {int cmp =do_compare_entry_piecewise (ce, info->prev, info->name, info->namelen, - info->mode); +S_ISDIR (info->mode));if (cmp)return cmp; }
@@ -947,13 +947,13 @@ static int do_compare_entry_piecewise(const struct cache_entry *ce, ce_len -= pathlen; ce_name = ce->name + pathlen; -return df_name_compare (ce_name, ce_len,S_IFREG , name, namelen, mode); +return df_name_compare (ce_name, ce_len,0 , name, namelen, istree); }static int do_compare_entry (const struct cache_entry *ce,const struct traverse_info *info,const char *name,size_t namelen, -unsigned mode) +unsigned istree) {int pathlen, ce_len;const char *ce_name;
@@ -965,7 +965,7 @@ static int do_compare_entry(const struct cache_entry *ce,* it is quicker to use the precomputed version. */ if (!info->traverse_path) -return do_compare_entry_piecewise (ce, info, name, namelen, mode); +return do_compare_entry_piecewise (ce, info, name, namelen, istree); cmp =strncmp (ce->name, info->traverse_path, info->pathlen);if (cmp)
@@ -980,12 +980,13 @@ static int do_compare_entry(const struct cache_entry *ce, ce_len -= pathlen; ce_name = ce->name + pathlen; -return df_name_compare (ce_name, ce_len,S_IFREG , name, namelen, mode); +return df_name_compare (ce_name, ce_len,0 , name, namelen, istree); }static int compare_entry (const struct cache_entry *ce,const struct traverse_info *info,const struct name_entry *n) { -int cmp =do_compare_entry (ce, info, n->path, n->pathlen, n->mode); +int istree =S_ISDIR (n->mode); +int cmp =do_compare_entry (ce, info, n->path, n->pathlen, istree);if (cmp)return cmp;
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 4/18 fast-import tests: test for sorting dir/file foo v.s. foo.txt
In reply to Ævar Arnfjörð BjarmasonAdd a missing test for the sorting of "foo" v.s. "foo.txt" where "foo" can be either a file or a directory. If it's a file then "foo" should sort before "foo.txt", and the other way around if "foo" is a directory.
See [1] for a reply to a patch of mine introducing such a regression. We now finally have a test for this code added back in 463acbe1c6 (Added tree and commit writing to fast-import., 2006-08-14).
This tests both the tecmp1() and tecmp0() functions introduced inn 4cabf8583f (Implemented tree delta compression in fast-import., 2006-08-28).
This will catch cases where the "mode" is the same, or reversed between a & b in both functions.
There was an existing test for the tecmp1() function(s) just above this one added here.
That existing test was added in e741130386 (New fast-import test case for valid tree sorting, 2007-03-12) and would catch cases where entries were reversed, but not if their mode (or rather, type) was the the same or otherwise wrong value.
There were no tests at all for the tecmp0() function. As with the tecmp1() test the new test will catch cases where the "mode" is the same (e.g. "1"), or if the two are reversed. It won't catch a "return 0" from the function (i.e. already sorted), that case requires tecmp1() to also be broken.
1. https://lore.kernel.org/git/CABPp-BEZfG_pNNTWsnxEa1xG+kgpQfpXj=KHBkCBAMikrXj-aA@mail.gmail.com/
--- t/t9300-fast-import.sh | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
t/t9300-fast-import.sh +87 -0
@@ -955,6 +955,93 @@ test_expect_success 'L: verify internal tree sorting' ' test_cmp expect actual ' +test_expect_success 'L: verify internal tree sorting on bad input (tecmp1)' ' + test_create_repo L1-0 && + + cat >input <<-INPUT_END && + blob + mark :1 + data 0 + + reset refs/heads/L1-0 + commit refs/heads/L1-0 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + create L1-0 + COMMIT + M 100644 :1 x.txt + M 100644 :1 x/y.txt + M 100644 :1 z.txt + M 100644 :1 z + INPUT_END + + cat >expected <<-EXPECT_END && + x.txt + x + z + z.txt + EXPECT_END + + git -C L1-0 fast-import <input && + git -C L1-0 ls-tree L1-0 >tmp && + cut -f 2 <tmp >actual && + test_cmp expected actual && + git -C L1-0 fsck 2>err && + # Would happen if tecmp1() were broken + ! grep "error in tree .*: treeNotSorted: " err +' + +test_expect_success 'L: verify internal tree sorting on bad input (tecmp0)' ' + + test_create_repo L1-1 && + + cat >input <<-INPUT_END && + blob + mark :1 + data <<EOF + some data + EOF + + reset refs/heads/L1-1 + commit refs/heads/L1-1 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + create L1-1 + COMMIT + M 100644 :1 x.txt + M 100644 :1 x/y.txt + M 100644 :1 z.txt + M 100644 :1 z + + commit refs/heads/L1-1 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + update L1-1 + COMMIT + M 100644 :1 another.txt + M 100644 :1 x.txt + M 100644 :1 x/y.txt + M 100644 :1 z.txt + M 100644 :1 z + INPUT_END + + cat >expected <<-EXPECT_END && + another.txt + x.txt + x + z + z.txt + EXPECT_END + + git -C L1-1 fast-import <input && + git -C L1-1 ls-tree L1-1 >tmp 2>err && + # Would happen if tecmp0() passed a fixed mode + ! grep "fatal: not a tree object" err && + cut -f 2 <tmp >actual && + test_cmp expected actual && + git -C L1-1 fsck +' + test_expect_success 'L: nested tree copy does not corrupt deltas' ' cat >input <<-INPUT_END && blob
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 5/18 mktree tests: test that "mode" is passed when sorting
In reply to Ævar Arnfjörð BjarmasonAdd a test for the mode being passed to ent_compare(). That code dates back to 83f50539a9 (git-mktree: reverse of git-ls-tree., 2006-02-20) and there's never been a test for that particular edge case. Now we have one.
I don't see how anything could run into this in practice. In order for that mode sorting to matter as a tiebreaker we need to have a duplicate entry in the tree, i.e. two "foo" entries, one a blob and one a tree. This asserts that if that happens we'll sort on the modes we encounter in such an invalid entry, i.e. we expect the tree entry before the blob.
As shown here we'd need to disable the fsck.duplicateEntries error to get to the point of running "mktree", so I doubt anyone's pushing this sort of data around.
--- t/t1450-fsck.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
t/t1450-fsck.sh +44 -0
@@ -318,6 +318,50 @@ test_expect_success 'tree entry with type mismatch' ' test_i18ngrep ! "dangling blob" out ' +test_expect_success 'tree entry with duplicate type mismatching objects' ' + test_create_repo duplicate-entry && + ( + cd duplicate-entry && + blob="$(printf "foo" | git hash-object -w --stdin)" && + tree="$(printf "100644 blob $blob\tfoo" | git mktree)" && + commit="$(git commit-tree $tree -m "first commit")" && + git cat-file commit $commit >good-commit && + + # First bad commit, wrong type, but in the right order + printf "40000 A\0$(echo $tree | hex2oct)" >broken-tree-A && + printf "100644 A\0$(echo $blob | hex2oct)" >broken-tree-B && + cat broken-tree-A broken-tree-B >broken-tree.1 && + broken_tree1="$(git hash-object -w --literally -t tree broken-tree.1)" && + bad_commit1="$(git commit-tree $broken_tree1 -m "bad commit 1")" && + git cat-file commit $bad_commit1 >bad-commit.1 && + git update-ref refs/heads/broken-commit-1 $bad_commit1 && + + test_must_fail git fsck && + git -c fsck.duplicateEntries=warn fsck 2>err && + grep " in tree .*$broken_tree1: duplicateEntries" err && + + # Second bad commits, wrong types and order + cat broken-tree-B broken-tree-A >broken-tree.2 && + broken_tree2="$(git hash-object -w --literally -t tree broken-tree.2)" && + bad_commit2="$(git commit-tree $broken_tree2 -m "bad commit 2")" && + git cat-file commit $bad_commit2 >bad-commit.2 && + git update-ref refs/heads/broken-commit-2 $bad_commit2 && + + test_must_fail git fsck && + git -c fsck.duplicateEntries=warn fsck 2>err && + grep " in tree .*$broken_tree2: duplicateEntries" err && + + # git mktree should "fix" the order of this already broken data + git ls-tree broken-commit-1 >broken-tree-1-ls && + git ls-tree broken-commit-2 >broken-tree-2-ls && + ! test_cmp broken-tree-1-ls broken-tree-2-ls && + + git mktree <broken-tree-1-ls >broken-mktree-1 && + git mktree <broken-tree-2-ls >broken-mktree-2 && + test_cmp broken-mktree-1 broken-mktree-2 + ) +' + test_expect_success 'tag pointing to nonexistent' ' badoid=$(test_oid deadbeef) && cat >invalid-tag <<-EOF &&
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 6/18 diff tests: test that "mode" is passed when sorting
In reply to Ævar Arnfjörð BjarmasonPiggy-back on the recently added fsck tests for mode comparisons in mktree and assert that diff-tree also does the right thing in this implausible scenario.
As with the other tests I've added in preceding commits, these tests will fail if the mode is the same or reversed, respectively.
The diff-tree code being tested here was originally added back in .9174026cfe (Add "diff-tree" program to show which files have changed between two trees., 2005-04-09).
Unlike the other tests I've added there are existing tests for both of these scenarios. Breaking that function as described above will make tests in t4002-diff-basic.sh, t6409-merge-subtree.sh and t4037-diff-r-t-dirs.sh fail.
I think it's good to have tests for this regardless, so let's add these.
--- t/t1450-fsck.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
t/t1450-fsck.sh +22 -0
@@ -362,6 +362,28 @@ test_expect_success 'tree entry with duplicate type mismatching objects' ' ) ' +test_expect_success 'diff-tree stressing tree-diff.c::tree_entry_pathcmp(), not the same type' ' + zero=$(test_oid zero) && + git -C duplicate-entry diff-tree broken-commit-1 broken-commit-2 >1-to-2 && + grep "$zero" 1-to-2 >lines && + test_line_count = 2 lines && + + git -C duplicate-entry diff-tree broken-commit-2 broken-commit-1 >2-to-1 && + grep "$zero" 2-to-1 >lines && + test_line_count = 2 lines +' + +test_expect_success 'diff-tree stressing tree-diff.c::tree_entry_pathcmp(), types not reversed' ' + blob_ok=$(git -C duplicate-entry rev-parse broken-commit-2:A) && + git -C duplicate-entry diff-tree --diff-filter=A broken-commit-1 broken-commit-2 >1-to-2 && + grep "$blob_ok" 1-to-2 && + test_line_count = 1 1-to-2 && + + git -C duplicate-entry diff-tree --diff-filter=A broken-commit-2 broken-commit-1 >2-to-1 && + grep "$blob_ok" 2-to-1 && + test_line_count = 1 2-to-1 +' + test_expect_success 'tag pointing to nonexistent' ' badoid=$(test_oid deadbeef) && cat >invalid-tag <<-EOF &&
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 7/18 merge-tree tests: test for the mode comparison in same_entry()
In reply to Ævar Arnfjörð BjarmasonAdd a test to stress the "a->mode == b->mode" comparison in merge-tree.c's same_entry().
That code was initially added by Linus in 33deb63a36f (Add "merge-tree" helper program. Maybe it's retarded, maybe it's helpful., 2005-04-14), and then again in its current form in 492e0759bfe (Handling large files with GIT, 2006-02-14).
However, nothing was testing that we handled this case correctly. Simply removing the mode comparison left all tests passing, but as seen here it's important that we don't think a path with the same content but different modes is the same_entry().
--- t/t4300-merge-tree.sh | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
t/t4300-merge-tree.sh +44 -0
@@ -40,6 +40,25 @@ test_expect_success 'file add A, B (same)' ' test_must_be_empty actual ' +test_expect_success 'file add A, B (different mode)' ' + git reset --hard initial && + test_commit "add-a-b-same-diff-mode-A" "ONE" "AAA" && + git reset --hard initial && + echo AAA >ONE && + test_chmod +x ONE && + test_tick && + git commit -m"add-a-b-same-diff-mode-B" && + git tag "add-a-b-same-diff-mode-B" HEAD && + git merge-tree initial add-a-b-same-diff-mode-A add-a-b-same-diff-mode-B >actual && + cat >expected <<EXPECTED && +added in both + our 100644 $(git rev-parse add-a-b-same-diff-mode-A:ONE) ONE + their 100755 $(git rev-parse add-a-b-same-diff-mode-B:ONE) ONE +EXPECTED + + test_cmp expected actual +' + test_expect_success 'file add A, B (different)' ' git reset --hard initial && test_commit "add-a-b-diff-A" "ONE" "AAA" &&
@@ -61,6 +80,31 @@ EXPECTED test_cmp expected actual ' +test_expect_success 'file add A, B (different and different mode)' ' + git reset --hard initial && + test_commit "add-a-b-diff-diff-mode-A" "ONE" "AAA" && + git reset --hard initial && + echo BBB >ONE && + test_chmod +x ONE && + test_tick && + git commit -m"add-a-b-diff-diff-mode-B" && + git tag "add-a-b-diff-diff-mode-B" && + git merge-tree initial add-a-b-diff-diff-mode-A add-a-b-diff-diff-mode-B >actual && + cat >expected <<EXPECTED && +added in both + our 100644 $(git rev-parse add-a-b-diff-diff-mode-A:ONE) ONE + their 100755 $(git rev-parse add-a-b-diff-diff-mode-B:ONE) ONE +@@ -1 +1,5 @@ ++<<<<<<< .our + AAA ++======= ++BBB ++>>>>>>> .their +EXPECTED + + test_cmp expected actual +' + test_expect_success 'file change A, !B' ' git reset --hard initial && test_commit "change-a-not-b" "initial-file" "BBB" &&
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 8/18 blame: emit a better error on 'git blame directory'
In reply to Ævar Arnfjörð BjarmasonChange an early check for non-blobs in verify_working_tree_path() to let any such objects pass, and instead die shortly thereafter in the fake_working_tree_commit() caller's type check.
Now e.g. doing "git blame t" in git.git emits:
fatal: unsupported file type t
Instead of:
fatal: no such path 't' in HEAD
The main point of this test is to assert that we're not doing something uniquely bad when in a conflicted merge. See cd8ae20195 (git-blame shouldn't crash if run in an unmerged tree, 2007-10-18) and 9aeaab6811 (blame: allow "blame file" in the middle of a conflicted merge, 2012-09-11) for the bug the test was originally meant to address.
But when extending it let's grep out the specific error message for good measure. Having to change it in the future (e.g. as part of my parallel series to improve such 'OID does not match type' messages) is a small price for ensuring it doesn't regress.
--- blame.c | 3 +-- t/t8004-blame-with-conflicts.sh | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-)
blame.c +1 -2
@@ -103,8 +103,7 @@ static void verify_working_tree_path(struct repository *r,struct object_id blob_oid;unsigned short mode; -if (!get_tree_entry (r, commit_oid, path, &blob_oid, &mode) && -oid_object_info (r, &blob_oid,NULL ) ==OBJ_BLOB ) +if (!get_tree_entry (r, commit_oid, path, &blob_oid, &mode))return ; }
t/t8004-blame-with-conflicts.sh +21 -0
@@ -73,4 +73,25 @@ test_expect_success 'blame does not crash with conflicted file in stages 1,3' ' git blame file1 ' +test_expect_success 'setup second case' ' + git merge --abort +' + +test_expect_success 'blame on directory/file conflict' ' + mkdir d && + test_commit second && + test_commit d/file && + test_must_fail git blame d 2>expected && + grep "unsupported file type d" expected && + + git reset --hard second && + >d && + git add d && + git commit -m"a not-a-dir" && + test_must_fail git merge d/file && + + test_must_fail git blame d 2>actual && + test_cmp expected actual +' + test_done
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 9/18 notes & match-trees: use name_entry's "pathlen" member
In reply to Ævar Arnfjörð BjarmasonChange code that was doing a strlen() on the "path" from a name_entry struct to instead use the pathlen given to us by decode_tree_entry().
--- match-trees.c | 7 +++---- notes.c | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-)
match-trees.c +3 -4
@@ -199,9 +199,10 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,while (desc.size) {const char *name;unsigned short mode; +int len =tree_entry_len (&desc.entry);tree_entry_extract (&desc, &name, &mode); -if (strlen (name) == toplen && +if (len == toplen && !memcmp (name, prefix, toplen)) {if (!S_ISDIR (mode)) die("entry %s in tree %s is not a tree", name,
@@ -216,9 +217,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,* - to discard the "const"; this is OK because we * know it points into our non-const "buf" */ - rewrite_here = (unsigned char *)(desc.entry.path + -strlen (desc.entry.path) + -1 ); + rewrite_here = (unsigned char *)(name + len +1 );break ; }update_tree_entry (&desc);
notes.c +2 -2
@@ -413,7 +413,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,while (tree_entry (&desc, &entry)) {unsigned char type;struct leaf_node *l; -size_t path_len =strlen (entry.path); +int path_len = entry.pathlen;if (path_len ==2 * (hashsz - prefix_len)) {/* This is potentially the remainder of the SHA-1 */
@@ -483,7 +483,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,strbuf_addch (&non_note_path, *q++);strbuf_addch (&non_note_path,'/' ); } -strbuf_addstr (&non_note_path, entry.path); +strbuf_add (&non_note_path, entry.path, path_len);add_non_note (t,strbuf_detach (&non_note_path,NULL ), entry.mode, entry.oid.hash); }
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 10/18 tree-walk.h users: use temporary variable(s) for "mode"
In reply to Ævar Arnfjörð BjarmasonIn preparation for an eventual rename of the "mode" field, add temporary variable(s) in those places where it's used more than once.
This will make those later commits easier to read, since we're only going to need to modify the line on which the assignment happens.
--- builtin/merge-tree.c | 12 +++++++++--- match-trees.c | 13 +++++++------ merge-ort.c | 5 +++-- notes.c | 3 ++- tree-diff.c | 13 ++++++++----- unpack-trees.c | 3 ++- 6 files changed, 31 insertions(+), 18 deletions(-)
builtin/merge-tree.c +9 -3
@@ -190,14 +190,17 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s {struct merge_list *orig, *final;const char *path; +unsigned int orig_mode, final_mode;/* If it's already ours, don't bother showing it */ if (!ours)return ; path =traverse_path (info, result); - orig =create_entry (2 , ours->mode, &ours->oid, path); - final =create_entry (0 , result->mode, &result->oid, path); + orig_mode = ours->mode; + orig =create_entry (2 , orig_mode, &ours->oid, path); + final_mode = result->mode; + final =create_entry (0 , final_mode, &result->oid, path); final->link = orig;
@@ -241,6 +244,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info {const char *path;struct merge_list *link; +unsigned int link_mode;if (!n->mode)return entry;
@@ -248,7 +252,9 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info path = entry->path; else path =traverse_path (info, n); - link =create_entry (stage, n->mode, &n->oid, path); + link_mode = n->mode; + link =create_entry (stage, link_mode, &n->oid, path); + link->link = entry;return link; }
match-trees.c +7 -6
@@ -86,6 +86,8 @@ static int score_trees(const struct object_id *hash1, const struct object_id *hafor (;;) {int cmp; +unsigned int one_mode = one.entry.mode; +unsigned int two_mode = two.entry.mode;if (one.size && two.size) cmp =base_name_entries_compare (&one.entry, &two.entry);
@@ -100,22 +102,21 @@ static int score_trees(const struct object_id *hash1, const struct object_id *haif (cmp <0 ) {/* path1 does not appear in two */ - score +=score_missing (one.entry.mode); + score +=score_missing (one_mode);update_tree_entry (&one); }else if (cmp >0 ) {/* path2 does not appear in one */ - score +=score_missing (two.entry.mode); + score +=score_missing (two_mode);update_tree_entry (&two); }else { +/* path appears in both */ if (!oideq (&one.entry.oid, &two.entry.oid)) {/* they are different */ - score +=score_differs (one.entry.mode, - two.entry.mode); + score +=score_differs (one_mode, two_mode); }else {/* same subtree or blob */ - score +=score_matches (one.entry.mode, - two.entry.mode); + score +=score_matches (one_mode, two_mode); }update_tree_entry (&one);update_tree_entry (&two);
merge-ort.c +3 -2
@@ -538,11 +538,12 @@ static void add_pair(struct merge_options *opt,struct diff_filespec *one, *two;struct rename_info *renames = &opt->priv->renames;int names_idx = is_add ? side :0 ; +const struct object_id *oid = &names[names_idx].oid; +unsigned int mode = names[names_idx].mode; one =alloc_filespec (pathname); two =alloc_filespec (pathname); -fill_filespec (is_add ? two : one, - &names[names_idx].oid,1 , names[names_idx].mode); +fill_filespec (is_add ? two : one, oid,1 , mode);diff_queue (&renames->pairs[side], one, two); }
notes.c +2 -1
@@ -478,6 +478,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,struct strbuf non_note_path =STRBUF_INIT ;const char *q =oid_to_hex (&subtree->key_oid);size_t i; +unsigned int mode = entry.mode;for (i =0 ; i < prefix_len; i++) {strbuf_addch (&non_note_path, *q++);strbuf_addch (&non_note_path, *q++);
@@ -485,7 +486,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, }strbuf_add (&non_note_path, entry.path, path_len);add_non_note (t,strbuf_detach (&non_note_path,NULL ), - entry.mode, entry.oid.hash); + mode, entry.oid.hash); } }free (buf);
tree-diff.c +8 -5
@@ -466,17 +466,19 @@ static struct combine_diff_path *ll_diff_tree_paths( tp[0 ].entry.mode &= ~S_IFXMIN_NEQ ;for (i =1 ; i < nparent; ++i) { +unsigned int mode = tp[i].entry.mode; cmp =tree_entry_pathcmp (&tp[i], &tp[imin]);if (cmp <0 ) { imin = i; - tp[i].entry.mode &= ~S_IFXMIN_NEQ ; + mode &= ~S_IFXMIN_NEQ ; }else if (cmp ==0 ) { - tp[i].entry.mode &= ~S_IFXMIN_NEQ ; + mode &= ~S_IFXMIN_NEQ ; }else { - tp[i].entry.mode |=S_IFXMIN_NEQ ; + mode |=S_IFXMIN_NEQ ; } + tp[i].entry.mode = mode; }/* fixup markings for entries before imin */
@@ -493,13 +495,14 @@ static struct combine_diff_path *ll_diff_tree_paths(/* are either pi > p[imin] or diff(t,pi) != ø ? */ if (!opt->flags.find_copies_harder) {for (i =0 ; i < nparent; ++i) { +unsigned int mode = tp[i].entry.mode;/* p[i] > p[imin] */ -if (tp[i].entry.mode &S_IFXMIN_NEQ ) +if (mode &S_IFXMIN_NEQ )continue ;/* diff(t,pi) != ø */ if (!oideq (&t.entry.oid, &tp[i].entry.oid) || - (t.entry.mode != tp[i].entry.mode)) + (t.entry.mode != mode))continue ; goto skip_emit_t_tp;
unpack-trees.c +2 -1
@@ -1023,8 +1023,9 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, is_transient ?make_empty_transient_cache_entry (len) :make_empty_cache_entry (istate, len); +unsigned int mode = n->mode; - ce->ce_mode =create_ce_mode (n->mode); + ce->ce_mode =create_ce_mode (mode); ce->ce_flags =create_ce_flags (stage); ce->ce_namelen = len;oidcpy (&ce->oid, &n->oid);
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 11/18 match-trees: use "tmp" for mode in shift_tree_by()
In reply to Ævar Arnfjörð BjarmasonRefactor code added in 85e51b783c3 (Make "subtree" part more orthogonal to the rest of merge-recursive., 2008-06-30) to make it obvious that we don't care about the "mode" here outside of the if statement it appears in.
That's opposed to the sub1 & sub2 variables, where we use the two object ids later in this function.
--- match-trees.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
match-trees.c +5 -5
@@ -317,17 +317,17 @@ void shift_tree_by(struct repository *r, const char *shift_prefix) {struct object_id sub1, sub2; -unsigned short mode1, mode2; +unsigned short tmp;unsigned candidate =0 ;/* Can hash2 be a tree at shift_prefix in tree hash1? */ -if (!get_tree_entry (r, hash1, shift_prefix, &sub1, &mode1) && -S_ISDIR (mode1)) +if (!get_tree_entry (r, hash1, shift_prefix, &sub1, &tmp) && +S_ISDIR (tmp)) candidate |=1 ;/* Can hash1 be a tree at shift_prefix in tree hash2? */ -if (!get_tree_entry (r, hash2, shift_prefix, &sub2, &mode2) && -S_ISDIR (mode2)) +if (!get_tree_entry (r, hash2, shift_prefix, &sub2, &tmp) && +S_ISDIR (tmp)) candidate |=2 ;if (candidate ==3 ) {
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 12/18 tree.h: format argument lists of read_tree() users
In reply to Ævar Arnfjörð BjarmasonRe-indent and format the argument list of read_tree() callbacks, and the relevant functions they call.
This is a whitespace-only change to make changes in a later series easier to read. In that series I'll be adding a new argument on the "mode" line, so leave space on it for a new argument.
--- archive.c | 13 ++++++++----- builtin/checkout.c | 4 +++- builtin/log.c | 5 +++-- builtin/ls-tree.c | 4 +++- merge-recursive.c | 3 ++- tree.h | 5 ++++- 6 files changed, 23 insertions(+), 11 deletions(-)
archive.c +8 -5
@@ -134,8 +134,9 @@ static int check_attr_export_subst(const struct attr_check *check) }static int write_archive_entry (const struct object_id *oid,const char *base, -int baselen,const char *filename,unsigned mode, -void *context) +int baselen,const char *filename, +unsigned mode, +void *context) {static struct strbuf path =STRBUF_INIT ;struct archiver_context *c = context;
@@ -225,8 +226,9 @@ static int write_directory(struct archiver_context *c) }static int queue_or_write_archive_entry (const struct object_id *oid, -struct strbuf *base,const char *filename, -unsigned mode,void *context) +struct strbuf *base,const char *filename, +unsigned mode, +void *context) {struct archiver_context *c = context;
@@ -372,7 +374,8 @@ struct path_exists_context { };static int reject_entry (const struct object_id *oid,struct strbuf *base, -const char *filename,unsigned mode, +const char *filename, +unsigned mode,void *context) {int ret =-1 ;
builtin/checkout.c +3 -1
@@ -114,7 +114,9 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm }static int update_some (const struct object_id *oid,struct strbuf *base, -const char *pathname,unsigned mode,void *context) +const char *pathname, +unsigned mode, +void *context) {int len;struct cache_entry *ce;
builtin/log.c +3 -2
@@ -598,8 +598,9 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev) }static int show_tree_object (const struct object_id *oid, -struct strbuf *base, -const char *pathname,unsigned mode,void *context) +struct strbuf *base,const char *pathname, +unsigned mode, +void *context) {FILE *file = context;fprintf (file,"%s%s\n" , pathname,S_ISDIR (mode) ?"/" :"" );
builtin/ls-tree.c +3 -1
@@ -62,7 +62,9 @@ static int show_recursive(const char *base, int baselen, const char *pathname) }static int show_tree (const struct object_id *oid,struct strbuf *base, -const char *pathname,unsigned mode,void *context) +const char *pathname, +unsigned mode, +void *context) {int retval =0 ;int baselen;
merge-recursive.c +2 -1
@@ -453,7 +453,8 @@ static void unpack_trees_finish(struct merge_options *opt)static int save_files_dirs (const struct object_id *oid,struct strbuf *base,const char *path, -unsigned int mode,void *context) +unsigned int mode, +void *context) {struct path_hashmap_entry *entry;int baselen = base->len;
tree.h +4 -1
@@ -31,7 +31,10 @@ struct tree *parse_tree_indirect(const struct object_id *oid);int cmp_cache_name_compare (const void *a_,const void *b_);#define READ_TREE_RECURSIVE 1 -typedef int (*read_tree_fn_t )(const struct object_id *,struct strbuf *,const char *,unsigned int ,void *); +typedef int (*read_tree_fn_t )(const struct object_id *,struct strbuf *, +const char *, +unsigned int , +void *); int read_tree_at(struct repository *r, struct tree *tree, struct strbuf *base,
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 13/18 tree-walk.h API: formatting changes for subsequent commit
In reply to Ævar Arnfjörð BjarmasonDo formatting (mainly whitespace) changes of code around the get_tree_entry() function to make a subsequent change where we'll add a sister function easier to read.
--- tree-walk.c | 9 ++++++--- tree-walk.h | 12 ++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-)
tree-walk.c +6 -3
@@ -589,7 +589,8 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t,oidcpy (result, &oid);return 0 ; } -return get_tree_entry (r, &oid, name + entrylen, result, mode); +return get_tree_entry (r, &oid, name + entrylen, result, + mode); }return -1 ; }
@@ -620,7 +621,8 @@ int get_tree_entry(struct repository *r, }else {struct tree_desc t;init_tree_desc (&t, tree, size); - retval =find_tree_entry (r, &t, name, oid, mode); + retval =find_tree_entry (r, &t, name, oid, + mode); }free (tree);return retval;
@@ -746,7 +748,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,/* Look up the first (or only) path component in the tree. */ find_result =find_tree_entry (r, &t, namebuf.buf, - ¤t_tree_oid, mode); + ¤t_tree_oid, + mode);if (find_result) { goto done; }
tree-walk.h +8 -4
@@ -167,10 +167,14 @@ struct traverse_info {/** * Find an entry in a tree given a pathname and the sha1 of a tree to -* search. Returns 0 if the entry is found and -1 otherwise. The third -* and fourth parameters are set to the entry's sha1 and mode respectively. -*/ -int get_tree_entry (struct repository *,const struct object_id *,const char *,struct object_id *,unsigned short *); +* search. Returns 0 if the entry is found and -1 otherwise. +* +* The third and fourth parameters are set to the entry's sha1 and +* mode respectively. +*/ +int get_tree_entry (struct repository *,const struct object_id *,const char *, +struct object_id *, +unsigned short *);/** * Generate the full pathname of a tree entry based from the root of the
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 14/18 tree-walk.h API doc: improve documentation of get_tree_entry()
In reply to Ævar Arnfjörð BjarmasonChange a mention of sha1 to OID and change the comment to a listing of functions discussed below, right now there's only one function, but subsequent commits will add more.
--- tree-walk.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tree-walk.h +5 -3
@@ -166,11 +166,13 @@ struct traverse_info { };/** -* Find an entry in a tree given a pathname and the sha1 of a tree to +* Find an entry in a tree given a pathname and the OID of a tree to * search. Returns 0 if the entry is found and -1 otherwise. * -* The third and fourth parameters are set to the entry's sha1 and -* mode respectively. +* You always need a pointer to an appropriate variable to fill in +* (NULL won't do!). That variable is: +* +* get_tree_entry(): unsigned short mode */ int get_tree_entry(struct repository *, const struct object_id *, const char *, struct object_id *,
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 15/18 tree-walk.h API: rename get_tree_entry() to get_tree_entry_mode()
In reply to Ævar Arnfjörð BjarmasonRename the get_tree_entry() function to get_tree_entry_mode(). This change is only a search-replacement of the name and indentation of the argument lists.
Subsequent commits will add another get_tree_entry_*() function. Those changes will be much easier to read if we do this rename first.
--- archive.c | 8 ++++---- blame.c | 5 ++--- builtin/rm.c | 2 +- builtin/update-index.c | 2 +- line-log.c | 2 +- match-trees.c | 6 +++--- merge-recursive.c | 18 +++++++++--------- notes.c | 2 +- object-name.c | 6 +++--- tree-walk.c | 14 +++++++------- tree-walk.h | 8 ++++---- 11 files changed, 36 insertions(+), 37 deletions(-)
archive.c +4 -4
@@ -475,10 +475,10 @@ static void parse_treeish_arg(const char **argv,unsigned short mode;int err; - err =get_tree_entry (ar_args->repo, - &tree->object.oid, - prefix, &tree_oid, - &mode); + err =get_tree_entry_mode (ar_args->repo, + &tree->object.oid, + prefix, &tree_oid, + &mode);if (err || !S_ISDIR (mode))die (_ ("current working directory is untracked" ));
blame.c +2 -3
@@ -102,8 +102,7 @@ static void verify_working_tree_path(struct repository *r,const struct object_id *commit_oid = &parents->item->object.oid;struct object_id blob_oid;unsigned short mode; - -if (!get_tree_entry (r, commit_oid, path, &blob_oid, &mode)) +if (!get_tree_entry_mode (r, commit_oid, path, &blob_oid, &mode))return ; }
@@ -1237,7 +1236,7 @@ static int fill_blob_sha1_and_mode(struct repository *r, {if (!is_null_oid (&origin->blob_oid))return 0 ; -if (get_tree_entry (r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode)) +if (get_tree_entry_mode (r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode)) goto error_out;if (oid_object_info (r, &origin->blob_oid,NULL ) !=OBJ_BLOB ) goto error_out;
builtin/rm.c +1 -1
@@ -179,7 +179,7 @@ static int check_local_mod(struct object_id *head, int index_only)* way as changed from the HEAD. */ if (no_head - ||get_tree_entry (the_repository, head, name, &oid, &mode) + ||get_tree_entry_mode (the_repository, head, name, &oid, &mode) || ce->ce_mode !=create_ce_mode (mode) || !oideq (&ce->oid, &oid)) staged_changes =1 ;
builtin/update-index.c +1 -1
@@ -603,7 +603,7 @@ static struct cache_entry *read_one_ent(const char *which,struct object_id oid;struct cache_entry *ce; -if (get_tree_entry (the_repository, ent, path, &oid, &mode)) { +if (get_tree_entry_mode (the_repository, ent, path, &oid, &mode)) {if (which)error ("%s: not in %s branch." , path, which);return NULL ;
line-log.c +1 -1
@@ -503,7 +503,7 @@ static void fill_blob_sha1(struct repository *r, struct commit *commit,unsigned short mode;struct object_id oid; -if (get_tree_entry (r, &commit->object.oid, spec->path, &oid, &mode)) +if (get_tree_entry_mode (r, &commit->object.oid, spec->path, &oid, &mode))die ("There is no path %s in the commit" , spec->path);fill_filespec (spec, &oid,1 , mode);
match-trees.c +3 -3
@@ -293,7 +293,7 @@ void shift_tree(struct repository *r,if (!*del_prefix)return ; -if (get_tree_entry (r, hash2, del_prefix, shifted, &mode)) +if (get_tree_entry_mode (r, hash2, del_prefix, shifted, &mode))die ("cannot find path %s in tree %s" , del_prefix,oid_to_hex (hash2));return ;
@@ -321,12 +321,12 @@ void shift_tree_by(struct repository *r,unsigned candidate =0 ;/* Can hash2 be a tree at shift_prefix in tree hash1? */ -if (!get_tree_entry (r, hash1, shift_prefix, &sub1, &tmp) && +if (!get_tree_entry_mode (r, hash1, shift_prefix, &sub1, &tmp) &&S_ISDIR (tmp)) candidate |=1 ;/* Can hash1 be a tree at shift_prefix in tree hash2? */ -if (!get_tree_entry (r, hash2, shift_prefix, &sub2, &tmp) && +if (!get_tree_entry_mode (r, hash2, shift_prefix, &sub2, &tmp) &&S_ISDIR (tmp)) candidate |=2 ;
merge-recursive.c +9 -9
@@ -485,7 +485,7 @@ static int get_tree_entry_if_blob(struct repository *r, {int ret; - ret =get_tree_entry (r, tree, path, &dfs->oid, &dfs->mode); + ret =get_tree_entry_mode (r, tree, path, &dfs->oid, &dfs->mode);if (S_ISDIR (dfs->mode)) {oidcpy (&dfs->oid, &null_oid); dfs->mode =0 ;
@@ -1884,9 +1884,9 @@ static int tree_has_path(struct repository *r, struct tree *tree,struct object_id hashy;unsigned short mode_o; -return !get_tree_entry (r, - &tree->object.oid, path, - &hashy, &mode_o); +return !get_tree_entry_mode (r, + &tree->object.oid, path, + &hashy, &mode_o); }/*
@@ -2538,11 +2538,11 @@ static void apply_directory_rename_modifications(struct merge_options *opt,* the various handle_rename_*() functions update the index * explicitly rather than relying on unpack_trees() to have done it. */ -get_tree_entry (opt->repo, - &tree->object.oid, - pair->two->path, - &re->dst_entry->stages[stage].oid, - &re->dst_entry->stages[stage].mode); +get_tree_entry_mode (opt->repo, + &tree->object.oid, + pair->two->path, + &re->dst_entry->stages[stage].oid, + &re->dst_entry->stages[stage].mode);/* * Record the original change status (or 'type' of change). If it
notes.c +1 -1
@@ -1021,7 +1021,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,return ;if (flags &NOTES_INIT_WRITABLE &&read_ref (notes_ref, &object_oid))die ("Cannot use notes ref %s" , notes_ref); -if (get_tree_entry (the_repository, &object_oid,"" , &oid, &mode)) +if (get_tree_entry_mode (the_repository, &object_oid,"" , &oid, &mode))die ("Failed to read notes tree referenced by %s (%s)" , notes_ref,oid_to_hex (&object_oid));
object-name.c +3 -3
@@ -1704,7 +1704,7 @@ static void diagnose_invalid_oid_path(struct repository *r,if (is_missing_file_error (errno)) {char *fullname =xstrfmt ("%s%s" , prefix, filename); -if (!get_tree_entry (r, tree_oid, fullname, &oid, &mode)) { +if (!get_tree_entry_mode (r, tree_oid, fullname, &oid, &mode)) { die(_("path '%s' exists, but not '%s'\n" "hint: Did you mean '%.*s:%s' aka '%.*s:./%s'?"), fullname,
@@ -1903,8 +1903,8 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, filename, oid, &oc->symlink_path, &oc->mode); }else { - ret =get_tree_entry (repo, &tree_oid, filename, oid, - &oc->mode); + ret =get_tree_entry_mode (repo, &tree_oid, filename, oid, + &oc->mode);if (ret && only_to_die) { diagnose_invalid_oid_path(repo, prefix, filename,
tree-walk.c +7 -7
@@ -589,17 +589,17 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t,oidcpy (result, &oid);return 0 ; } -return get_tree_entry (r, &oid, name + entrylen, result, - mode); +return get_tree_entry_mode (r, &oid, name + entrylen, result, + mode); }return -1 ; } -int get_tree_entry (struct repository *r, -const struct object_id *tree_oid, -const char *name, -struct object_id *oid, -unsigned short *mode) +int get_tree_entry_mode (struct repository *r, +const struct object_id *tree_oid, +const char *name, +struct object_id *oid, +unsigned short *mode) {int retval;void *tree;
tree-walk.h +4 -4
@@ -172,11 +172,11 @@ struct traverse_info {* You always need a pointer to an appropriate variable to fill in * (NULL won't do!). That variable is: * -* get_tree_entry(): unsigned short mode +* get_tree_entry_mode(): unsigned short mode */ -int get_tree_entry (struct repository *,const struct object_id *,const char *, -struct object_id *, -unsigned short *); +int get_tree_entry_mode (struct repository *,const struct object_id *,const char *, +struct object_id *, +unsigned short *);/** * Generate the full pathname of a tree entry based from the root of the
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 16/18 tree-walk.h API: add a get_tree_entry_path() function
In reply to Ævar Arnfjörð BjarmasonAdd a get_tree_entry_path() variant in addition to get_tree_entry_path_mode(). This is for those callers that don't need the "mode" filled for them.
There are callers here which don't need the "struct object_id" filled either, but let's leave that for now. I'm focusing downstream code that depends on "mode" (or "enum object_type").
The code being modified here was introduced in:
- shift_tree(): 68faf68938e (A new merge stragety[sic] 'subtree'.,
2007-02-15) for the shift_tree()
- tree_has_path(): 96e7ffbdc31 (merge-recursive: check for directory level conflicts, 2018-04-19)
- init_notes(): fd53c9eb445 (Speed up git notes lookup, 2009-10-09)
- diagnose_invalid_oid_path(): 009fee4774d (Detailed diagnosis when parsing an object name fails., 2009-12-07)
--- match-trees.c | 4 +--- merge-recursive.c | 6 ++---- notes.c | 3 +-- object-name.c | 3 +-- tree-walk.c | 9 +++++++++ tree-walk.h | 3 +++ 6 files changed, 17 insertions(+), 11 deletions(-)
match-trees.c +1 -3
@@ -288,12 +288,10 @@ void shift_tree(struct repository *r,if (add_score < del_score) {/* We need to pick a subtree of two */ -unsigned short mode; -if (!*del_prefix)return ; -if (get_tree_entry_mode (r, hash2, del_prefix, shifted, &mode)) +if (get_tree_entry_path (r, hash2, del_prefix, shifted))die ("cannot find path %s in tree %s" , del_prefix,oid_to_hex (hash2));return ;
merge-recursive.c +2 -4
@@ -1882,11 +1882,9 @@ static int tree_has_path(struct repository *r, struct tree *tree, const char *path) {struct object_id hashy; -unsigned short mode_o; - -return !get_tree_entry_mode (r, +return !get_tree_entry_path (r, &tree->object.oid, path, - &hashy, &mode_o); + &hashy); }/*
notes.c +1 -2
@@ -994,7 +994,6 @@ void init_notes(struct notes_tree *t, const char *notes_ref, combine_notes_fn combine_notes, int flags) {struct object_id oid, object_oid; -unsigned short mode;struct leaf_node root_tree;if (!t)
@@ -1021,7 +1020,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,return ;if (flags &NOTES_INIT_WRITABLE &&read_ref (notes_ref, &object_oid))die ("Cannot use notes ref %s" , notes_ref); -if (get_tree_entry_mode (the_repository, &object_oid,"" , &oid, &mode)) +if (get_tree_entry_path (the_repository, &object_oid,"" , &oid))die ("Failed to read notes tree referenced by %s (%s)" , notes_ref,oid_to_hex (&object_oid));
object-name.c +1 -2
@@ -1693,7 +1693,6 @@ static void diagnose_invalid_oid_path(struct repository *r, int object_name_len) {struct object_id oid; -unsigned short mode;if (!prefix) prefix ="" ;
@@ -1704,7 +1703,7 @@ static void diagnose_invalid_oid_path(struct repository *r,if (is_missing_file_error (errno)) {char *fullname =xstrfmt ("%s%s" , prefix, filename); -if (!get_tree_entry_mode (r, tree_oid, fullname, &oid, &mode)) { +if (!get_tree_entry_path (r, tree_oid, fullname, &oid)) { die(_("path '%s' exists, but not '%s'\n" "hint: Did you mean '%.*s:%s' aka '%.*s:./%s'?"), fullname,
tree-walk.c +9 -0
@@ -628,6 +628,15 @@ int get_tree_entry_mode(struct repository *r,return retval; } +int get_tree_entry_path (struct repository *r, +const struct object_id *tree_oid, +const char *name, +struct object_id *oid) +{ +unsigned short mode; +return get_tree_entry_mode (r, tree_oid, name, oid, &mode); +} +/* * This is Linux's built-in max for the number of symlinks to follow. * That limit, of course, does not affect git, but it's a reasonable
tree-walk.h +3 -0
@@ -172,8 +172,11 @@ struct traverse_info {* You always need a pointer to an appropriate variable to fill in * (NULL won't do!). That variable is: * +* get_tree_entry_path(): <no extra argument, just get the common 'path'> * get_tree_entry_mode(): unsigned short mode */ +int get_tree_entry_path (struct repository *,const struct object_id *,const char *, +struct object_id *);int get_tree_entry_mode (struct repository *,const struct object_id *,const char *,struct object_id *,unsigned short *);
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 17/18 tree-walk.h API: document and format tree_entry_extract()
In reply to Ævar Arnfjörð BjarmasonDocument and format the argument list of the tree_entry_extract() function in preparation for eventually adding a sister function.
--- tree-walk.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
tree-walk.h +10 -4
@@ -38,11 +38,17 @@ struct tree_desc {/** * Decode the entry currently being visited (the one pointed to by -* `tree_desc's` `entry` member) and return the sha1 of the entry. The -* `pathp` and `modep` arguments are set to the entry's pathname and mode -* respectively. +* `tree_desc's` `entry` member) and return the OID of the entry. +* +* There are variants of this function depending on what fields in the +* "struct name_entry" you'd like. You always need a pointer to an +* appropriate variable to fill in (NULL won't do!): +* +* tree_entry_extract(): const char *path, unsigned int mode */ -static inline const struct object_id *tree_entry_extract (struct tree_desc *desc,const char **pathp,unsigned short *modep) +static inline const struct object_id *tree_entry_extract (struct tree_desc *desc, +const char **pathp, +unsigned short *modep) { *pathp = desc->entry.path; *modep = desc->entry.mode;
Signature · 1 line
2.31.1.474.g72d45d12706
PATCH v5 18/18 tree-entry.h API: rename tree_entry_extract() to tree_entry_extract_mode()
In reply to Ævar Arnfjörð BjarmasonAs with the recent split of the get_tree_entry() function, rename the tree_entry_extract() function to *_mode() in preparation for adding other variants of it.
--- fsck.c | 2 +- match-trees.c | 4 ++-- tree-diff.c | 4 ++-- tree-walk.c | 2 +- tree-walk.h | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-)
fsck.c +1 -1
@@ -673,7 +673,7 @@ static int fsck_tree(const struct object_id *oid,const char *name, *backslash;const struct object_id *oid; - oid =tree_entry_extract (&desc, &name, &mode); + oid =tree_entry_extract_mode (&desc, &name, &mode); has_null_sha1 |=is_null_oid (oid); has_full_path |= !!strchr (name,'/' );
match-trees.c +2 -2
@@ -146,7 +146,7 @@ static void match_trees(const struct object_id *hash1,unsigned short mode;int score; - elem =tree_entry_extract (&one, &path, &mode); + elem =tree_entry_extract_mode (&one, &path, &mode);if (!S_ISDIR (mode)) goto next; score =score_trees (elem, hash2);
@@ -202,7 +202,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,unsigned short mode;int len =tree_entry_len (&desc.entry); -tree_entry_extract (&desc, &name, &mode); +tree_entry_extract_mode (&desc, &name, &mode);if (len == toplen && !memcmp (name, prefix, toplen)) {if (!S_ISDIR (mode))
tree-diff.c +2 -2
@@ -196,7 +196,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,if (t) {/* path present in resulting tree */ - oid =tree_entry_extract (t, &path, &mode); + oid =tree_entry_extract_mode (t, &path, &mode); pathlen =tree_entry_len (&t->entry); isdir =S_ISDIR (mode); }else {
@@ -207,7 +207,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,* 1) all modes for tp[i]=tp[imin] should be the same wrt * S_ISDIR, thanks to base_name_compare(). */ -tree_entry_extract (&tp[imin], &path, &mode); +tree_entry_extract_mode (&tp[imin], &path, &mode); pathlen =tree_entry_len (&tp[imin].entry); isdir =S_ISDIR (mode);
tree-walk.c +1 -1
@@ -567,7 +567,7 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t,struct object_id oid;int entrylen, cmp; -oidcpy (&oid,tree_entry_extract (t, &entry, mode)); +oidcpy (&oid,tree_entry_extract_mode (t, &entry, mode)); entrylen =tree_entry_len (&t->entry);update_tree_entry (t);if (entrylen > namelen)
tree-walk.h +4 -4
@@ -44,11 +44,11 @@ struct tree_desc {* "struct name_entry" you'd like. You always need a pointer to an * appropriate variable to fill in (NULL won't do!): * -* tree_entry_extract(): const char *path, unsigned int mode +* tree_entry_extract_mode(): const char *path, unsigned int mode */ -static inline const struct object_id *tree_entry_extract (struct tree_desc *desc, -const char **pathp, -unsigned short *modep) +static inline const struct object_id *tree_entry_extract_mode (struct tree_desc *desc, +const char **pathp, +unsigned short *modep) { *pathp = desc->entry.path; *modep = desc->entry.mode;
Signature · 1 line
2.31.1.474.g72d45d12706
Re: [PATCH v5 01/18] cache.h: add a comment to object_type()
In reply to Ævar Arnfjörð BjarmasonQuoted 8 lines · Ævar Arnfjörð Bjarmason
Add a comment to the
object_type()function to explain what it returns, and what the "mode" is in the "else" case.The
object_type()function dates back to4d1012c3709(Fix rev-list when showing objects involving submodules, 2007-11-11). It's not immediately obvious to someone looking at its history and how it's come to be used.
Quoted 4 lines
Despite what Linus noted in
4d1012c3709(Fix rev-list when showing objects involving submodules, 2007-11-11) about wanting to move away from users ofobject_type()relying onS_ISLNK(mode)being true here we do currently rely on that.
You are misreading Linus's comment here.
The comment is not about "S_ISLNK()" specifically. It is about assuming that any "S_ISx()" macros that are designed to work on stat.st_mode would work the same way for our "mode bits in tree" (i.e. 'internal git state' in the commit message refers to this fact). Platforms do not have to have 100xxx to be regular files, but we did rely on that bit assignment.
And then we invented S_ISGITLINK() that exists on nobody's stat.st_mode and have been assuming that would not collide with any real S_IFMT bit assignment.
All of that has been patched with NEEDS_MODE_TRANSLATION band-aid quite some time ago, though, with d543d9c0 (compat: convert modes to use portable file type values, 2014-12-03).
So, no, we do not quite rely on that anymore.
Quoted 3 lines
If this is changed to a condition to
only returnOBJ_BLOBonS_ISREG(mode)then t4008, t4023 and t7415 will have failing tests.
Specifically, the comment is not about symbolic links, and nobody who reads the comment correctly would imagine that limiting BLOB to S_ISREG. The comment merely was lamenting that
"If ISDIR, then tree and otherwise blob" does not hold anymore since we added submodules; "If ISDIR, then tree, and if ISGITLINK, then commit and otherwise blob" would fix it, but relying on ISDIR, ISGITLINK, etc. was a mistake that we continue to rely on even with this fix.
Quoted 2 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>---
Which means that a lot of the stuff in the proposed log message is false. I do however think that ...
Quoted 8 lines
cache.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)cache.h +0
-0
cache.h enum object_type { · line 459
Quoted 9 lines
cache.h +5
-0@@ -451,11 +451,16 @@ enum object_type { OBJ_MAX }; +/* +* object_type() returns an object of a type that'll appear in a tree, +* so no OBJ_TAG is possible. This is mostly (and dates back to) +* consumers of the tree-walk.h API's "mode" field. +*/
... this comment is correct and it is a good change to clarify what 'mode' we are talking about here.
cache.h enum object_type { · line 463
Quoted 6 lines
cache.h +1
-1static inline enum object_type object_type (unsigned int mode) {return S_ISDIR (mode) ?OBJ_TREE :S_ISGITLINK (mode) ?OBJ_COMMIT : -OBJ_BLOB ; +OBJ_BLOB ;/* S_ISREG(mode) || S_ISLNK(mode) */
For futureproofing, it might not be a bad idea to do this:
S_ISDIR(mode) ? OBJ_TREE : S_ISGITLINK(mode) ? OBJ_COMMIT : (S_ISREG(mode) || S_ISLNK(mode)) ? OBJ_BLOB : OBJ_ERROR;
to anticipate new tree mode bits so that the need for a fix similar to 4d1012c3 (Fix rev-list when showing objects involving submodules, 2007-11-11) is immediately noticed, but for now, code and comment clarification would be sufficient.
The proposed log message needs rewriting, though.
Thanks.
Re: [PATCH v5 03/18] cache.h: have base_name_compare() take "is tree?", not "mode"
In reply to Ævar Arnfjörð BjarmasonQuoted 8 lines · Ævar Arnfjörð Bjarmason
Change the
base_name_compare()API and the relateddf_name_compare()function to take a boolean argument indicating whether the entry is a tree or not, instead of having them callS_ISDIR(mode)on their own.This introduces no functional change, but makes later (not part of this series) changes to abstract away "
object_type" from "mode" more readable.
Quoted 8 lines
The API being modified here was originally added way back in
958ba6c96eb(Introduce "base_name_compare()" helper function, 2005-05-20).None of these comparison functions used to have tests, but with preceding commits some of them now do. I thought the remainder was trivial enough to review without tests, and didn't want to spend more time on them.
Puzzled. preceeding commits?
Quoted 5 lines
cache.h +0
-0
cache.h int repo_interpret_branch_name(struct repository *r, · line 1512
Quoted 9 lines
cache.h +2
-2@@ -1506,8 +1506,8 @@ int repo_interpret_branch_name(struct repository *r,int validate_headref (const char *ref); -int base_name_compare (const char *name1,int len1,int mode1,const char *name2,int len2,int mode2); -int df_name_compare (const char *name1,int len1,int mode1,const char *name2,int len2,int mode2); +int base_name_compare (const char *name1,int len1,int istree1,const char *name2,int len2,int istree2); +int df_name_compare (const char *name1,int len1,int istree1,const char *name2,int len2,int istree2);int name_compare (const char *name1,size_t len1,const char *name2,size_t len2);int cache_name_stage_compare (const char *name1,int len1,int stage1,const char *name2,int len2,int stage2);
Hopefully there won't be any new callers to these comparison functions introduced while this topic is in flight.
Without seeing real users (not yet at this 3rd step in the 18 patch series, anyway), this step feels to be a needless code churn whose only effect is to increase risks of silent semantic conflicts that compilers will not be able to help detecting. It might make it slightly less error prone to add
if (istree1 != 0 && istree1 != 1)
BUG("%o? unconverted caller?", istree1);
if (istree2 != 0 && istree2 != 1)
BUG("%o? unconverted caller?", istree2);in the callee while the topic is still in flight. Or do this in a renamed function so that such a semantic conflict will be noticed by the linker (although that would increase the busywork workload on the integrator).
I know steps like this in a long series (not limited to this series) means well, and we do encourage people to move necessary preliminary clean-up to the early part of a series, but they make me wonder "can we get to the point without 'clean-up while we are at it' steps that may turn out to be more-or-less irrelevant?"
In other words, we do encourage people to do necessary preliminary clean-up before the main part of a series, but it sometimes is unclear if an early "clean-up" patch in a long series is "necessary" or merely "while at it" that can be omitted.
But let me hold my judgment until I reach the end of the series to know enough to say if this step is or is not "necessary" preliminary clean-up.
unpack-trees.c static int traverse_trees_recursive(int n, unsigned long dirmask, · line 928
Quoted 10 lines
unpack-trees.c +1
-1@@ -925,7 +925,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,static int do_compare_entry_piecewise (const struct cache_entry *ce,const struct traverse_info *info,const char *name,size_t namelen, -unsigned mode) +unsigned istree)
Here, the "istree" boolean is expressed as unsigned, but in cache.h, it is expressed as int? Why the discrepancy?
Re: [PATCH v5 05/18] mktree tests: test that "mode" is passed when sorting
In reply to Ævar Arnfjörð BjarmasonQuoted 11 lines · Ævar Arnfjörð Bjarmason
Add a test for the mode being passed to
ent_compare(). That code dates back to83f50539a9(git-mktree: reverse of git-ls-tree., 2006-02-20) and there's never been a test for that particular edge case. Now we have one.I don't see how anything could run into this in practice. In order for that mode sorting to matter as a tiebreaker we need to have a duplicate entry in the tree, i.e. two "foo" entries, one a blob and one a tree. This asserts that if that happens we'll sort on the modes we encounter in such an invalid entry, i.e. we expect the tree entry before the blob.
It is more like "in a tree with 'foo.' and 'foo0' (both of which are blobs), a 'foo' that is a tree should appear after 'foo.' and before 'foo0', because it sorts as if it were 'foo/'. If 'foo' is a blob, it sorts the first before 'foo.' and 'foo0'".
Checking a broken tree with both 'foo' (blob) and 'foo' (tree) that does not even pass fsck is not very valuable, but the sort order of these two trees (i.e. one with foo as tree, the other with foo as blob) do need to be tested, as the unpack_trees merge machinery will need to walk such pair of trees correctly.
Thanks.
Re: [PATCH v5 06/18] diff tests: test that "mode" is passed when sorting
In reply to Ævar Arnfjörð BjarmasonQuoted 3 lines · Ævar Arnfjörð Bjarmason
Piggy-back on the recently added fsck tests for mode comparisons in mktree and assert that diff-tree also does the right thing in this implausible scenario.
The same comment applies. Just testing the order of "foo" (blob), "foo." (blob), "foo/" (tree), and "foo0" (blob) in two comparisons would be a more realistic test that has more practical value.
Re: [PATCH v5 07/18] merge-tree tests: test for the mode comparison in same_entry()
In reply to Ævar Arnfjörð BjarmasonQuoted 8 lines · Ævar Arnfjörð Bjarmason
Add a test to stress the "
a->mode==b->mode" comparison in merge-tree.c'ssame_entry().That code was initially added by Linus in
33deb63a36f(Add "merge-tree" helper program. Maybe it's retarded, maybe it's helpful., 2005-04-14), and then again in its current form in492e0759bfe(Handling large files with GIT, 2006-02-14).
Quoted 4 lines
However, nothing was testing that we handled this case correctly. Simply removing the mode comparison left all tests passing, but as seen here it's important that we don't think a path with the same content but different modes is the
same_entry().
Good thinking.
Quoted 18 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- t/t4300-merge-tree.sh | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)t/t4300-merge-tree.sh +5
-0@@ -40,6 +40,25 @@ test_expect_success 'file add A, B (same)' ' test_must_be_empty actual ' +test_expect_success 'file add A, B (different mode)' ' + git reset --hard initial && + test_commit "add-a-b-same-diff-mode-A" "ONE" "AAA" && + git reset --hard initial && + echo AAA >ONE &&
t/t4300-merge-tree.sh test_expect_success 'file add A, B (same)' ' · line 57
Quoted 10 lines
t/t4300-merge-tree.sh +10
-0+ test_chmod +x ONE && + test_tick && + git commit -m"add-a-b-same-diff-mode-B" && + git tag "add-a-b-same-diff-mode-B" HEAD && + git merge-tree initial add-a-b-same-diff-mode-A add-a-b-same-diff-mode-B >actual && + cat >expected <<EXPECTED && +added in both + our 100644 $(git rev-parse add-a-b-same-diff-mode-A:ONE) ONE + their 100755 $(git rev-parse add-a-b-same-diff-mode-B:ONE) ONE +EXPECTED
Can we HT-indent the here text with "<<-EOF", unless existing tests in the same script predate the more recent convention?
... goes and looks and realizes it is full of unindented expectation ...
Nah, let's keep it that way.
Quoted 21 lines
t/t4300-merge-tree.sh +14
-0+ test_cmp expected actual +' + test_expect_success 'file add A, B (different)' ' git reset --hard initial && test_commit "add-a-b-diff-A" "ONE" "AAA" &&@@ -61,6 +80,31 @@ EXPECTED test_cmp expected actual ' +test_expect_success 'file add A, B (different and different mode)' ' + git reset --hard initial && + test_commit "add-a-b-diff-diff-mode-A" "ONE" "AAA" && + git reset --hard initial && + echo BBB >ONE && + test_chmod +x ONE && + test_tick && + git commit -m"add-a-b-diff-diff-mode-B" && + git tag "add-a-b-diff-diff-mode-B" && + git merge-tree initial add-a-b-diff-diff-mode-A add-a-b-diff-diff-mode-B >actual && + cat >expected <<EXPECTED &&
t/t4300-merge-tree.sh EXPECTED · line 103
Quoted 10 lines
t/t4300-merge-tree.sh +10
-0+added in both + our 100644 $(git rev-parse add-a-b-diff-diff-mode-A:ONE) ONE + their 100755 $(git rev-parse add-a-b-diff-diff-mode-B:ONE) ONE +@@ -1 +1,5 @@ ++<<<<<<< .our + AAA ++======= ++BBB ++>>>>>>> .their +EXPECTED
Nice. So the mode-only conflict and mode plus contents conflict are both shown in a sensible way.
Looks good.
Thanks.
Re: [PATCH v5 08/18] blame: emit a better error on 'git blame directory'
In reply to Ævar Arnfjörð BjarmasonQuoted 11 lines · Ævar Arnfjörð Bjarmason
Change an early check for non-blobs in
verify_working_tree_path()to let any such objects pass, and instead die shortly thereafter in thefake_working_tree_commit()caller's type check.Now e.g. doing "git blame t" in git.git emits:
fatal: unsupported file type t
Instead of:
fatal: no such path 't' in HEAD
Sorry, but I fail to see why "unsupported file type t" is quite an improvement. Is this one of these irrelevant clean-up while at it whose benefit is unclear until much later, I have to wonder.
Quoted 2 lines
The main point of this test is to assert that we're not doing something uniquely bad when in a conflicted merge. See
"this test" refers to the logic "it is OK to skip the check if one of the parents does have it as a blob", introduced in 9aeaab68 (blame: allow "blame file" in the middle of a conflicted merge, 2012-09-11)?
blame.c static void verify_working_tree_path(struct repository *r, · line 108
Quoted 5 lines
blame.c +1
-2-if (!get_tree_entry (r, commit_oid, path, &blob_oid, &mode) && -oid_object_info (r, &blob_oid,NULL ) ==OBJ_BLOB ) +if (!get_tree_entry (r, commit_oid, path, &blob_oid, &mode))return ; }
At least, the original logic makes sense to me in that if an early parent has the path as a directory we do not declare it is OK but keep going until we find a blob in a later parent before deciding to short-cut. I am not sure what the updated "in this case we can bypass the real check" condition even means. Mechanically, it says "if any parent has the path as any filesystem entity, even if it were a directory, then it is OK", but why?
Thanks.
Re: [PATCH v5 09/18] notes & match-trees: use name_entry's "pathlen" member
In reply to Ævar Arnfjörð Bjarmasonmatch-trees.c static int splice_tree(const struct object_id *oid1, const char *prefix, · line 205
Quoted 8 lines · Ævar Arnfjörð Bjarmason
match-trees.c +2
-1while (desc.size) {const char *name;unsigned short mode; +int len =tree_entry_len (&desc.entry);tree_entry_extract (&desc, &name, &mode); - if (strlen(name) == toplen && + if (len == toplen &&
Makes sense.
match-trees.c static int splice_tree(const struct object_id *oid1, const char *prefix, · line 220
Quoted 8 lines
match-trees.c +1
-3@@ -216,9 +217,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,* - to discard the "const"; this is OK because we * know it points into our non-const "buf" */ - rewrite_here = (unsigned char *)(desc.entry.path + -strlen (desc.entry.path) + -1 ); + rewrite_here = (unsigned char *)(name + len +1 );
So does this. The original using desc.entry.path even though it called extract to learn the name does not make much sense.
notes.c static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, · line 416
Quoted 13 lines
match-trees.c +0
-0break ; }update_tree_entry (&desc);notes.c +1
-1@@ -413,7 +413,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,while (tree_entry (&desc, &entry)) {unsigned char type;struct leaf_node *l; -size_t path_len =strlen (entry.path); +int path_len = entry.pathlen;
OK.
notes.c static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, · line 486
Quoted 8 lines
notes.c +1
-1if (path_len ==2 * (hashsz - prefix_len)) {/* This is potentially the remainder of the SHA-1 */ @@ -483,7 +483,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,strbuf_addch (&non_note_path, *q++);strbuf_addch (&non_note_path,'/' ); } -strbuf_addstr (&non_note_path, entry.path); +strbuf_add (&non_note_path, entry.path, path_len);
OK.
notes.c static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, · line 489
Quoted 3 lines
notes.c +0
-0add_non_note (t,strbuf_detach (&non_note_path,NULL ), entry.mode, entry.oid.hash); }
Looking good.
Thanks.
Re: [PATCH v5 11/18] match-trees: use "tmp" for mode in shift_tree_by()
In reply to Ævar Arnfjörð BjarmasonQuoted 4 lines · Ævar Arnfjörð Bjarmason
Refactor code added in
85e51b783c3(Make "subtree" part more orthogonal to the rest of merge-recursive., 2008-06-30) to make it obvious that we don't care about the "mode" here outside of the if statement it appears in.
OK.
Quoted 36 lines
That's opposed to the sub1 & sub2 variables, where we use the two object ids later in this function.
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- match-trees.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)match-trees.c +5
-5@@ -317,17 +317,17 @@ void shift_tree_by(struct repository *r, const char *shift_prefix) {struct object_id sub1, sub2; -unsigned short mode1, mode2; +unsigned short tmp;unsigned candidate =0 ;/* Can hash2 be a tree at shift_prefix in tree hash1? */ -if (!get_tree_entry (r, hash1, shift_prefix, &sub1, &mode1) && -S_ISDIR (mode1)) +if (!get_tree_entry (r, hash1, shift_prefix, &sub1, &tmp) && +S_ISDIR (tmp)) candidate |=1 ;/* Can hash1 be a tree at shift_prefix in tree hash2? */ -if (!get_tree_entry (r, hash2, shift_prefix, &sub2, &mode2) && -S_ISDIR (mode2)) +if (!get_tree_entry (r, hash2, shift_prefix, &sub2, &tmp) && +S_ISDIR (tmp)) candidate |=2 ;if (candidate ==3 ) {
Re: [PATCH v5 14/18] tree-walk.h API doc: improve documentation of get_tree_entry()
In reply to Ævar Arnfjörð BjarmasonQuoted 17 lines · Ævar Arnfjörð Bjarmason
Change a mention of sha1 to OID and change the comment to a listing of functions discussed below, right now there's only one function, but subsequent commits will add more.
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- tree-walk.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)tree-walk.h +0
-0@@ -166,11 +166,13 @@ struct traverse_info { };/**
tree-walk.h struct traverse_info { · line 175
Quoted 10 lines
tree-walk.h +5
-3-* Find an entry in a tree given a pathname and the sha1 of a tree to +* Find an entry in a tree given a pathname and the OID of a tree to * search. Returns 0 if the entry is found and -1 otherwise. * -* The third and fourth parameters are set to the entry's sha1 and -* mode respectively. +* You always need a pointer to an appropriate variable to fill in +* (NULL won't do!). That variable is: +* +* get_tree_entry(): unsigned short mode
The last part after "That variable is:" makes no sense. Sent before completing?
The function takes a repository, tree object name, a path in that tree as input, and find the entry in the tree at the given path. Its finding is returned in the fourth and fifth parameters as
struct object_id *oid
unsigned short *mode
By the way, I think somebody forgot to update the description while inserting the "struct repository *" as the first parameter and that is where the "third and fourth" in the original comes from.
Re: [PATCH v5 16/18] tree-walk.h API: add a get_tree_entry_path() function
In reply to Ævar Arnfjörð Bjarmasonmatch-trees.c void shift_tree(struct repository *r, · line 296
Quoted 4 lines · Ævar Arnfjörð Bjarmason
match-trees.c +1
-1-if (get_tree_entry_mode (r, hash2, del_prefix, shifted, &mode)) +if (get_tree_entry_path (r, hash2, del_prefix, shifted))die ("cannot find path %s in tree %s" , del_prefix,oid_to_hex (hash2));
The observation that many "get_tree_entry()" users do not need the mode bits and the code can be simplified by taking advantage of that fact is good.
It does not automatically follow that it is a good implementation of that simplification to introduce a variant that does not take the mode pointer. The original function could have just been taught to accept NULL in the field the caller is not interested in, as in many other functions do.
Besides, get_tree_entry_mode() vs get_tree_entry_path() does not make any sense as pair of functions with contrasting names. If it were that unlike the former that returns mode, the latter returns path instead, it would have made sense, but that is not what is going on. The former returns object name and mode, the latter only returns object name without mode.
In any case, at this point in the series, it is highly dubious that an extra function is an improvement. Teaching get_tree_entry() (do not even rename it) to take NULL in *mode pointer would make a lot more sense.
Re: [PATCH v5 17/18] tree-walk.h API: document and format tree_entry_extract()
In reply to Ævar Arnfjörð BjarmasonQuoted 14 lines · Ævar Arnfjörð Bjarmason
Document and format the argument list of the
tree_entry_extract()function in preparation for eventually adding a sister function.Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- tree-walk.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)tree-walk.h +0
-0@@ -38,11 +38,17 @@ struct tree_desc {
tree-walk.h struct tree_desc { · line 45
Quoted 10 lines
tree-walk.h +5
-3/** * Decode the entry currently being visited (the one pointed to by -* `tree_desc's` `entry` member) and return the sha1 of the entry. The -* `pathp` and `modep` arguments are set to the entry's pathname and mode -* respectively. +* `tree_desc's` `entry` member) and return the OID of the entry. +* +* There are variants of this function depending on what fields in the +* "struct name_entry" you'd like. You always need a pointer to an +* appropriate variable to fill in (NULL won't do!):
There aren't. At least not yet. So if you want to build a series like this that does many little things in each step, stop this step at updating SHA-1 to OID and do nothing else, until you introduce different variant.
What is missing in the current description that is more worth describing for those who are new to the codebase is probably the fact that this is meant to be used in pairs with update_tree_entry(). You call extract, which does not change the entry at all, and when you are done, update knows (from the data kept in the entry) where the next entry is in memory and the entry is updated to point there.
Thanks.
Quoted 10 lines
tree-walk.h +5
-1+* +* tree_entry_extract(): const char *path, unsigned int mode */ -static inline const struct object_id *tree_entry_extract (struct tree_desc *desc,const char **pathp,unsigned short *modep) +static inline const struct object_id *tree_entry_extract (struct tree_desc *desc, +const char **pathp, +unsigned short *modep) { *pathp = desc->entry.path; *modep = desc->entry.mode;
Re: [PATCH v5 18/18] tree-entry.h API: rename tree_entry_extract() to tree_entry_extract_mode()
In reply to Ævar Arnfjörð BjarmasonQuoted 3 lines · Ævar Arnfjörð Bjarmason
As with the recent split of the
get_tree_entry()function, rename thetree_entry_extract()function to*_mode()in preparation for adding other variants of it.
I do not see a value in this approach over optionally accepting NULL, for the same reason why splitting get_tree_entry() does not show a value over optionally accepting NULL. At least at this point in the series.
There might be future changes that would benefit from having separate functions, but I do not see how they cannot work with an updated version of existing helper functions that optionally can take NULL as "don't care" when they can with a different function with one fewer parameter.
Re: [PATCH v5 08/18] blame: emit a better error on 'git blame directory'
In reply to Junio C HamanoQuoted 10 lines · Junio C Hamano
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Change an early check for non-blobs in
verify_working_tree_path()to let any such objects pass, and instead die shortly thereafter in thefake_working_tree_commit()caller's type check.Now e.g. doing "git blame t" in git.git emits:
fatal: unsupported file type t
Quoted 7 lines
Quoted 3 lines
Instead of:
fatal: no such path 't' in HEAD
Sorry, but I fail to see why "unsupported file type t" is quite an improvement. Is this one of these irrelevant clean-up while at it whose benefit is unclear until much later, I have to wonder.
Because "t" is directory we can stat() and which exists in the index, so it makes more sense to fall through to the stat() codepath.
I think the "unsupported file type" message is a bit odd, but it's the existing one, perhaps changing it while we're at it to something like:
fatal: cannot 'blame' a directory
Would be better, but in any case I think saying "no such path X in HEAD" when you can "git show HEAD:t" to see that there is such a path doesn't make sense.
I don't have a test for it here, but this change also makes this error better:
rm -rf contrib
git blame contrib
Before we'd say:
fatal: no such path 'contrib' in HEAD
But now we'll fall back to:
fatal: Cannot lstat 'contrib': No such file or directory
Which could also be reworded, but aside from the specific wording I think not aborting early when we see "this is not a blob" is better.
Quoted 7 lines
Quoted 2 lines
The main point of this test is to assert that we're not doing something uniquely bad when in a conflicted merge. See
"this test" refers to the logic "it is OK to skip the check if one of the parents does have it as a blob", introduced in
9aeaab68(blame: allow "blame file" in the middle of a conflicted merge, 2012-09-11)?
Yes, will clarify.
Quoted 6 lines
blame.c static void verify_working_tree_path(struct repository *r, · line 108
Quoted 5 lines
blame.c +1
-2-if (!get_tree_entry (r, commit_oid, path, &blob_oid, &mode) && -oid_object_info (r, &blob_oid,NULL ) ==OBJ_BLOB ) +if (!get_tree_entry (r, commit_oid, path, &blob_oid, &mode))return ; }
Quoted 7 lines
At least, the original logic makes sense to me in that if an early parent has the path as a directory we do not declare it is OK but keep going until we find a blob in a later parent before deciding to short-cut. I am not sure what the updated "in this case we can bypass the real check" condition even means. Mechanically, it says "if any parent has the path as any filesystem entity, even if it were a directory, then it is OK", but why?
Because we'll fall down to code that's better at doing the rest of that check.
Looking at this again, another thing this changes is the behavior of --contents, which I again think is an improvement. Let's say you:
rm Makefile &&
mkdir Makefile &&
touch Makefile/foo &&
git add Makefile &&
git commit -m"foo"I.e. turn a random file into a directory, then:
git show origin/master:Makefile | git blame --contents - Makefile
We'll now say:
fatal: no such path 'Makefile' in HEAD
With my patch we'll do what the user asked (and I think consistently with the documentation) and pretend as though the stream on stdin was the contents at the "Makefile" path.
The blame we show doesn't make much sense, it's all the lines in the file with "Not Committed Yet", but that's another matter to do with the blame algorithm in general, e.g. if you flip Makefile back & forth between a file->dir->file it won't traverse past the dir->file move.
Re: [PATCH v5 14/18] tree-walk.h API doc: improve documentation of get_tree_entry()
In reply to Junio C HamanoQuoted 18 lines · Junio C Hamano
Quoted 16 lines · Ævar Arnfjörð Bjarmason
Change a mention of sha1 to OID and change the comment to a listing of functions discussed below, right now there's only one function, but subsequent commits will add more.
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- tree-walk.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)tree-walk.h +0
-0@@ -166,11 +166,13 @@ struct traverse_info { };
Quoted 14 lines
tree-walk.h struct traverse_info { · line 175
Quoted 11 lines
tree-walk.h +5
-3/** -* Find an entry in a tree given a pathname and the sha1 of a tree to +* Find an entry in a tree given a pathname and the OID of a tree to * search. Returns 0 if the entry is found and -1 otherwise. * -* The third and fourth parameters are set to the entry's sha1 and -* mode respectively. +* You always need a pointer to an appropriate variable to fill in +* (NULL won't do!). That variable is: +* +* get_tree_entry(): unsigned short mode The last part after "That variable is:" makes no sense. Sent before completing?
It's meant to refer to the "unsigned short mode", but I'll rephrase.
Quoted 10 lines
The function takes a repository, tree object name, a path in that tree as input, and find the entry in the tree at the given path. Its finding is returned in the fourth and fifth parameters as
struct
object_id*oid
unsigned short *modeBy the way, I think somebody forgot to update the description while inserting the "struct repository *" as the first parameter and that is where the "third and fourth" in the original comes from.
Also as a fix for this...
Re: [PATCH v5 16/18] tree-walk.h API: add a get_tree_entry_path() function
In reply to Junio C HamanoQuoted 24 lines · Junio C Hamano
match-trees.c void shift_tree(struct repository *r, · line 296
Quoted 4 lines · Ævar Arnfjörð Bjarmason
match-trees.c +1
-1-if (get_tree_entry_mode (r, hash2, del_prefix, shifted, &mode)) +if (get_tree_entry_path (r, hash2, del_prefix, shifted))die ("cannot find path %s in tree %s" , del_prefix,oid_to_hex (hash2));The observation that many "
get_tree_entry()" users do not need the mode bits and the code can be simplified by taking advantage of that fact is good.It does not automatically follow that it is a good implementation of that simplification to introduce a variant that does not take the mode pointer. The original function could have just been taught to accept NULL in the field the caller is not interested in, as in many other functions do.
Besides,
get_tree_entry_mode()vsget_tree_entry_path()does not make any sense as pair of functions with contrasting names. If it were that unlike the former that returns mode, the latter returns path instead, it would have made sense, but that is not what is going on. The former returns object name and mode, the latter only returns object name without mode.
Quoted 4 lines
In any case, at this point in the series, it is highly dubious that an extra function is an improvement. Teaching
get_tree_entry()(do not even rename it) to take NULL in *mode pointer would make a lot more sense.
Thanks. Yes that makes a lot more sense.
This whole path of introducing multiple functions is an oversight of mine. I did it because in 7146e66f086 (tree-walk: finally switch over tree descriptors to contain a pre-parsed entry, 2014-02-06) we removed canon_mode() from the inline function to make it trivially inline-able.
So I assumed without testing that introducing conditionals in that function would matter to a compiler, and wanted to not introduce any performance regressions (however small) in this series.
But looking at the generated *.s code under GCC -O3 it makes no difference if you've got an "if (ptr) *ptr = xyz" there. The compiler sees that and produces the same machine code.
So I'll re-roll this to do as you suggested, thanks.
Re: [PATCH v5 08/18] blame: emit a better error on 'git blame directory'
In reply to Ævar Arnfjörð BjarmasonQuoted 14 lines · Ævar Arnfjörð Bjarmason
Quoted 12 lines · Junio C Hamano
Quoted 10 lines · Ævar Arnfjörð Bjarmason
Change an early check for non-blobs in
verify_working_tree_path()to let any such objects pass, and instead die shortly thereafter in thefake_working_tree_commit()caller's type check.Now e.g. doing "git blame t" in git.git emits:
fatal: unsupported file type t
Instead of:
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
fatal: no such path 't' in HEAD
Sorry, but I fail to see why "unsupported file type t" is quite an improvement. Is this one of these irrelevant clean-up while at it whose benefit is unclear until much later, I have to wonder.
Because "t" is directory we can
stat()and which exists in the index, so it makes more sense to fall through to thestat()codepath.
't' is not in the index, even though many things with 't/' prefix may.
But my understanding of the point of that loop is to catch cases where one side may have 't' as a directory, the other side may have it as a blob, and we have a 't' regular file during a process of resolving a conflicted merge (perhaps the tentative resolution has already been "git add"ed to the index). So "git blame t" would want to start from the "working tree state", which is made into a virtual commit, with two "virtual" parents, one is HEAD that has 't' as a directory but the other MERGE_HEAD may have 't' as a regular file, so "blame" should be able to follow the history of that regular file through the merge in progress.
If we change, like the proposed patch does, the loop to exit immediately after we notice 't' exists in HEAD (as a tree), without even looking at the second parent to notice that it is a regular file there, wouldn't that change the behaviour?
Quoted 6 lines
I think the "unsupported file type" message is a bit odd, but it's the existing one, perhaps changing it while we're at it to something like:
fatal: cannot 'blame' a directory
Would be better,...
Sure. As long as the change does not break the original use case the loop intended to support, that is fine, and the message would be a lot better than the "unsupported file type t".