git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/3] unpack-trees: use 'cuddled' style for if-else cascade

From
Ronnie Sahlberg <sahlberg@google.com>
Date
Aug 13, 2014, 14:52 UTC
Message-ID
<CAL=YDWnpiUOiCTrDfcXFUUJc+uP77kfNNoN3VZ+7g2i0fvXu2A@mail.gmail.com>
In-Reply-To
<20140813000045.GF24621@google.com>
On Tue, Aug 12, 2014 at 5:00 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 22 quoted lines
> Match the predominant style in git by following K&R style for if/else
> cascades.  Documentation/CodingStyle from linux.git explains:
>
>   Note that the closing brace is empty on a line of its own, _except_ in
>   the cases where it is followed by a continuation of the same statement,
>   ie a "while" in a do-statement or an "else" in an if-statement, like
>   this:
>
>         if (x == y) {
>                 ..
>         } else if (x > y) {
>                 ...
>         } else {
>                 ....
>         }
>
>   Rationale: K&R.
>
>   Also, note that this brace-placement also minimizes the number of empty
>   (or almost empty) lines, without any loss of readability.
>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Reviewed-by: Ronnie Sahlberg <sahlberg@google.com>
Show 44 quoted lines
> ---
>  unpack-trees.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/unpack-trees.c b/unpack-trees.c
> index f4a9aa9..187b15b 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -1771,8 +1771,7 @@ int twoway_merge(const struct cache_entry * const *src,
>                                         return merged_entry(newtree, current, o);
>                         }
>                         return o->gently ? -1 : reject_merge(current, o);
> -               }
> -               else if ((!oldtree && !newtree) || /* 4 and 5 */
> +               } else if ((!oldtree && !newtree) || /* 4 and 5 */
>                          (!oldtree && newtree &&
>                           same(current, newtree)) || /* 6 and 7 */
>                          (oldtree && newtree &&
> @@ -1781,17 +1780,14 @@ int twoway_merge(const struct cache_entry * const *src,
>                           !same(oldtree, newtree) && /* 18 and 19 */
>                           same(current, newtree))) {
>                         return keep_entry(current, o);
> -               }
> -               else if (oldtree && !newtree && same(current, oldtree)) {
> +               } else if (oldtree && !newtree && same(current, oldtree)) {
>                         /* 10 or 11 */
>                         return deleted_entry(oldtree, current, o);
> -               }
> -               else if (oldtree && newtree &&
> +               } else if (oldtree && newtree &&
>                          same(current, oldtree) && !same(current, newtree)) {
>                         /* 20 or 21 */
>                         return merged_entry(newtree, current, o);
> -               }
> -               else
> +               } else
>                         return o->gently ? -1 : reject_merge(current, o);
>         }
>         else if (newtree) {
> --
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous: Jonathan NiederNext: Jonathan Nieder
Message 8 of 15 in “unpack-tree.c: remove dead code”
  1. unpack-tree.c: remove dead codeStefan Beller, Aug 11, 2014
  2. Junio C HamanoAug 12, 2014
  3. unpack-tree.c: remove dead codeStefan Beller, Aug 12, 2014
  4. Junio C HamanoAug 12, 2014
  5. 0/3 Re: [PATCH] unpack-tree.c: remove dead codeJonathan Nieder, Aug 12, 2014
  6. 1/3 unpack-trees: simplify 'all other failures' caseJonathan Nieder, Aug 12, 2014
  7. 2/3 unpack-trees: use 'cuddled' style for if-else cascadeJonathan Nieder, Aug 13, 2014
  8. Ronnie SahlbergAug 13, 2014
  9. 3/3 checkout -m: attempt merge when deletion of path was stagedJonathan Nieder, Aug 13, 2014
  10. Junio C HamanoAug 13, 2014
  11. Junio C HamanoAug 13, 2014
  12. Junio C HamanoAug 13, 2014
  13. Johannes SixtAug 13, 2014
  14. Junio C HamanoAug 13, 2014
  15. Stefan BellerAug 13, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.