threads / patch / 45585

patch, 2 parts[GSOC] Convert signed flags to unsigned

Subject: [PATCH 1/2] [GSOC] Convert signed flags to unsigned

## tl;dr

9 messages between Apr 1, 2017 and Apr 2, 2017. Diffs are folded; open one to read it.

replies: 8people: 2as markdown or json

Robert Stanca· Apr 1, 2017, 15:30 UTC · lore
 Unsigned int is a closer representation of bitflags rather than signed int that uses 1 special bit for sign.This shouldn't make much difference because rev_list_info.flags uses only 2 bits(BISECT_SHOW_ALL and REV_LIST_QUIET)
Signed-off-by: Robert Stanca <robert.stanca7@gmail.com>
---
 bisect.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to bisect.h +1 −1
diff --git a/bisect.h b/bisect.h
index acd12ef80..a979a7f11 100644
--- a/bisect.h
+++ b/bisect.h
@@ -16,7 +16,7 @@ extern struct commit_list *filter_skipped(struct commit_list *list,
 
 struct rev_list_info {
 	struct rev_info *revs;
-	int flags;
+	unsigned int flags;
 	int show_timestamp;
 	int hdr_termination;
 	const char *header_prefix;
-- 
2.12.2.575.gb14f27f91.dirty
Robert Stanca· Apr 1, 2017, 15:30 UTC · re: Robert Stanca · lore

[PATCH 2/2] [GSOC] show_bisect_vars(): Use unsigned int instead of signed int for flags

 As rev_list_info's flag is unsigned int , var flags should have proper type.Also var cnt could be unsigned as there's no negative number of commits (all-reaches)
Signed-off-by: Robert Stanca <robert.stanca7@gmail.com>
---
 builtin/rev-list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to builtin/rev-list.c +1 −1
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 0aa93d589..eb4af53ab 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -211,7 +211,7 @@ static void print_var_int(const char *var, int val)
 
 static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
 {
-	int cnt, flags = info->flags;
+	unsigned int cnt, flags = info->flags;
 	char hex[GIT_SHA1_HEXSZ + 1] = "";
 	struct commit_list *tried;
 	struct rev_info *revs = info->revs;
-- 
2.12.2.575.gb14f27f91.dirty
Junio C Hamano· Apr 1, 2017, 19:13 UTC · re: Robert Stanca · lore

Re: [PATCH 2/2] [GSOC] show_bisect_vars(): Use unsigned int instead of signed int for flags

Robert Stanca <robert.stanca7@gmail.com> writes:
>  As rev_list_info's flag is unsigned int , var flags should have proper type.Also var cnt could be unsigned as there's no negative number of commits (all-reaches)
>
> Signed-off-by: Robert Stanca <robert.stanca7@gmail.com>
> ---
OK.  I would have squashed these two commits into one, though.
Robert Stanca· Apr 1, 2017, 19:19 UTC · re: Junio C Hamano · lore

Re: [PATCH 2/2] [GSOC] show_bisect_vars(): Use unsigned int instead of signed int for flags

I am used to 1change per patch so it's easier to redo specific patches...if there are small changes(10 lines max) can i send them as 1 patch?

On Sat, Apr 1, 2017 at 10:13 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 8 quoted lines
> Robert Stanca <robert.stanca7@gmail.com> writes:
>
>>  As rev_list_info's flag is unsigned int , var flags should have proper type.Also var cnt could be unsigned as there's no negative number of commits (all-reaches)
>>
>> Signed-off-by: Robert Stanca <robert.stanca7@gmail.com>
>> ---
>
> OK.  I would have squashed these two commits into one, though.
Junio C Hamano· Apr 2, 2017, 03:30 UTC · re: Robert Stanca · lore

Re: [PATCH 2/2] [GSOC] show_bisect_vars(): Use unsigned int instead of signed int for flags

Robert Stanca <robert.stanca7@gmail.com> writes:
> I am used to 1change per patch so it's easier  to redo specific
> patches...if there are small changes(10 lines max) can i send them as
> 1 patch?

It's not number of lines. One line per patch does not make sense if you need to make corresponding changes to two places, one line each, in order to make the end result consistent. If you change a type of a structure field, and that field is assigned to a variable somewhere, you would change the type of both that field and the variable that receives its value at the same time in a single commit, as that would be the logical unit of a smallest change that still makes sense (i.e. either half of that change alone would not make sense).

Robert Stanca· Apr 2, 2017, 13:18 UTC · re: Junio C Hamano · lore

Re: [PATCH 2/2] [GSOC] show_bisect_vars(): Use unsigned int instead of signed int for flags

One more quesestion regarding flags used in structures : for example: update_callback_data has a flags field (type int) , in function void update_callback() the field flags of that structure is used as param for add_file_to_index(..., data->flags) and this function is define as: int add_file_to_index(..., int flags) in read-cache.c The question is : If the flags field of the structure is used in function calls should i update flags that deep?(there are other cases where the field is used in nested calls )

On Sun, Apr 2, 2017 at 6:30 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 18 quoted lines
> Robert Stanca <robert.stanca7@gmail.com> writes:
>
>> I am used to 1change per patch so it's easier  to redo specific
>> patches...if there are small changes(10 lines max) can i send them as
>> 1 patch?
>
> It's not number of lines.  One line per patch does not make sense if
> you need to make corresponding changes to two places, one line each,
> in order to make the end result consistent.  If you change a type of
> a structure field, and that field is assigned to a variable
> somewhere, you would change the type of both that field and the
> variable that receives its value at the same time in a single
> commit, as that would be the logical unit of a smallest change that
> still makes sense (i.e. either half of that change alone would not
> make sense).
>
>
>
Junio C Hamano· Apr 2, 2017, 17:14 UTC · re: Robert Stanca · lore

Re: [PATCH 2/2] [GSOC] show_bisect_vars(): Use unsigned int instead of signed int for flags

Robert Stanca <robert.stanca7@gmail.com> writes:
> The question is : If the flags field of the structure is used in
> function calls should i update flags that deep?(there are other
> cases where the field is used in nested calls )
[administrivia: please don't top-post around here].

There won't be any fast and clear rule and you'd need to grow and use common sense and good taste, but it probably is helpful to go back and think from the first principle, i.e. why you are doing this conversion.

For example, in your PATCH 2/2 that we are discussing, you updated the local variable "flags" to unsigned in show_bisect_vars(), because it receives the value from "info->flags", which is becoming an "unsigned" because it is a collection of independent bits.

The function uses this "flags" (now unsigned) twice, and one is to pass it to filter_skipped() as its 3rd parameter. This helper function takes "int", but you didn't update it to "unsigned". And you made the right decision to stop there.

The reason why it is the right place to stop is because the function does not use its 3rd parameter as a collection of bits; it wants its callers to give Yes/No there--anything non-zero is yes. Because you know "flags & BISECT_SHOW_ALL", which is unsigned, would be passed as a non-zero "int" to filter_skipped(), iff flags has that bit set, you know you do not have to touch that function and you stop there.

There will be similar places in the callchain that stop propagating the "collection-of-independent-bits"-ness. And that is where you would stop--because beyond that point there is no "arrgh, we use signed int to represent a collection of bits?" problem, which is what you are cleaning up.

Junio C Hamano· Apr 1, 2017, 19:12 UTC · re: Robert Stanca · lore

Re: [PATCH 1/2] [GSOC] Convert signed flags to unsigned

Robert Stanca <robert.stanca7@gmail.com> writes:
> Subject: Re: [PATCH 1/2] [GSOC] Convert signed flags to unsigned
Try
    git shortlog --no-merges -40

to learn how commits are typically titled. And then imagine this patch makes into our codebase and appear in the output.

Can you tell what this commit is about from that single line title? No. You wouldn't even know that it is only touching bisect.h and nothing else.

What do your readers want "shortlog" output to tell them about your commit? What are the most important thing (other than giving you an excuse to say "I have completed a microproject and now I am eligible to apply to GSoC" ;-)? Your proposed commit log message, especially its title, must be written to help future readers of the project history.

Perhaps
    bisect.h: make flags field in rev_list_info unsigned
would help them better.
>  Unsigned int is a closer representation of bitflags rather than signed int that uses 1 special bit for sign.This shouldn't make much difference because rev_list_info.flags uses only 2 bits(BISECT_SHOW_ALL and REV_LIST_QUIET)

Overlong lines, without space after full-stop before the second sentence, without full-stop at the end of the sentence.

Show 16 quoted lines
>
> Signed-off-by: Robert Stanca <robert.stanca7@gmail.com>
> ---
>  bisect.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/bisect.h b/bisect.h
> index acd12ef80..a979a7f11 100644
> --- a/bisect.h
> +++ b/bisect.h
> @@ -16,7 +16,7 @@ extern struct commit_list *filter_skipped(struct commit_list *list,
>  
>  struct rev_list_info {
>  	struct rev_info *revs;
> -	int flags;
> +	unsigned int flags;

Have you checked how this field is used? For example, there is this line somewhere in rev-list.c

	int cnt, flags = info->flags;

and the reason why the code copies the value to a local variable "flags" must be because it is going to use it, just like it and other codepaths use info->flags, no? It makes the code inconsistent by leaving the local variable a signed int, I suspect.

Robert Stanca· Apr 1, 2017, 19:30 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/2] [GSOC] Convert signed flags to unsigned

Regarding the first part , i can resend those 2 patches rewriting the commit message if you want.

On Sat, Apr 1, 2017 at 10:12 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 59 quoted lines
> Robert Stanca <robert.stanca7@gmail.com> writes:
>
>> Subject: Re: [PATCH 1/2] [GSOC] Convert signed flags to unsigned
>
> Try
>
>     git shortlog --no-merges -40
>
> to learn how commits are typically titled.  And then imagine this
> patch makes into our codebase and appear in the output.
>
> Can you tell what this commit is about from that single line title?
> No.  You wouldn't even know that it is only touching bisect.h and
> nothing else.
>
> What do your readers want "shortlog" output to tell them about your
> commit?  What are the most important thing (other than giving you an
> excuse to say "I have completed a microproject and now I am eligible
> to apply to GSoC" ;-)?  Your proposed commit log message, especially
> its title, must be written to help future readers of the project
> history.
>
> Perhaps
>
>     bisect.h: make flags field in rev_list_info unsigned
>
> would help them better.
>
>>  Unsigned int is a closer representation of bitflags rather than signed int that uses 1 special bit for sign.This shouldn't make much difference because rev_list_info.flags uses only 2 bits(BISECT_SHOW_ALL and REV_LIST_QUIET)
>
> Overlong lines, without space after full-stop before the second
> sentence, without full-stop at the end of the sentence.
>
>>
>> Signed-off-by: Robert Stanca <robert.stanca7@gmail.com>
>> ---
>>  bisect.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/bisect.h b/bisect.h
>> index acd12ef80..a979a7f11 100644
>> --- a/bisect.h
>> +++ b/bisect.h
>> @@ -16,7 +16,7 @@ extern struct commit_list *filter_skipped(struct commit_list *list,
>>
>>  struct rev_list_info {
>>       struct rev_info *revs;
>> -     int flags;
>> +     unsigned int flags;
>
> Have you checked how this field is used?  For example, there is this
> line somewhere in rev-list.c
>
>         int cnt, flags = info->flags;
>
> and the reason why the code copies the value to a local variable
> "flags" must be because it is going to use it, just like it and
> other codepaths use info->flags, no?  It makes the code inconsistent
> by leaving the local variable a signed int, I suspect.

← back to recent threads