# [PATCH 1/1] builtin/blame.c: constants into bit shift format

9 messages from 2019-10-16 to 2019-10-17. Participants: Hariom Verma via GitGitGadget, Pratyush Yadav, Jonathan Tan, Junio C Hamano.
Thread: https://gitlist.dev/t/52050

## Hariom Verma via GitGitGadget, 2019-10-16 18:30

Subject: [PATCH 1/1] builtin/blame.c: constants into bit shift format
Message-ID: <3b4b8e0353d705ea649c9fb608c021b35e6d8f5b.1571250635.git.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/3b4b8e0353d705ea649c9fb608c021b35e6d8f5b.1571250635.git.gitgitgadget%40gmail.com
In-Reply-To: <pull.382.git.1571250635.gitgitgadget@gmail.com>

```
From: Hariom Verma <hariom18599@gmail.com>

We are looking at bitfield constants, and elsewhere in the Git source
code, such cases are handled via bit shift operators rather than octal
numbers, which also makes it easier to spot holes in the range
(if, say, 1<<5 was missing, it is easier to spot it between 1<<4
and 1<<6 than it is to spot a missing 040 between a 020 and a 0100).

Signed-off-by: Hariom Verma <hariom18599@gmail.com>
---
 builtin/blame.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index e946ba6cd9..a57020acf9 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -319,18 +319,18 @@ static const char *format_time(timestamp_t time, const char *tz_str,
 	return time_buf.buf;
 }
 
-#define OUTPUT_ANNOTATE_COMPAT	001
-#define OUTPUT_LONG_OBJECT_NAME	002
-#define OUTPUT_RAW_TIMESTAMP	004
-#define OUTPUT_PORCELAIN	010
-#define OUTPUT_SHOW_NAME	020
-#define OUTPUT_SHOW_NUMBER	040
-#define OUTPUT_SHOW_SCORE	0100
-#define OUTPUT_NO_AUTHOR	0200
-#define OUTPUT_SHOW_EMAIL	0400
-#define OUTPUT_LINE_PORCELAIN	01000
-#define OUTPUT_COLOR_LINE	02000
-#define OUTPUT_SHOW_AGE_WITH_COLOR	04000
+#define OUTPUT_ANNOTATE_COMPAT      (1<<0)
+#define OUTPUT_LONG_OBJECT_NAME     (1<<1)
+#define OUTPUT_RAW_TIMESTAMP        (1<<2)
+#define OUTPUT_PORCELAIN            (1<<3)
+#define OUTPUT_SHOW_NAME            (1<<4)
+#define OUTPUT_SHOW_NUMBER          (1<<5)
+#define OUTPUT_SHOW_SCORE           (1<<6)
+#define OUTPUT_NO_AUTHOR            (1<<7)
+#define OUTPUT_SHOW_EMAIL           (1<<8)
+#define OUTPUT_LINE_PORCELAIN       (1<<9)
+#define OUTPUT_COLOR_LINE           (1<<10)
+#define OUTPUT_SHOW_AGE_WITH_COLOR  (1<<11)
 
 static void emit_porcelain_details(struct blame_origin *suspect, int repeat)
 {
-- 
gitgitgadget

```

## Hariom Verma via GitGitGadget, 2019-10-16 18:30

Subject: [PATCH 0/1] builtin/blame.c: bit field constants into bit shift format
Message-ID: <pull.382.git.1571250635.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/pull.382.git.1571250635.gitgitgadget%40gmail.com

```
we are looking at bitfield constants, and elsewhere in the Git source code,
such cases are handled via bit shift operators rather than octal numbers,
which also makes it easier to spot holes in the range (if, say, 1<<5 was
missing, it is easier to spot it between 1<<4 and 1<<6 than it is to spot a
missing 040 between a 020 and a 0100). Also, bit shifts lead to low-level
optimizations because they require fewer calculations for the CPU. 

Special Thanks to @dscho for helping me out throughout the process.

Hariom Verma (1):
  builtin/blame.c: constants into bit shift format

 builtin/blame.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)


base-commit: 08da6496b61341ec45eac36afcc8f94242763468
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-382%2Fharry-hov%2Fenum-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-382/harry-hov/enum-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/382
-- 
gitgitgadget

```

