diff mbox series

[03/30] cache.h: add a comment to object_type()

Message ID 20210308150650.18626-4-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series Move the read_tree() function to its only user | expand

Commit Message

Ævar Arnfjörð Bjarmason March 8, 2021, 3:06 p.m. UTC
Add a comment to the object_type() function to explain what it
returns, and whet 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.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 cache.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Elijah Newren March 9, 2021, 4:40 p.m. UTC | #1
On Mon, Mar 8, 2021 at 7:07 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>
> Add a comment to the object_type() function to explain what it
> returns, and whet the "mode" is in the "else" case.

s/whet/what/ ?


>
> 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.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  cache.h | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/cache.h b/cache.h
> index d9281496140..e513f0ee5b4 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -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. */
> --
> 2.31.0.rc0.126.g04f22c5b82
diff mbox series

Patch

diff --git a/cache.h b/cache.h
index d9281496140..e513f0ee5b4 100644
--- a/cache.h
+++ b/cache.h
@@ -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. */