diff mbox series

[RFC/PATCH,2/5] ls-files: make "mode" in show_ce() loop a variable

Message ID 20210317132814.30175-3-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series [RFC/PATCH,1/5] ls-files: defer read_index() after parse_options() etc. | expand

Commit Message

Ævar Arnfjörð Bjarmason March 17, 2021, 1:28 p.m. UTC
In a subsequent commit I'll optionally change the mode in a new sparse
mode, let's do this first to make that change smaller.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/ls-files.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Elijah Newren March 17, 2021, 6:11 p.m. UTC | #1
On Wed, Mar 17, 2021 at 6:28 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
>
> In a subsequent commit I'll optionally change the mode in a new sparse
> mode, let's do this first to make that change smaller.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/ls-files.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/ls-files.c b/builtin/ls-files.c
> index eb72d16493..4db75351f2 100644
> --- a/builtin/ls-files.c
> +++ b/builtin/ls-files.c
> @@ -242,9 +242,17 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
>                 if (!show_stage) {
>                         fputs(tag, stdout);
>                 } else {
> +                       unsigned int mode = ce->ce_mode;
> +                       if (show_sparse && S_ISSPARSEDIR(mode))
> +                               /*
> +                                * We could just do & 0177777 all the
> +                                * time, just make it clear this is
> +                                * for --stage-sparse.
> +                                */
> +                               mode &= 0177777;

I could kind of see referencing the magic constant 0177777 in a test-*
source file, but it really needs an explanation when showing up in
actual git source code.  At least reference something about how
cache.h mentions these are the mode bits, or better yet #define this
constant somewhere in cache.h with an explanation.

Also, what is --stage-sparse?

>                         printf("%s%06o %s %d\t",
>                                tag,
> -                              ce->ce_mode,
> +                              mode,
>                                find_unique_abbrev(&ce->oid, abbrev),
>                                ce_stage(ce));
>                 }
> --
> 2.31.0.260.g719c683c1d
Ævar Arnfjörð Bjarmason March 24, 2021, 12:46 a.m. UTC | #2
On Wed, Mar 17 2021, Elijah Newren wrote:

> On Wed, Mar 17, 2021 at 6:28 AM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>>
>> In a subsequent commit I'll optionally change the mode in a new sparse
>> mode, let's do this first to make that change smaller.
>>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>>  builtin/ls-files.c | 10 +++++++++-
>>  1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/builtin/ls-files.c b/builtin/ls-files.c
>> index eb72d16493..4db75351f2 100644
>> --- a/builtin/ls-files.c
>> +++ b/builtin/ls-files.c
>> @@ -242,9 +242,17 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
>>                 if (!show_stage) {
>>                         fputs(tag, stdout);
>>                 } else {
>> +                       unsigned int mode = ce->ce_mode;
>> +                       if (show_sparse && S_ISSPARSEDIR(mode))
>> +                               /*
>> +                                * We could just do & 0177777 all the
>> +                                * time, just make it clear this is
>> +                                * for --stage-sparse.
>> +                                */
>> +                               mode &= 0177777;
>
> I could kind of see referencing the magic constant 0177777 in a test-*
> source file, but it really needs an explanation when showing up in
> actual git source code.  At least reference something about how
> cache.h mentions these are the mode bits, or better yet #define this
> constant somewhere in cache.h with an explanation.
>
> Also, what is --stage-sparse?

A relic from a WIP version of this patch. I ended up just calling it
--sparse in 3/5.

>>                         printf("%s%06o %s %d\t",
>>                                tag,
>> -                              ce->ce_mode,
>> +                              mode,
>>                                find_unique_abbrev(&ce->oid, abbrev),
>>                                ce_stage(ce));
>>                 }
>> --
>> 2.31.0.260.g719c683c1d
diff mbox series

Patch

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index eb72d16493..4db75351f2 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -242,9 +242,17 @@  static void show_ce(struct repository *repo, struct dir_struct *dir,
 		if (!show_stage) {
 			fputs(tag, stdout);
 		} else {
+			unsigned int mode = ce->ce_mode;
+			if (show_sparse && S_ISSPARSEDIR(mode))
+				/*
+				 * We could just do & 0177777 all the
+				 * time, just make it clear this is
+				 * for --stage-sparse.
+				 */
+				mode &= 0177777;
 			printf("%s%06o %s %d\t",
 			       tag,
-			       ce->ce_mode,
+			       mode,
 			       find_unique_abbrev(&ce->oid, abbrev),
 			       ce_stage(ce));
 		}