## Pratyush Yadav, 2019-10-16 19:10

Subject: Re: [PATCH 1/1] builtin/blame.c: constants into bit shift format
Message-ID: <20191016191012.ij3zbexu7pxupdho@yadavpratyush.com>
URL: https://gitlist.dev/e/20191016191012.ij3zbexu7pxupdho%40yadavpratyush.com
In-Reply-To: <3b4b8e0353d705ea649c9fb608c021b35e6d8f5b.1571250635.git.gitgitgadget@gmail.com>

```
On 16/10/19 06:30PM, Hariom Verma via GitGitGadget wrote:
> From: Hariom Verma <hariom18599@gmail.com>
> 
> We are looking at bitfield constants, and elsewhere in the Git source
> code, such cases are handled via bit shift operators rather than octal
> numbers, which also makes it easier to spot holes in the range
> (if, say, 1<<5 was missing, it is easier to spot it between 1<<4
> and 1<<6 than it is to spot a missing 040 between a 020 and a 0100).
> 
> Signed-off-by: Hariom Verma <hariom18599@gmail.com>
> ---
>  builtin/blame.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/builtin/blame.c b/builtin/blame.c
> index e946ba6cd9..a57020acf9 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -319,18 +319,18 @@ static const char *format_time(timestamp_t time, const char *tz_str,
>  	return time_buf.buf;
>  }
>  
> -#define OUTPUT_ANNOTATE_COMPAT	001
> -#define OUTPUT_LONG_OBJECT_NAME	002
> -#define OUTPUT_RAW_TIMESTAMP	004
> -#define OUTPUT_PORCELAIN	010
> -#define OUTPUT_SHOW_NAME	020
> -#define OUTPUT_SHOW_NUMBER	040
> -#define OUTPUT_SHOW_SCORE	0100
> -#define OUTPUT_NO_AUTHOR	0200
> -#define OUTPUT_SHOW_EMAIL	0400
> -#define OUTPUT_LINE_PORCELAIN	01000
> -#define OUTPUT_COLOR_LINE	02000
> -#define OUTPUT_SHOW_AGE_WITH_COLOR	04000
> +#define OUTPUT_ANNOTATE_COMPAT      (1<<0)
> +#define OUTPUT_LONG_OBJECT_NAME     (1<<1)
> +#define OUTPUT_RAW_TIMESTAMP        (1<<2)
> +#define OUTPUT_PORCELAIN            (1<<3)
> +#define OUTPUT_SHOW_NAME            (1<<4)
> +#define OUTPUT_SHOW_NUMBER          (1<<5)
> +#define OUTPUT_SHOW_SCORE           (1<<6)
> +#define OUTPUT_NO_AUTHOR            (1<<7)
> +#define OUTPUT_SHOW_EMAIL           (1<<8)
> +#define OUTPUT_LINE_PORCELAIN       (1<<9)
> +#define OUTPUT_COLOR_LINE           (1<<10)
> +#define OUTPUT_SHOW_AGE_WITH_COLOR  (1<<11)

Nitpick: In the code you remove, tabs were used for alignment. Here, you 
use spaces. Unless there is any specific reason to do it this way, might 
as well keep the older style.

There was some discussion recently about converting these related 
#defines to enums [0]. We might consider doing that here.

If you read through that entire thread, you'd see that there were some 
disagreements about whether using enums for sets of bits is a good idea 
([1] and [2]), but it is at least something worth considering while we 
are on this topic.

FWIW, I think it is a good idea to use an enum here.

>  
>  static void emit_porcelain_details(struct blame_origin *suspect, int repeat)
>  {

[0] https://public-inbox.org/git/20191010115230.10623-1-wambui.karugax@gmail.com/
[1] https://public-inbox.org/git/20191014182754.82302-1-jonathantanmy@google.com/
[2] https://public-inbox.org/git/xmqqk19ag60g.fsf@gitster-ct.c.googlers.com/

-- 
Regards,
Pratyush Yadav

```

## Jonathan Tan, 2019-10-16 19:37

