{"thread":{"id":"52050","subject":"[PATCH 1/1] builtin/blame.c: constants into bit shift format","startedAt":"2019-10-16T18:30:47Z","lastAt":"2019-10-17T17:47:53Z","messageCount":9,"participants":["Hariom Verma via GitGitGadget","Pratyush Yadav","Jonathan Tan","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"384198","messageId":"3b4b8e0353d705ea649c9fb608c021b35e6d8f5b.1571250635.git.gitgitgadget@gmail.com","threadId":"52050","inReplyTo":"pull.382.git.1571250635.gitgitgadget@gmail.com","subject":"[PATCH 1/1] builtin/blame.c: constants into bit shift format","fromName":"Hariom Verma via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-10-16T18:30:35Z","receivedAt":"2019-10-16T18:30:47Z","isPatch":true,"sender":{"key":"name:Hariom Verma","avatar":null},"body":"From: Hariom Verma <hariom18599@gmail.com>\n\nWe are looking at bitfield constants, and elsewhere in the Git source\ncode, such cases are handled via bit shift operators rather than octal\nnumbers, which also makes it easier to spot holes in the range\n(if, say, 1<<5 was missing, it is easier to spot it between 1<<4\nand 1<<6 than it is to spot a missing 040 between a 020 and a 0100).\n\nSigned-off-by: Hariom Verma <hariom18599@gmail.com>\n---\n builtin/blame.c | 24 ++++++++++++------------\n 1 file changed, 12 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex e946ba6cd9..a57020acf9 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -319,18 +319,18 @@ static const char *format_time(timestamp_t time, const char *tz_str,\n \treturn time_buf.buf;\n }\n \n-#define OUTPUT_ANNOTATE_COMPAT\t001\n-#define OUTPUT_LONG_OBJECT_NAME\t002\n-#define OUTPUT_RAW_TIMESTAMP\t004\n-#define OUTPUT_PORCELAIN\t010\n-#define OUTPUT_SHOW_NAME\t020\n-#define OUTPUT_SHOW_NUMBER\t040\n-#define OUTPUT_SHOW_SCORE\t0100\n-#define OUTPUT_NO_AUTHOR\t0200\n-#define OUTPUT_SHOW_EMAIL\t0400\n-#define OUTPUT_LINE_PORCELAIN\t01000\n-#define OUTPUT_COLOR_LINE\t02000\n-#define OUTPUT_SHOW_AGE_WITH_COLOR\t04000\n+#define OUTPUT_ANNOTATE_COMPAT      (1<<0)\n+#define OUTPUT_LONG_OBJECT_NAME     (1<<1)\n+#define OUTPUT_RAW_TIMESTAMP        (1<<2)\n+#define OUTPUT_PORCELAIN            (1<<3)\n+#define OUTPUT_SHOW_NAME            (1<<4)\n+#define OUTPUT_SHOW_NUMBER          (1<<5)\n+#define OUTPUT_SHOW_SCORE           (1<<6)\n+#define OUTPUT_NO_AUTHOR            (1<<7)\n+#define OUTPUT_SHOW_EMAIL           (1<<8)\n+#define OUTPUT_LINE_PORCELAIN       (1<<9)\n+#define OUTPUT_COLOR_LINE           (1<<10)\n+#define OUTPUT_SHOW_AGE_WITH_COLOR  (1<<11)\n \n static void emit_porcelain_details(struct blame_origin *suspect, int repeat)\n {\n-- \ngitgitgadget\n"},{"id":"384199","messageId":"pull.382.git.1571250635.gitgitgadget@gmail.com","threadId":"52050","inReplyTo":null,"subject":"[PATCH 0/1] builtin/blame.c: bit field constants into bit shift format","fromName":"Hariom Verma via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-10-16T18:30:34Z","receivedAt":"2019-10-16T18:30:48Z","isPatch":true,"sender":{"key":"name:Hariom Verma","avatar":null},"body":"we are looking at bitfield constants, and elsewhere in the Git source code,\nsuch cases are handled via bit shift operators rather than octal numbers,\nwhich also makes it easier to spot holes in the range (if, say, 1<<5 was\nmissing, it is easier to spot it between 1<<4 and 1<<6 than it is to spot a\nmissing 040 between a 020 and a 0100). Also, bit shifts lead to low-level\noptimizations because they require fewer calculations for the CPU. \n\nSpecial Thanks to @dscho for helping me out throughout the process.\n\nHariom Verma (1):\n  builtin/blame.c: constants into bit shift format\n\n builtin/blame.c | 24 ++++++++++++------------\n 1 file changed, 12 insertions(+), 12 deletions(-)\n\n\nbase-commit: 08da6496b61341ec45eac36afcc8f94242763468\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-382%2Fharry-hov%2Fenum-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-382/harry-hov/enum-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/382\n-- \ngitgitgadget\n"},{"id":"384203","messageId":"20191016191012.ij3zbexu7pxupdho@yadavpratyush.com","threadId":"52050","inReplyTo":"3b4b8e0353d705ea649c9fb608c021b35e6d8f5b.1571250635.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/1] builtin/blame.c: constants into bit shift format","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2019-10-16T19:10:12Z","receivedAt":"2019-10-16T19:10:19Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"On 16/10/19 06:30PM, Hariom Verma via GitGitGadget wrote:\n> From: Hariom Verma <hariom18599@gmail.com>\n> \n> We are looking at bitfield constants, and elsewhere in the Git source\n> code, such cases are handled via bit shift operators rather than octal\n> numbers, which also makes it easier to spot holes in the range\n> (if, say, 1<<5 was missing, it is easier to spot it between 1<<4\n> and 1<<6 than it is to spot a missing 040 between a 020 and a 0100).\n> \n> Signed-off-by: Hariom Verma <hariom18599@gmail.com>\n> ---\n>  builtin/blame.c | 24 ++++++++++++------------\n>  1 file changed, 12 insertions(+), 12 deletions(-)\n> \n> diff --git a/builtin/blame.c b/builtin/blame.c\n> index e946ba6cd9..a57020acf9 100644\n> --- a/builtin/blame.c\n> +++ b/builtin/blame.c\n> @@ -319,18 +319,18 @@ static const char *format_time(timestamp_t time, const char *tz_str,\n>  \treturn time_buf.buf;\n>  }\n>  \n> -#define OUTPUT_ANNOTATE_COMPAT\t001\n> -#define OUTPUT_LONG_OBJECT_NAME\t002\n> -#define OUTPUT_RAW_TIMESTAMP\t004\n> -#define OUTPUT_PORCELAIN\t010\n> -#define OUTPUT_SHOW_NAME\t020\n> -#define OUTPUT_SHOW_NUMBER\t040\n> -#define OUTPUT_SHOW_SCORE\t0100\n> -#define OUTPUT_NO_AUTHOR\t0200\n> -#define OUTPUT_SHOW_EMAIL\t0400\n> -#define OUTPUT_LINE_PORCELAIN\t01000\n> -#define OUTPUT_COLOR_LINE\t02000\n> -#define OUTPUT_SHOW_AGE_WITH_COLOR\t04000\n> +#define OUTPUT_ANNOTATE_COMPAT      (1<<0)\n> +#define OUTPUT_LONG_OBJECT_NAME     (1<<1)\n> +#define OUTPUT_RAW_TIMESTAMP        (1<<2)\n> +#define OUTPUT_PORCELAIN            (1<<3)\n> +#define OUTPUT_SHOW_NAME            (1<<4)\n> +#define OUTPUT_SHOW_NUMBER          (1<<5)\n> +#define OUTPUT_SHOW_SCORE           (1<<6)\n> +#define OUTPUT_NO_AUTHOR            (1<<7)\n> +#define OUTPUT_SHOW_EMAIL           (1<<8)\n> +#define OUTPUT_LINE_PORCELAIN       (1<<9)\n> +#define OUTPUT_COLOR_LINE           (1<<10)\n> +#define OUTPUT_SHOW_AGE_WITH_COLOR  (1<<11)\n\nNitpick: In the code you remove, tabs were used for alignment. Here, you \nuse spaces. Unless there is any specific reason to do it this way, might \nas well keep the older style.\n\nThere was some discussion recently about converting these related \n#defines to enums [0]. We might consider doing that here.\n\nIf you read through that entire thread, you'd see that there were some \ndisagreements about whether using enums for sets of bits is a good idea \n([1] and [2]), but it is at least something worth considering while we \nare on this topic.\n\nFWIW, I think it is a good idea to use an enum here.\n\n>  \n>  static void emit_porcelain_details(struct blame_origin *suspect, int repeat)\n>  {\n\n[0] https://public-inbox.org/git/20191010115230.10623-1-wambui.karugax@gmail.com/\n[1] https://public-inbox.org/git/20191014182754.82302-1-jonathantanmy@google.com/\n[2] https://public-inbox.org/git/xmqqk19ag60g.fsf@gitster-ct.c.googlers.com/\n\n-- \nRegards,\nPratyush Yadav\n"},{"id":"384208","messageId":"20191016193750.258148-1-jonathantanmy@google.com","threadId":"52050","inReplyTo":"20191016191012.ij3zbexu7pxupdho@yadavpratyush.com","subject":"Re: [PATCH 1/1] builtin/blame.c: constants into bit shift format","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2019-10-16T19:37:50Z","receivedAt":"2019-10-16T19:37:56Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"> There was some discussion recently about converting these related \n> #defines to enums [0]. We might consider doing that here.\n> \n> If you read through that entire thread, you'd see that there were some \n> disagreements about whether using enums for sets of bits is a good idea \n> ([1] and [2]), but it is at least something worth considering while we \n> are on this topic.\n> \n> FWIW, I think it is a good idea to use an enum here.\n\n[snip]\n\n> [0] https://public-inbox.org/git/20191010115230.10623-1-wambui.karugax@gmail.com/\n> [1] https://public-inbox.org/git/20191014182754.82302-1-jonathantanmy@google.com/\n> [2] https://public-inbox.org/git/xmqqk19ag60g.fsf@gitster-ct.c.googlers.com/\n\nThanks for the handy references. You know my opinion on bitflags as\nenums from reading them, but I think that we have already had that\ndiscussion and came to a conclusion. So don't use an enum here.\n\nThe patch itself looks good, and I also prefer the bit shift format over\noctal.\n"},{"id":"384209","messageId":"20191016194431.pax5kahg7d3zhlmo@yadavpratyush.com","threadId":"52050","inReplyTo":"20191016193750.258148-1-jonathantanmy@google.com","subject":"Re: [PATCH 1/1] builtin/blame.c: constants into bit shift format","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2019-10-16T19:44:31Z","receivedAt":"2019-10-16T19:44:39Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"On 16/10/19 12:37PM, Jonathan Tan wrote:\n> > There was some discussion recently about converting these related \n> > #defines to enums [0]. We might consider doing that here.\n> > \n> > If you read through that entire thread, you'd see that there were some \n> > disagreements about whether using enums for sets of bits is a good idea \n> > ([1] and [2]), but it is at least something worth considering while we \n> > are on this topic.\n> > \n> > FWIW, I think it is a good idea to use an enum here.\n> \n> [snip]\n> \n> > [0] https://public-inbox.org/git/20191010115230.10623-1-wambui.karugax@gmail.com/\n> > [1] https://public-inbox.org/git/20191014182754.82302-1-jonathantanmy@google.com/\n> > [2] https://public-inbox.org/git/xmqqk19ag60g.fsf@gitster-ct.c.googlers.com/\n> \n> Thanks for the handy references. You know my opinion on bitflags as\n> enums from reading them, but I think that we have already had that\n> discussion and came to a conclusion. So don't use an enum here.\n\nAh! I missed your last email in that thread that finally settled on \navoiding bitsets, and thought the discussion was still ongoing. My bad \n:)\n \n> The patch itself looks good, and I also prefer the bit shift format over\n> octal.\n\n-- \nRegards,\nPratyush Yadav\n"},{"id":"384247","messageId":"xmqqv9sn7rn0.fsf@gitster-ct.c.googlers.com","threadId":"52050","inReplyTo":"pull.382.git.1571250635.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/1] builtin/blame.c: bit field constants into bit shift format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-10-17T07:33:39Z","receivedAt":"2019-10-17T07:35:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Hariom Verma via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> we are looking at bitfield constants, and elsewhere in the Git source code,\n> such cases are handled via bit shift operators rather than octal numbers,\n> which also makes it easier to spot holes in the range (if, say, 1<<5 was\n> missing, it is easier to spot it between 1<<4 and 1<<6 than it is to spot a\n> missing 040 between a 020 and a 0100). Also, bit shifts lead to low-level\n> optimizations because they require fewer calculations for the CPU. \n\nI think the last sentence is a nonsense for any decent compiler that\nturns \"1<<5\" into 040 at compile time and treats it as literal\ninteger.  Luckily, it only appears here in the cover letter and does\nnot appear in the patch proper, so no need to resend the patch to\ncorrect this ;-)\n\n"},{"id":"384248","messageId":"xmqqr23b7ref.fsf@gitster-ct.c.googlers.com","threadId":"52050","inReplyTo":"3b4b8e0353d705ea649c9fb608c021b35e6d8f5b.1571250635.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/1] builtin/blame.c: constants into bit shift format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-10-17T07:38:48Z","receivedAt":"2019-10-17T07:38:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Hariom Verma via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> -#define OUTPUT_SHOW_AGE_WITH_COLOR\t04000\n> +#define OUTPUT_ANNOTATE_COMPAT      (1<<0)\n> +#define OUTPUT_LONG_OBJECT_NAME     (1<<1)\n> +#define OUTPUT_RAW_TIMESTAMP        (1<<2)\n> +#define OUTPUT_PORCELAIN            (1<<3)\n> +#define OUTPUT_SHOW_NAME            (1<<4)\n> +#define OUTPUT_SHOW_NUMBER          (1<<5)\n> +#define OUTPUT_SHOW_SCORE           (1<<6)\n> +#define OUTPUT_NO_AUTHOR            (1<<7)\n> +#define OUTPUT_SHOW_EMAIL           (1<<8)\n> +#define OUTPUT_LINE_PORCELAIN       (1<<9)\n> +#define OUTPUT_COLOR_LINE           (1<<10)\n> +#define OUTPUT_SHOW_AGE_WITH_COLOR  (1<<11)\n\nFor these small shift counts it probably would not matter, but it\nmay be a good discipline to make sure they are treated as constants\nof an unsigned type (i.e. write them as (1U<<0) etc.).  It probably\nstarts to matter when you reach 1<<31 if these are bits stuffed into\n\"unsigned int\" on 32-bit arch.\n\nOne advantage of octal and hexadecimal notations have is that\n0x80000000 is automatically unsigned, IIRC, on such an archtecture.\n"},{"id":"384279","messageId":"838478a185322572ed4747eb484b678a8e2d7ac6.1571334411.git.gitgitgadget@gmail.com","threadId":"52050","inReplyTo":"pull.382.v2.git.1571334411.gitgitgadget@gmail.com","subject":"[PATCH v2 1/1] builtin/blame.c: constants into bit shift format","fromName":"Hariom Verma via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-10-17T17:46:51Z","receivedAt":"2019-10-17T17:47:45Z","isPatch":true,"sender":{"key":"name:Hariom Verma","avatar":null},"body":"From: Hariom Verma <hariom18599@gmail.com>\n\nWe are looking at bitfield constants, and elsewhere in the Git source\ncode, such cases are handled via bit shift operators rather than octal\nnumbers, which also makes it easier to spot holes in the range\n(if, say, 1<<5 was missing, it is easier to spot it between 1<<4\nand 1<<6 than it is to spot a missing 040 between a 020 and a 0100).\n\nSigned-off-by: Hariom Verma <hariom18599@gmail.com>\n---\n builtin/blame.c | 24 ++++++++++++------------\n 1 file changed, 12 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex e946ba6cd9..10185ccdc6 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -319,18 +319,18 @@ static const char *format_time(timestamp_t time, const char *tz_str,\n \treturn time_buf.buf;\n }\n \n-#define OUTPUT_ANNOTATE_COMPAT\t001\n-#define OUTPUT_LONG_OBJECT_NAME\t002\n-#define OUTPUT_RAW_TIMESTAMP\t004\n-#define OUTPUT_PORCELAIN\t010\n-#define OUTPUT_SHOW_NAME\t020\n-#define OUTPUT_SHOW_NUMBER\t040\n-#define OUTPUT_SHOW_SCORE\t0100\n-#define OUTPUT_NO_AUTHOR\t0200\n-#define OUTPUT_SHOW_EMAIL\t0400\n-#define OUTPUT_LINE_PORCELAIN\t01000\n-#define OUTPUT_COLOR_LINE\t02000\n-#define OUTPUT_SHOW_AGE_WITH_COLOR\t04000\n+#define OUTPUT_ANNOTATE_COMPAT      (1U<<0)\n+#define OUTPUT_LONG_OBJECT_NAME     (1U<<1)\n+#define OUTPUT_RAW_TIMESTAMP        (1U<<2)\n+#define OUTPUT_PORCELAIN            (1U<<3)\n+#define OUTPUT_SHOW_NAME            (1U<<4)\n+#define OUTPUT_SHOW_NUMBER          (1U<<5)\n+#define OUTPUT_SHOW_SCORE           (1U<<6)\n+#define OUTPUT_NO_AUTHOR            (1U<<7)\n+#define OUTPUT_SHOW_EMAIL           (1U<<8)\n+#define OUTPUT_LINE_PORCELAIN       (1U<<9)\n+#define OUTPUT_COLOR_LINE           (1U<<10)\n+#define OUTPUT_SHOW_AGE_WITH_COLOR  (1U<<11)\n \n static void emit_porcelain_details(struct blame_origin *suspect, int repeat)\n {\n-- \ngitgitgadget\n"},{"id":"384280","messageId":"pull.382.v2.git.1571334411.gitgitgadget@gmail.com","threadId":"52050","inReplyTo":"pull.382.git.1571250635.gitgitgadget@gmail.com","subject":"[PATCH v2 0/1] builtin/blame.c: bit field constants into bit shift format","fromName":"Hariom Verma via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-10-17T17:46:50Z","receivedAt":"2019-10-17T17:47:53Z","isPatch":true,"sender":{"key":"name:Hariom Verma","avatar":null},"body":"we are looking at bitfield constants, and elsewhere in the Git source code,\nsuch cases are handled via bit shift operators rather than octal numbers,\nwhich also makes it easier to spot holes in the range (if, say, 1<<5 was\nmissing, it is easier to spot it between 1<<4 and 1<<6 than it is to spot a\nmissing 040 between a 020 and a 0100). Also, bit shifts lead to low-level\noptimizations because they require fewer calculations for the CPU. \n\nSpecial Thanks to @dscho for helping me out throughout the process.\n\nHariom Verma (1):\n  builtin/blame.c: constants into bit shift format\n\n builtin/blame.c | 24 ++++++++++++------------\n 1 file changed, 12 insertions(+), 12 deletions(-)\n\n\nbase-commit: 08da6496b61341ec45eac36afcc8f94242763468\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-382%2Fharry-hov%2Fenum-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-382/harry-hov/enum-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/382\n\nRange-diff vs v1:\n\n 1:  3b4b8e0353 ! 1:  838478a185 builtin/blame.c: constants into bit shift format\n     @@ -29,18 +29,18 @@\n      -#define OUTPUT_LINE_PORCELAIN\t01000\n      -#define OUTPUT_COLOR_LINE\t02000\n      -#define OUTPUT_SHOW_AGE_WITH_COLOR\t04000\n     -+#define OUTPUT_ANNOTATE_COMPAT      (1<<0)\n     -+#define OUTPUT_LONG_OBJECT_NAME     (1<<1)\n     -+#define OUTPUT_RAW_TIMESTAMP        (1<<2)\n     -+#define OUTPUT_PORCELAIN            (1<<3)\n     -+#define OUTPUT_SHOW_NAME            (1<<4)\n     -+#define OUTPUT_SHOW_NUMBER          (1<<5)\n     -+#define OUTPUT_SHOW_SCORE           (1<<6)\n     -+#define OUTPUT_NO_AUTHOR            (1<<7)\n     -+#define OUTPUT_SHOW_EMAIL           (1<<8)\n     -+#define OUTPUT_LINE_PORCELAIN       (1<<9)\n     -+#define OUTPUT_COLOR_LINE           (1<<10)\n     -+#define OUTPUT_SHOW_AGE_WITH_COLOR  (1<<11)\n     ++#define OUTPUT_ANNOTATE_COMPAT      (1U<<0)\n     ++#define OUTPUT_LONG_OBJECT_NAME     (1U<<1)\n     ++#define OUTPUT_RAW_TIMESTAMP        (1U<<2)\n     ++#define OUTPUT_PORCELAIN            (1U<<3)\n     ++#define OUTPUT_SHOW_NAME            (1U<<4)\n     ++#define OUTPUT_SHOW_NUMBER          (1U<<5)\n     ++#define OUTPUT_SHOW_SCORE           (1U<<6)\n     ++#define OUTPUT_NO_AUTHOR            (1U<<7)\n     ++#define OUTPUT_SHOW_EMAIL           (1U<<8)\n     ++#define OUTPUT_LINE_PORCELAIN       (1U<<9)\n     ++#define OUTPUT_COLOR_LINE           (1U<<10)\n     ++#define OUTPUT_SHOW_AGE_WITH_COLOR  (1U<<11)\n       \n       static void emit_porcelain_details(struct blame_origin *suspect, int repeat)\n       {\n\n-- \ngitgitgadget\n"}]}