Subject: Re: [PATCH 1/1] builtin/blame.c: constants into bit shift format
Message-ID: <20191016193750.258148-1-jonathantanmy@google.com>
URL: https://gitlist.dev/e/20191016193750.258148-1-jonathantanmy%40google.com
In-Reply-To: <20191016191012.ij3zbexu7pxupdho@yadavpratyush.com>

```
> There was some discussion recently about converting these related 
> #defines to enums [0]. We might consider doing that here.
> 
> If you read through that entire thread, you'd see that there were some 
> disagreements about whether using enums for sets of bits is a good idea 
> ([1] and [2]), but it is at least something worth considering while we 
> are on this topic.
> 
> FWIW, I think it is a good idea to use an enum here.

[snip]

> [0] https://public-inbox.org/git/20191010115230.10623-1-wambui.karugax@gmail.com/
> [1] https://public-inbox.org/git/20191014182754.82302-1-jonathantanmy@google.com/
> [2] https://public-inbox.org/git/xmqqk19ag60g.fsf@gitster-ct.c.googlers.com/

Thanks for the handy references. You know my opinion on bitflags as
enums from reading them, but I think that we have already had that
discussion and came to a conclusion. So don't use an enum here.

The patch itself looks good, and I also prefer the bit shift format over
octal.

```

## Pratyush Yadav, 2019-10-16 19:44

Subject: Re: [PATCH 1/1] builtin/blame.c: constants into bit shift format
Message-ID: <20191016194431.pax5kahg7d3zhlmo@yadavpratyush.com>
URL: https://gitlist.dev/e/20191016194431.pax5kahg7d3zhlmo%40yadavpratyush.com
In-Reply-To: <20191016193750.258148-1-jonathantanmy@google.com>

```
On 16/10/19 12:37PM, Jonathan Tan wrote:
> > There was some discussion recently about converting these related 
> > #defines to enums [0]. We might consider doing that here.
> > 
> > If you read through that entire thread, you'd see that there were some 
> > disagreements about whether using enums for sets of bits is a good idea 
> > ([1] and [2]), but it is at least something worth considering while we 
> > are on this topic.
> > 
> > FWIW, I think it is a good idea to use an enum here.
> 
> [snip]
> 
> > [0] https://public-inbox.org/git/20191010115230.10623-1-wambui.karugax@gmail.com/
> > [1] https://public-inbox.org/git/20191014182754.82302-1-jonathantanmy@google.com/
> > [2] https://public-inbox.org/git/xmqqk19ag60g.fsf@gitster-ct.c.googlers.com/
> 
> Thanks for the handy references. You know my opinion on bitflags as
> enums from reading them, but I think that we have already had that
> discussion and came to a conclusion. So don't use an enum here.

Ah! I missed your last email in that thread that finally settled on 
avoiding bitsets, and thought the discussion was still ongoing. My bad 
:)
 
> The patch itself looks good, and I also prefer the bit shift format over
> octal.

-- 
Regards,
Pratyush Yadav

```

## Junio C Hamano, 2019-10-17 07:33

Subject: Re: [PATCH 0/1] builtin/blame.c: bit field constants into bit shift format
Message-ID: <xmqqv9sn7rn0.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqv9sn7rn0.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <pull.382.git.1571250635.gitgitgadget@gmail.com>

```
"Hariom Verma via GitGitGadget" <gitgitgadget@gmail.com> writes:

> we are looking at bitfield constants, and elsewhere in the Git source code,
> such cases are handled via bit shift operators rather than octal numbers,
> which also makes it easier to spot holes in the range (if, say, 1<<5 was
> missing, it is easier to spot it between 1<<4 and 1<<6 than it is to spot a
> missing 040 between a 020 and a 0100). Also, bit shifts lead to low-level
> optimizations because they require fewer calculations for the CPU. 

I think the last sentence is a nonsense for any decent compiler that
turns "1<<5" into 040 at compile time and treats it as literal
integer.  Luckily, it only appears here in the cover letter and does
not appear in the patch proper, so no need to resend the patch to
correct this ;-)


```

## Junio C Hamano, 2019-10-17 07:38

Subject: Re: [PATCH 1/1] builtin/blame.c: constants into bit shift format
Message-ID: <xmqqr23b7ref.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqr23b7ref.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <3b4b8e0353d705ea649c9fb608c021b35e6d8f5b.1571250635.git.gitgitgadget@gmail.com>

```
"Hariom Verma via GitGitGadget" <gitgitgadget@gmail.com> writes:

> -#define OUTPUT_SHOW_AGE_WITH_COLOR	04000
> +#define OUTPUT_ANNOTATE_COMPAT      (1<<0)
> +#define OUTPUT_LONG_OBJECT_NAME     (1<<1)
> +#define OUTPUT_RAW_TIMESTAMP        (1<<2)
> +#define OUTPUT_PORCELAIN            (1<<3)
> +#define OUTPUT_SHOW_NAME            (1<<4)
> +#define OUTPUT_SHOW_NUMBER          (1<<5)
> +#define OUTPUT_SHOW_SCORE           (1<<6)
> +#define OUTPUT_NO_AUTHOR            (1<<7)
> +#define OUTPUT_SHOW_EMAIL           (1<<8)
> +#define OUTPUT_LINE_PORCELAIN       (1<<9)
> +#define OUTPUT_COLOR_LINE           (1<<10)
> +#define OUTPUT_SHOW_AGE_WITH_COLOR  (1<<11)

For these small shift counts it probably would not matter, but it
may be a good discipline to make sure they are treated as constants
of an unsigned type (i.e. write them as (1U<<0) etc.).  It probably
starts to matter when you reach 1<<31 if these are bits stuffed into
"unsigned int" on 32-bit arch.

One advantage of octal and hexadecimal notations have is that
0x80000000 is automatically unsigned, IIRC, on such an archtecture.

```

## Hariom Verma via GitGitGadget, 2019-10-17 17:46

Subject: [PATCH v2 1/1] builtin/blame.c: constants into bit shift format
Message-ID: <838478a185322572ed4747eb484b678a8e2d7ac6.1571334411.git.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/838478a185322572ed4747eb484b678a8e2d7ac6.1571334411.git.gitgitgadget%40gmail.com
In-Reply-To: <pull.382.v2.git.1571334411.gitgitgadget@gmail.com>

```
From: Hariom Verma <hariom18599@gmail.com>

We are looking at bitfield constants, and elsewhere in the Git source
code, such cases are handled via bit shift operators rather than octal
numbers, which also makes it easier to spot holes in the range
(if, say, 1<<5 was missing, it is easier to spot it between 1<<4
and 1<<6 than it is to spot a missing 040 between a 020 and a 0100).

Signed-off-by: Hariom Verma <hariom18599@gmail.com>
---
 builtin/blame.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index e946ba6cd9..10185ccdc6 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -319,18 +319,18 @@ static const char *format_time(timestamp_t time, const char *tz_str,
 	return time_buf.buf;
 }
 
-#define OUTPUT_ANNOTATE_COMPAT	001
-#define OUTPUT_LONG_OBJECT_NAME	002
-#define OUTPUT_RAW_TIMESTAMP	004
-#define OUTPUT_PORCELAIN	010
-#define OUTPUT_SHOW_NAME	020
-#define OUTPUT_SHOW_NUMBER	040
-#define OUTPUT_SHOW_SCORE	0100
-#define OUTPUT_NO_AUTHOR	0200
-#define OUTPUT_SHOW_EMAIL	0400
-#define OUTPUT_LINE_PORCELAIN	01000
-#define OUTPUT_COLOR_LINE	02000
-#define OUTPUT_SHOW_AGE_WITH_COLOR	04000
+#define OUTPUT_ANNOTATE_COMPAT      (1U<<0)
+#define OUTPUT_LONG_OBJECT_NAME     (1U<<1)
+#define OUTPUT_RAW_TIMESTAMP        (1U<<2)
+#define OUTPUT_PORCELAIN            (1U<<3)
+#define OUTPUT_SHOW_NAME            (1U<<4)
+#define OUTPUT_SHOW_NUMBER          (1U<<5)
+#define OUTPUT_SHOW_SCORE           (1U<<6)
+#define OUTPUT_NO_AUTHOR            (1U<<7)
+#define OUTPUT_SHOW_EMAIL           (1U<<8)
+#define OUTPUT_LINE_PORCELAIN       (1U<<9)
+#define OUTPUT_COLOR_LINE           (1U<<10)
+#define OUTPUT_SHOW_AGE_WITH_COLOR  (1U<<11)
 
 static void emit_porcelain_details(struct blame_origin *suspect, int repeat)
 {
-- 
gitgitgadget

```

## Hariom Verma via GitGitGadget, 2019-10-17 17:46

Subject: [PATCH v2 0/1] builtin/blame.c: bit field constants into bit shift format
Message-ID: <pull.382.v2.git.1571334411.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/pull.382.v2.git.1571334411.gitgitgadget%40gmail.com
In-Reply-To: <pull.382.git.1571250635.gitgitgadget@gmail.com>

```
we are looking at bitfield constants, and elsewhere in the Git source code,
such cases are handled via bit shift operators rather than octal numbers,
which also makes it easier to spot holes in the range (if, say, 1<<5 was
missing, it is easier to spot it between 1<<4 and 1<<6 than it is to spot a
missing 040 between a 020 and a 0100). Also, bit shifts lead to low-level
optimizations because they require fewer calculations for the CPU. 

Special Thanks to @dscho for helping me out throughout the process.

Hariom Verma (1):
  builtin/blame.c: constants into bit shift format

 builtin/blame.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)


base-commit: 08da6496b61341ec45eac36afcc8f94242763468
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-382%2Fharry-hov%2Fenum-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-382/harry-hov/enum-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/382

Range-diff vs v1:

 1:  3b4b8e0353 ! 1:  838478a185 builtin/blame.c: constants into bit shift format
     @@ -29,18 +29,18 @@
      -#define OUTPUT_LINE_PORCELAIN	01000
      -#define OUTPUT_COLOR_LINE	02000
      -#define OUTPUT_SHOW_AGE_WITH_COLOR	04000
     -+#define OUTPUT_ANNOTATE_COMPAT      (1<<0)
     -+#define OUTPUT_LONG_OBJECT_NAME     (1<<1)
     -+#define OUTPUT_RAW_TIMESTAMP        (1<<2)
     -+#define OUTPUT_PORCELAIN            (1<<3)
     -+#define OUTPUT_SHOW_NAME            (1<<4)
     -+#define OUTPUT_SHOW_NUMBER          (1<<5)
     -+#define OUTPUT_SHOW_SCORE           (1<<6)
     -+#define OUTPUT_NO_AUTHOR            (1<<7)
     -+#define OUTPUT_SHOW_EMAIL           (1<<8)
     -+#define OUTPUT_LINE_PORCELAIN       (1<<9)
     -+#define OUTPUT_COLOR_LINE           (1<<10)
     -+#define OUTPUT_SHOW_AGE_WITH_COLOR  (1<<11)
     ++#define OUTPUT_ANNOTATE_COMPAT      (1U<<0)
     ++#define OUTPUT_LONG_OBJECT_NAME     (1U<<1)
     ++#define OUTPUT_RAW_TIMESTAMP        (1U<<2)
     ++#define OUTPUT_PORCELAIN            (1U<<3)
     ++#define OUTPUT_SHOW_NAME            (1U<<4)
     ++#define OUTPUT_SHOW_NUMBER          (1U<<5)
     ++#define OUTPUT_SHOW_SCORE           (1U<<6)
     ++#define OUTPUT_NO_AUTHOR            (1U<<7)
     ++#define OUTPUT_SHOW_EMAIL           (1U<<8)
     ++#define OUTPUT_LINE_PORCELAIN       (1U<<9)
     ++#define OUTPUT_COLOR_LINE           (1U<<10)
     ++#define OUTPUT_SHOW_AGE_WITH_COLOR  (1U<<11)
       
       static void emit_porcelain_details(struct blame_origin *suspect, int repeat)
       {

-- 
gitgitgadget

```
