{"thread":{"id":"55811","subject":"[PATCH v3 0/7] Unconvolutize push.default=simple","startedAt":"2021-05-31T19:32:48Z","lastAt":"2021-06-02T04:05:07Z","messageCount":24,"participants":["Felipe Contreras","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":7},"messages":[{"id":"426055","messageId":"20210531193237.216726-1-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":null,"subject":"[PATCH v3 0/7] Unconvolutize push.default=simple","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:32:30Z","receivedAt":"2021-05-31T19:32:48Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Tired of jumping through hoops trying to understand what the \"simple\"\nmode does, I decided to reorganize it up for good so it's crystal\nclear.\n\nThere are no functional changes.\n\nBasically the simple mode pushes the current branch with the same name\non the remote.\n\nExcept... when there's no upstream branch configured with the same name.\n\nNow the code and the documentation are clear.\n\nThe difference from v2 is that now triangular is renamed to same_remote in the very first patch.\nThat way the rest of both series are easier to digest.\n\nUnfortunately the first patch is a little noisy, and the same with the rangediff. That might be a\nsmall price to pay to make the rest easier.\n\nThe result of this series is in short this function:\n\nstatic void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n{\n\tif (!branch)\n\t\tdie(_(message_detached_head_die), remote->name);\n\n\tif (same_remote) {\n\t\tif (!branch->merge_nr || !branch->merge || !branch->remote_name)\n\t\t\tdie(_(\"The current branch %s has no upstream branch.\\n\"\n\t\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n\t\t\t    \"\\n\"\n\t\t\t    \"    git push --set-upstream %s %s\\n\"),\n\t\t\t    branch->name,\n\t\t\t    remote->name,\n\t\t\t    branch->name);\n\t\tif (branch->merge_nr != 1)\n\t\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n\t\t\t    \"refusing to push.\"), branch->name);\n\n\t\t/* Additional safety */\n\t\tif (strcmp(branch->refname, branch->merge[0]->src))\n\t\t\tdie_push_simple(branch, remote);\n\t}\n\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n}\n\nFelipe Contreras (7):\n  push: rename !triangular to same_remote\n  push: hedge code of default=simple\n  push: copy code to setup_push_simple()\n  push: reorganize setup_push_simple()\n  push: simplify setup_push_simple()\n  push: remove unused code in setup_push_upstream()\n  doc: push: explain default=simple correctly\n\n Documentation/config/push.txt | 13 +++++-----\n builtin/push.c                | 48 +++++++++++++++++++++++------------\n 2 files changed, 38 insertions(+), 23 deletions(-)\n\nRange-diff against v2:\n1:  f1f42bda32 < -:  ---------- push: hedge code of default=simple\n-:  ---------- > 1:  e8efe0d844 push: rename !triangular to same_remote\n-:  ---------- > 2:  f84aa09a93 push: hedge code of default=simple\n2:  bb6d810011 ! 3:  7d04af5b2c push: move code to setup_push_simple()\n    @@ Metadata\n     Author: Felipe Contreras <felipe.contreras@gmail.com>\n     \n      ## Commit message ##\n    -    push: move code to setup_push_simple()\n    +    push: copy code to setup_push_simple()\n     \n         In order to avoid doing unnecessary things and simplify it in further\n    -    patches.\n    +    patches. In particular moving the additional name safety out of\n    +    setup_push_upstream() and into setup_push_simple() and thus making both\n    +    more straightforward.\n     \n         The code is copied exactly as-is; no functional changes.\n     \n    @@ Commit message\n      ## builtin/push.c ##\n     @@ builtin/push.c: static void setup_push_current(struct remote *remote, struct branch *branch)\n      \n    - static void setup_push_simple(struct remote *remote, struct branch *branch, int triangular)\n    + static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n      {\n    --\tif (triangular)\n    +-\tif (!same_remote)\n     -\t\tsetup_push_current(remote, branch);\n     -\telse\n    --\t\tsetup_push_upstream(remote, branch, triangular, 1);\n    -+\tif (triangular) {\n    +-\t\tsetup_push_upstream(remote, branch, same_remote, 1);\n    ++\tif (!same_remote) {\n     +\t\tif (!branch)\n     +\t\t\tdie(_(message_detached_head_die), remote->name);\n     +\t\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n    @@ builtin/push.c: static void setup_push_current(struct remote *remote, struct bra\n     +\t\tif (branch->merge_nr != 1)\n     +\t\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n     +\t\t\t    \"refusing to push.\"), branch->name);\n    -+\t\tif (triangular)\n    ++\t\tif (!same_remote)\n     +\t\t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n     +\t\t\t      \"your current branch '%s', without telling me what to push\\n\"\n     +\t\t\t      \"to update which remote branch.\"),\n    @@ builtin/push.c: static void setup_push_current(struct remote *remote, struct bra\n     +\t}\n      }\n      \n    - static int is_workflow_triangular(struct remote *remote)\n    + static int is_same_remote(struct remote *remote)\n3:  d66a442fba ! 4:  5e0e09bc7a push: reorganize setup_push_simple()\n    @@ Commit message\n         push: reorganize setup_push_simple()\n     \n         Simply move the code around and remove dead code. In particular the\n    -    'trivial' conditional is a no-op since that part of the code is the\n    -    !trivial leg of the conditional beforehand.\n    +    '!same_remote' conditional is a no-op since that part of the code is the\n    +    same_remote leg of the conditional beforehand.\n     \n         No functional changes.\n     \n    @@ Commit message\n      ## builtin/push.c ##\n     @@ builtin/push.c: static void setup_push_current(struct remote *remote, struct branch *branch)\n      \n    - static void setup_push_simple(struct remote *remote, struct branch *branch, int triangular)\n    + static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n      {\n     +\tconst char *dst;\n     +\n     +\tif (!branch)\n     +\t\tdie(_(message_detached_head_die), remote->name);\n     +\n    - \tif (triangular) {\n    + \tif (!same_remote) {\n     -\t\tif (!branch)\n     -\t\t\tdie(_(message_detached_head_die), remote->name);\n     -\t\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n    @@ builtin/push.c: static void setup_push_simple(struct remote *remote, struct bran\n      \t\tif (branch->merge_nr != 1)\n      \t\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n      \t\t\t    \"refusing to push.\"), branch->name);\n    --\t\tif (triangular)\n    +-\t\tif (!same_remote)\n     -\t\t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n     -\t\t\t      \"your current branch '%s', without telling me what to push\\n\"\n     -\t\t\t      \"to update which remote branch.\"),\n    @@ builtin/push.c: static void setup_push_simple(struct remote *remote, struct bran\n     +\trefspec_appendf(&rs, \"%s:%s\", branch->refname, dst);\n      }\n      \n    - static int is_workflow_triangular(struct remote *remote)\n    + static int is_same_remote(struct remote *remote)\n4:  eaae6a826a ! 5:  723d95b572 push: simplify setup_push_simple()\n    @@ Metadata\n      ## Commit message ##\n         push: simplify setup_push_simple()\n     \n    -    There's a safety check to make sure branch->refname is not different\n    +    There's a safety check to make sure branch->refname isn't different\n         from branch->merge[0]->src, otherwise we die().\n     \n         Therefore we always push to branch->refname.\n    @@ Commit message\n      ## builtin/push.c ##\n     @@ builtin/push.c: static void setup_push_current(struct remote *remote, struct branch *branch)\n      \n    - static void setup_push_simple(struct remote *remote, struct branch *branch, int triangular)\n    + static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n      {\n     -\tconst char *dst;\n     -\n      \tif (!branch)\n      \t\tdie(_(message_detached_head_die), remote->name);\n      \n    --\tif (triangular) {\n    +-\tif (!same_remote) {\n     -\t\tdst = branch->refname;\n     -\t} else {\n    -+\tif (!triangular) {\n    ++\tif (same_remote) {\n      \t\tif (!branch->merge_nr || !branch->merge || !branch->remote_name)\n      \t\t\tdie(_(\"The current branch %s has no upstream branch.\\n\"\n      \t\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n    @@ builtin/push.c: static void setup_push_simple(struct remote *remote, struct bran\n     +\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n      }\n      \n    - static int is_workflow_triangular(struct remote *remote)\n    + static int is_same_remote(struct remote *remote)\n5:  8d9ae5e552 ! 6:  8ffaacd0db push: remove unused code in setup_push_upstream()\n    @@ builtin/push.c: static const char message_detached_head_die[] =\n      \t   \"    git push %s HEAD:<name-of-remote-branch>\\n\");\n      \n      static void setup_push_upstream(struct remote *remote, struct branch *branch,\n    --\t\t\t\tint triangular, int simple)\n    -+\t\t\t\tint triangular)\n    +-\t\t\t\tint same_remote, int simple)\n    ++\t\t\t\tint same_remote)\n      {\n      \tif (!branch)\n      \t\tdie(_(message_detached_head_die), remote->name);\n    @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n      \t\tbreak;\n      \n      \tcase PUSH_DEFAULT_UPSTREAM:\n    --\t\tsetup_push_upstream(remote, branch, triangular, 0);\n    -+\t\tsetup_push_upstream(remote, branch, triangular);\n    +-\t\tsetup_push_upstream(remote, branch, same_remote, 0);\n    ++\t\tsetup_push_upstream(remote, branch, same_remote);\n      \t\tbreak;\n      \n      \tcase PUSH_DEFAULT_CURRENT:\n6:  b35bdf14dc = 7:  3cc20c876f doc: push: explain default=simple correctly\n-- \n2.32.0.rc0\n\n"},{"id":"426056","messageId":"20210531193237.216726-2-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531193237.216726-1-felipe.contreras@gmail.com","subject":"[PATCH v3 1/7] push: rename !triangular to same_remote","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:32:31Z","receivedAt":"2021-05-31T19:32:52Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"The typical case is what git was designed for: distributed remotes.\n\nIt's only the atypical case--fetching and pushing to the same\nremote--that we need to keep an eye on.\n\nNo functional changes.\n\nLiked-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 16 ++++++++--------\n 1 file changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 194967ed79..06406353ce 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -186,7 +186,7 @@ static const char message_detached_head_die[] =\n \t   \"    git push %s HEAD:<name-of-remote-branch>\\n\");\n \n static void setup_push_upstream(struct remote *remote, struct branch *branch,\n-\t\t\t\tint triangular, int simple)\n+\t\t\t\tint same_remote, int simple)\n {\n \tif (!branch)\n \t\tdie(_(message_detached_head_die), remote->name);\n@@ -201,7 +201,7 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,\n \tif (branch->merge_nr != 1)\n \t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n \t\t    \"refusing to push.\"), branch->name);\n-\tif (triangular)\n+\tif (!same_remote)\n \t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n \t\t      \"your current branch '%s', without telling me what to push\\n\"\n \t\t      \"to update which remote branch.\"),\n@@ -223,16 +223,16 @@ static void setup_push_current(struct remote *remote, struct branch *branch)\n \trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n }\n \n-static int is_workflow_triangular(struct remote *remote)\n+static int is_same_remote(struct remote *remote)\n {\n \tstruct remote *fetch_remote = remote_get(NULL);\n-\treturn (fetch_remote && fetch_remote != remote);\n+\treturn (!fetch_remote || fetch_remote == remote);\n }\n \n static void setup_default_push_refspecs(struct remote *remote)\n {\n \tstruct branch *branch = branch_get(NULL);\n-\tint triangular = is_workflow_triangular(remote);\n+\tint same_remote = is_same_remote(remote);\n \n \tswitch (push_default) {\n \tdefault:\n@@ -242,14 +242,14 @@ static void setup_default_push_refspecs(struct remote *remote)\n \n \tcase PUSH_DEFAULT_UNSPECIFIED:\n \tcase PUSH_DEFAULT_SIMPLE:\n-\t\tif (triangular)\n+\t\tif (!same_remote)\n \t\t\tsetup_push_current(remote, branch);\n \t\telse\n-\t\t\tsetup_push_upstream(remote, branch, triangular, 1);\n+\t\t\tsetup_push_upstream(remote, branch, same_remote, 1);\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_UPSTREAM:\n-\t\tsetup_push_upstream(remote, branch, triangular, 0);\n+\t\tsetup_push_upstream(remote, branch, same_remote, 0);\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_CURRENT:\n-- \n2.32.0.rc0\n\n"},{"id":"426057","messageId":"20210531193237.216726-3-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531193237.216726-1-felipe.contreras@gmail.com","subject":"[PATCH v3 2/7] push: hedge code of default=simple","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:32:32Z","receivedAt":"2021-05-31T19:32:54Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"`simple` is the most important mode so move the relevant code to its own\nfunction to make it easier to see what it's doing.\n\nReviewed-by: Elijah Newren <newren@gmail.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 13 +++++++++----\n 1 file changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 06406353ce..48c38fe25a 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -223,6 +223,14 @@ static void setup_push_current(struct remote *remote, struct branch *branch)\n \trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n }\n \n+static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n+{\n+\tif (!same_remote)\n+\t\tsetup_push_current(remote, branch);\n+\telse\n+\t\tsetup_push_upstream(remote, branch, same_remote, 1);\n+}\n+\n static int is_same_remote(struct remote *remote)\n {\n \tstruct remote *fetch_remote = remote_get(NULL);\n@@ -242,10 +250,7 @@ static void setup_default_push_refspecs(struct remote *remote)\n \n \tcase PUSH_DEFAULT_UNSPECIFIED:\n \tcase PUSH_DEFAULT_SIMPLE:\n-\t\tif (!same_remote)\n-\t\t\tsetup_push_current(remote, branch);\n-\t\telse\n-\t\t\tsetup_push_upstream(remote, branch, same_remote, 1);\n+\t\tsetup_push_simple(remote, branch, same_remote);\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_UPSTREAM:\n-- \n2.32.0.rc0\n\n"},{"id":"426058","messageId":"20210531193237.216726-4-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531193237.216726-1-felipe.contreras@gmail.com","subject":"[PATCH v3 3/7] push: copy code to setup_push_simple()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:32:33Z","receivedAt":"2021-05-31T19:32:58Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"In order to avoid doing unnecessary things and simplify it in further\npatches. In particular moving the additional name safety out of\nsetup_push_upstream() and into setup_push_simple() and thus making both\nmore straightforward.\n\nThe code is copied exactly as-is; no functional changes.\n\nReviewed-by: Elijah Newren <newren@gmail.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 36 ++++++++++++++++++++++++++++++++----\n 1 file changed, 32 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 48c38fe25a..6a620a90e3 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -225,10 +225,38 @@ static void setup_push_current(struct remote *remote, struct branch *branch)\n \n static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n {\n-\tif (!same_remote)\n-\t\tsetup_push_current(remote, branch);\n-\telse\n-\t\tsetup_push_upstream(remote, branch, same_remote, 1);\n+\tif (!same_remote) {\n+\t\tif (!branch)\n+\t\t\tdie(_(message_detached_head_die), remote->name);\n+\t\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n+\t} else {\n+\t\tif (!branch)\n+\t\t\tdie(_(message_detached_head_die), remote->name);\n+\t\tif (!branch->merge_nr || !branch->merge || !branch->remote_name)\n+\t\t\tdie(_(\"The current branch %s has no upstream branch.\\n\"\n+\t\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n+\t\t\t    \"\\n\"\n+\t\t\t    \"    git push --set-upstream %s %s\\n\"),\n+\t\t\t    branch->name,\n+\t\t\t    remote->name,\n+\t\t\t    branch->name);\n+\t\tif (branch->merge_nr != 1)\n+\t\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n+\t\t\t    \"refusing to push.\"), branch->name);\n+\t\tif (!same_remote)\n+\t\t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n+\t\t\t      \"your current branch '%s', without telling me what to push\\n\"\n+\t\t\t      \"to update which remote branch.\"),\n+\t\t\t    remote->name, branch->name);\n+\n+\t\tif (1) {\n+\t\t\t/* Additional safety */\n+\t\t\tif (strcmp(branch->refname, branch->merge[0]->src))\n+\t\t\t\tdie_push_simple(branch, remote);\n+\t\t}\n+\n+\t\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->merge[0]->src);\n+\t}\n }\n \n static int is_same_remote(struct remote *remote)\n-- \n2.32.0.rc0\n\n"},{"id":"426059","messageId":"20210531193237.216726-5-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531193237.216726-1-felipe.contreras@gmail.com","subject":"[PATCH v3 4/7] push: reorganize setup_push_simple()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:32:34Z","receivedAt":"2021-05-31T19:33:01Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Simply move the code around and remove dead code. In particular the\n'!same_remote' conditional is a no-op since that part of the code is the\nsame_remote leg of the conditional beforehand.\n\nNo functional changes.\n\nSuggestions-by: Elijah Newren <newren@gmail.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 29 ++++++++++++-----------------\n 1 file changed, 12 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 6a620a90e3..972d8e1cfd 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -225,13 +225,14 @@ static void setup_push_current(struct remote *remote, struct branch *branch)\n \n static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n {\n+\tconst char *dst;\n+\n+\tif (!branch)\n+\t\tdie(_(message_detached_head_die), remote->name);\n+\n \tif (!same_remote) {\n-\t\tif (!branch)\n-\t\t\tdie(_(message_detached_head_die), remote->name);\n-\t\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n+\t\tdst = branch->refname;\n \t} else {\n-\t\tif (!branch)\n-\t\t\tdie(_(message_detached_head_die), remote->name);\n \t\tif (!branch->merge_nr || !branch->merge || !branch->remote_name)\n \t\t\tdie(_(\"The current branch %s has no upstream branch.\\n\"\n \t\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n@@ -243,20 +244,14 @@ static void setup_push_simple(struct remote *remote, struct branch *branch, int\n \t\tif (branch->merge_nr != 1)\n \t\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n \t\t\t    \"refusing to push.\"), branch->name);\n-\t\tif (!same_remote)\n-\t\t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n-\t\t\t      \"your current branch '%s', without telling me what to push\\n\"\n-\t\t\t      \"to update which remote branch.\"),\n-\t\t\t    remote->name, branch->name);\n-\n-\t\tif (1) {\n-\t\t\t/* Additional safety */\n-\t\t\tif (strcmp(branch->refname, branch->merge[0]->src))\n-\t\t\t\tdie_push_simple(branch, remote);\n-\t\t}\n \n-\t\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->merge[0]->src);\n+\t\t/* Additional safety */\n+\t\tif (strcmp(branch->refname, branch->merge[0]->src))\n+\t\t\tdie_push_simple(branch, remote);\n+\n+\t\tdst = branch->merge[0]->src;\n \t}\n+\trefspec_appendf(&rs, \"%s:%s\", branch->refname, dst);\n }\n \n static int is_same_remote(struct remote *remote)\n-- \n2.32.0.rc0\n\n"},{"id":"426060","messageId":"20210531193237.216726-6-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531193237.216726-1-felipe.contreras@gmail.com","subject":"[PATCH v3 5/7] push: simplify setup_push_simple()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:32:35Z","receivedAt":"2021-05-31T19:33:03Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"There's a safety check to make sure branch->refname isn't different\nfrom branch->merge[0]->src, otherwise we die().\n\nTherefore we always push to branch->refname.\n\nSuggestions-by: Elijah Newren <newren@gmail.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 10 ++--------\n 1 file changed, 2 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 972d8e1cfd..e37c751268 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -225,14 +225,10 @@ static void setup_push_current(struct remote *remote, struct branch *branch)\n \n static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n {\n-\tconst char *dst;\n-\n \tif (!branch)\n \t\tdie(_(message_detached_head_die), remote->name);\n \n-\tif (!same_remote) {\n-\t\tdst = branch->refname;\n-\t} else {\n+\tif (same_remote) {\n \t\tif (!branch->merge_nr || !branch->merge || !branch->remote_name)\n \t\t\tdie(_(\"The current branch %s has no upstream branch.\\n\"\n \t\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n@@ -248,10 +244,8 @@ static void setup_push_simple(struct remote *remote, struct branch *branch, int\n \t\t/* Additional safety */\n \t\tif (strcmp(branch->refname, branch->merge[0]->src))\n \t\t\tdie_push_simple(branch, remote);\n-\n-\t\tdst = branch->merge[0]->src;\n \t}\n-\trefspec_appendf(&rs, \"%s:%s\", branch->refname, dst);\n+\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n }\n \n static int is_same_remote(struct remote *remote)\n-- \n2.32.0.rc0\n\n"},{"id":"426061","messageId":"20210531193237.216726-8-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531193237.216726-1-felipe.contreras@gmail.com","subject":"[PATCH v3 7/7] doc: push: explain default=simple correctly","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:32:37Z","receivedAt":"2021-05-31T19:33:06Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Now that the code has been simplified and it's clear what it's\nactually doing, update the documentation to reflect that.\n\nNamely; the simple mode only barfs when working on a centralized\nworkflow, and there's no configured upstream branch with the same name.\n\nCc: Elijah Newren <newren@gmail.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n Documentation/config/push.txt | 13 ++++++-------\n 1 file changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/config/push.txt b/Documentation/config/push.txt\nindex f2667b2689..632033638c 100644\n--- a/Documentation/config/push.txt\n+++ b/Documentation/config/push.txt\n@@ -24,15 +24,14 @@ push.default::\n \n * `tracking` - This is a deprecated synonym for `upstream`.\n \n-* `simple` - in centralized workflow, work like `upstream` with an\n-  added safety to refuse to push if the upstream branch's name is\n-  different from the local one.\n+* `simple` - pushes the current branch with the same name on the remote.\n +\n-When pushing to a remote that is different from the remote you normally\n-pull from, work as `current`.  This is the safest option and is suited\n-for beginners.\n+If you are working on a centralized workflow (pushing to the same repository you\n+pull from, which is typically `origin`), then you need to configure an upstream\n+branch with the same name.\n +\n-This mode has become the default in Git 2.0.\n+This mode is the default since Git 2.0, and is the safest option suited for\n+beginners.\n \n * `matching` - push all branches having the same name on both ends.\n   This makes the repository you are pushing to remember the set of\n-- \n2.32.0.rc0\n\n"},{"id":"426062","messageId":"20210531193237.216726-7-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531193237.216726-1-felipe.contreras@gmail.com","subject":"[PATCH v3 6/7] push: remove unused code in setup_push_upstream()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:32:36Z","receivedAt":"2021-05-31T19:33:10Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Now it's not used for the simple mode.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 10 ++--------\n 1 file changed, 2 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex e37c751268..29fea70ff1 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -186,7 +186,7 @@ static const char message_detached_head_die[] =\n \t   \"    git push %s HEAD:<name-of-remote-branch>\\n\");\n \n static void setup_push_upstream(struct remote *remote, struct branch *branch,\n-\t\t\t\tint same_remote, int simple)\n+\t\t\t\tint same_remote)\n {\n \tif (!branch)\n \t\tdie(_(message_detached_head_die), remote->name);\n@@ -207,12 +207,6 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,\n \t\t      \"to update which remote branch.\"),\n \t\t    remote->name, branch->name);\n \n-\tif (simple) {\n-\t\t/* Additional safety */\n-\t\tif (strcmp(branch->refname, branch->merge[0]->src))\n-\t\t\tdie_push_simple(branch, remote);\n-\t}\n-\n \trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->merge[0]->src);\n }\n \n@@ -271,7 +265,7 @@ static void setup_default_push_refspecs(struct remote *remote)\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_UPSTREAM:\n-\t\tsetup_push_upstream(remote, branch, same_remote, 0);\n+\t\tsetup_push_upstream(remote, branch, same_remote);\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_CURRENT:\n-- \n2.32.0.rc0\n\n"},{"id":"426063","messageId":"20210531195124.218325-1-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531193237.216726-1-felipe.contreras@gmail.com","subject":"[PATCH v2 00/13] push: revamp push.default","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:11Z","receivedAt":"2021-05-31T19:51:31Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"This patch series is the new second part of [1] and it's mostly a ton of\ncleanups.\n\nIn theory there should be no functional changes.\n\nMost of the changes since v1 are due to the fact that\ns/!triangular/same_remote/ was done early in the previous series. Other\nthan that there's a few changes to the code and commit messages\nsuggested by Junio C Hamano.\n\nThe end result is almost identical to v1, only the way we get there\nchanges (plus there's an extra cosmetic break).\n\nThere's too many changes to list them all, it's much easier to see the\nend result:\n\nstatic const char *get_upstream_ref(struct branch *branch, const char *remote_name)\n{\n\tif (!branch->merge_nr || !branch->merge || !branch->remote_name)\n\t\tdie(_(\"The current branch %s has no upstream branch.\\n\"\n\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n\t\t    \"\\n\"\n\t\t    \"    git push --set-upstream %s %s\\n\"),\n\t\t    branch->name,\n\t\t    remote_name,\n\t\t    branch->name);\n\tif (branch->merge_nr != 1)\n\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n\t\t    \"refusing to push.\"), branch->name);\n\n\treturn branch->merge[0]->src;\n}\n\nstatic void setup_default_push_refspecs(struct remote *remote)\n{\n\tstruct branch *branch;\n\tconst char *dst;\n\tint same_remote;\n\n\tswitch (push_default) {\n\tcase PUSH_DEFAULT_MATCHING:\n\t\trefspec_append(&rs, \":\");\n\t\treturn;\n\n\tcase PUSH_DEFAULT_NOTHING:\n\t\tdie(_(\"You didn't specify any refspecs to push, and \"\n\t\t    \"push.default is \\\"nothing\\\".\"));\n\t\treturn;\n\tdefault:\n\t\tbreak;\n\t}\n\n\tbranch = branch_get(NULL);\n\tif (!branch)\n\t\tdie(_(message_detached_head_die), remote->name);\n\n\tdst = branch->refname;\n\tsame_remote = !strcmp(remote->name, remote_for_branch(branch, NULL));\n\n\tswitch (push_default) {\n\tdefault:\n\tcase PUSH_DEFAULT_UNSPECIFIED:\n\tcase PUSH_DEFAULT_SIMPLE:\n\t\tif (!same_remote)\n\t\t\tbreak;\n\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n\t\t\tdie_push_simple(branch, remote);\n\t\tbreak;\n\n\tcase PUSH_DEFAULT_UPSTREAM:\n\t\tif (!same_remote)\n\t\t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n\t\t\t      \"your current branch '%s', without telling me what to push\\n\"\n\t\t\t      \"to update which remote branch.\"),\n\t\t\t    remote->name, branch->name);\n\t\tdst = get_upstream_ref(branch, remote->name);\n\t\tbreak;\n\n\tcase PUSH_DEFAULT_CURRENT:\n\t\tbreak;\n\t}\n\n\trefspec_appendf(&rs, \"%s:%s\", branch->refname, dst);\n}\n\n[1] https://lore.kernel.org/git/20210531193237.216726-1-felipe.contreras@gmail.com\n\nFelipe Contreras (13):\n  push: create new get_upstream_ref() helper\n  push: return immediately in trivial switch case\n  push: split switch cases\n  push: factor out null branch check\n  push: only get the branch when needed\n  push: make setup_push_* return the dst\n  push: trivial simplifications\n  push: get rid of all the setup_push_* functions\n  push: factor out the typical case\n  push: remove redundant check\n  push: remove trivial function\n  push: only check same_remote when needed\n  push: don't get a full remote object\n\n builtin/push.c | 93 ++++++++++++++++++--------------------------------\n 1 file changed, 34 insertions(+), 59 deletions(-)\n\nRange-diff against v1:\n 1:  9d9d800b11 !  1:  675528cf7a push: create new get_upstream_ref() helper\n    @@ builtin/push.c: static const char message_detached_head_die[] =\n      \t   \"    git push %s HEAD:<name-of-remote-branch>\\n\");\n      \n     -static void setup_push_upstream(struct remote *remote, struct branch *branch,\n    --\t\t\t\tint triangular)\n    +-\t\t\t\tint same_remote)\n     +static const char *get_upstream_ref(struct branch *branch, const char *remote_name)\n      {\n     -\tif (!branch)\n    @@ builtin/push.c: static const char message_detached_head_die[] =\n     +}\n     +\n     +static void setup_push_upstream(struct remote *remote, struct branch *branch,\n    -+\t\t\t\tint triangular)\n    ++\t\t\t\tint same_remote)\n     +{\n     +\tconst char *upstream_ref;\n     +\tif (!branch)\n     +\t\tdie(_(message_detached_head_die), remote->name);\n     +\tupstream_ref = get_upstream_ref(branch, remote->name);\n    - \tif (triangular)\n    + \tif (!same_remote)\n      \t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n      \t\t      \"your current branch '%s', without telling me what to push\\n\"\n      \t\t      \"to update which remote branch.\"),\n    @@ builtin/push.c: static const char message_detached_head_die[] =\n     @@ builtin/push.c: static void setup_push_simple(struct remote *remote, struct branch *branch, int\n      \t\tdie(_(message_detached_head_die), remote->name);\n      \n    - \tif (!triangular) {\n    + \tif (same_remote) {\n     -\t\tif (!branch->merge_nr || !branch->merge || !branch->remote_name)\n     -\t\t\tdie(_(\"The current branch %s has no upstream branch.\\n\"\n     -\t\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n 2:  9d24821512 !  2:  dcbe8c53b5 push: return immediately in trivial switch case\n    @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n      \n      \tcase PUSH_DEFAULT_UNSPECIFIED:\n      \tcase PUSH_DEFAULT_SIMPLE:\n    - \t\tsetup_push_simple(remote, branch, triangular);\n    + \t\tsetup_push_simple(remote, branch, same_remote);\n     -\t\tbreak;\n     +\t\treturn;\n      \n      \tcase PUSH_DEFAULT_UPSTREAM:\n    - \t\tsetup_push_upstream(remote, branch, triangular);\n    + \t\tsetup_push_upstream(remote, branch, same_remote);\n     -\t\tbreak;\n     +\t\treturn;\n      \n 3:  160b8bee93 !  3:  55b227151f push: reorder switch cases\n    @@ Metadata\n     Author: Felipe Contreras <felipe.contreras@gmail.com>\n     \n      ## Commit message ##\n    -    push: reorder switch cases\n    +    push: split switch cases\n     \n         We want all the cases that don't do anything with a branch first, and\n    -    then the rest.\n    -\n    -    Will help further patches.\n    +    then the rest. That way we will be able to get the branch and die if\n    +    there's a problem in the parent function, instead of inside the function\n    +    of each mode.\n     \n         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n     \n      ## builtin/push.c ##\n     @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n    - \tint triangular = is_workflow_triangular(remote);\n    + \tint same_remote = is_same_remote(remote);\n      \n      \tswitch (push_default) {\n     -\tdefault:\n    @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n     +\t\t    \"push.default is \\\"nothing\\\".\"));\n     +\t\treturn;\n     +\tdefault:\n    ++\t\tbreak;\n     +\t}\n     +\n     +\tswitch (push_default) {\n     +\tdefault:\n      \tcase PUSH_DEFAULT_UNSPECIFIED:\n      \tcase PUSH_DEFAULT_SIMPLE:\n    - \t\tsetup_push_simple(remote, branch, triangular);\n    + \t\tsetup_push_simple(remote, branch, same_remote);\n     @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n      \tcase PUSH_DEFAULT_CURRENT:\n      \t\tsetup_push_current(remote, branch);\n 4:  2b299e2e5a !  4:  4ea0ee4631 push: factor out null branch check\n    @@ Commit message\n     \n      ## builtin/push.c ##\n     @@ builtin/push.c: static void setup_push_upstream(struct remote *remote, struct branch *branch,\n    - \t\t\t\tint triangular)\n    + \t\t\t\tint same_remote)\n      {\n      \tconst char *upstream_ref;\n     -\tif (!branch)\n     -\t\tdie(_(message_detached_head_die), remote->name);\n      \tupstream_ref = get_upstream_ref(branch, remote->name);\n    - \tif (triangular)\n    + \tif (!same_remote)\n      \t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n     @@ builtin/push.c: static void setup_push_upstream(struct remote *remote, struct branch *branch,\n      \n    @@ builtin/push.c: static void setup_push_upstream(struct remote *remote, struct br\n      \trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n      }\n      \n    - static void setup_push_simple(struct remote *remote, struct branch *branch, int triangular)\n    + static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n      {\n     -\tif (!branch)\n     -\t\tdie(_(message_detached_head_die), remote->name);\n     -\n    - \tif (!triangular) {\n    + \tif (same_remote) {\n      \t\tconst char *upstream_ref;\n      \n     @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n    - \tdefault:\n    + \t\tbreak;\n      \t}\n      \n     +\tif (!branch)\n 5:  4a721c99f1 !  5:  ae3d0dfdfe push: only get the branch when needed\n    @@ Commit message\n         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n     \n      ## builtin/push.c ##\n    -@@ builtin/push.c: static int is_workflow_triangular(struct remote *remote)\n    +@@ builtin/push.c: static int is_same_remote(struct remote *remote)\n      \n      static void setup_default_push_refspecs(struct remote *remote)\n      {\n     -\tstruct branch *branch = branch_get(NULL);\n     +\tstruct branch *branch;\n    - \tint triangular = is_workflow_triangular(remote);\n    + \tint same_remote = is_same_remote(remote);\n      \n      \tswitch (push_default) {\n     @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n    - \tdefault:\n    + \t\tbreak;\n      \t}\n      \n     +\tbranch = branch_get(NULL);\n 6:  30d5c43c28 !  6:  9d9a9ebfbe push: make setup_push_* return the dst\n    @@ Commit message\n         push: make setup_push_* return the dst\n     \n         All of the setup_push_* functions are appending a refspec. Do this only\n    -    once in the parent function.\n    +    once on the parent function.\n     \n         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n     \n    @@ builtin/push.c: static const char *get_upstream_ref(struct branch *branch, const\n      }\n      \n     -static void setup_push_upstream(struct remote *remote, struct branch *branch,\n    --\t\t\t\tint triangular)\n    +-\t\t\t\tint same_remote)\n     +static const char *setup_push_upstream(struct remote *remote, struct branch *branch,\n    -+\tint triangular)\n    ++\tint same_remote)\n      {\n      \tconst char *upstream_ref;\n      \tupstream_ref = get_upstream_ref(branch, remote->name);\n    @@ builtin/push.c: static void setup_push_upstream(struct remote *remote, struct br\n     +\treturn branch->refname;\n      }\n      \n    --static void setup_push_simple(struct remote *remote, struct branch *branch, int triangular)\n    -+static const char *setup_push_simple(struct remote *remote, struct branch *branch, int triangular)\n    +-static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n    ++static const char *setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n      {\n    - \tif (!triangular) {\n    + \tif (same_remote) {\n      \t\tconst char *upstream_ref;\n     @@ builtin/push.c: static void setup_push_simple(struct remote *remote, struct branch *branch, int\n      \t\tif (strcmp(branch->refname, upstream_ref))\n    @@ builtin/push.c: static void setup_push_simple(struct remote *remote, struct bran\n     +\treturn branch->refname;\n      }\n      \n    - static int is_workflow_triangular(struct remote *remote)\n    + static int is_same_remote(struct remote *remote)\n     @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n      {\n      \tstruct branch *branch;\n    - \tint triangular = is_workflow_triangular(remote);\n    + \tint same_remote = is_same_remote(remote);\n     +\tconst char *dst;\n      \n      \tswitch (push_default) {\n    @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n      \tdefault:\n      \tcase PUSH_DEFAULT_UNSPECIFIED:\n      \tcase PUSH_DEFAULT_SIMPLE:\n    --\t\tsetup_push_simple(remote, branch, triangular);\n    +-\t\tsetup_push_simple(remote, branch, same_remote);\n     -\t\treturn;\n    -+\t\tdst = setup_push_simple(remote, branch, triangular);\n    ++\t\tdst = setup_push_simple(remote, branch, same_remote);\n     +\t\tbreak;\n      \n      \tcase PUSH_DEFAULT_UPSTREAM:\n    --\t\tsetup_push_upstream(remote, branch, triangular);\n    +-\t\tsetup_push_upstream(remote, branch, same_remote);\n     -\t\treturn;\n    -+\t\tdst = setup_push_upstream(remote, branch, triangular);\n    ++\t\tdst = setup_push_upstream(remote, branch, same_remote);\n     +\t\tbreak;\n      \n      \tcase PUSH_DEFAULT_CURRENT:\n 7:  88cd2572a3 !  7:  f96581291a push: trivial simplifications\n    @@ Commit message\n      ## builtin/push.c ##\n     @@ builtin/push.c: static const char *get_upstream_ref(struct branch *branch, const char *remote_na\n      static const char *setup_push_upstream(struct remote *remote, struct branch *branch,\n    - \tint triangular)\n    + \tint same_remote)\n      {\n     -\tconst char *upstream_ref;\n     -\tupstream_ref = get_upstream_ref(branch, remote->name);\n    - \tif (triangular)\n    + \tif (!same_remote)\n      \t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n      \t\t      \"your current branch '%s', without telling me what to push\\n\"\n      \t\t      \"to update which remote branch.\"),\n    @@ builtin/push.c: static const char *get_upstream_ref(struct branch *branch, const\n      static const char *setup_push_current(struct remote *remote, struct branch *branch)\n     @@ builtin/push.c: static const char *setup_push_current(struct remote *remote, struct branch *bran\n      \n    - static const char *setup_push_simple(struct remote *remote, struct branch *branch, int triangular)\n    + static const char *setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n      {\n    --\tif (!triangular) {\n    +-\tif (same_remote) {\n     -\t\tconst char *upstream_ref;\n     -\n     -\t\tupstream_ref = get_upstream_ref(branch, remote->name);\n     -\n     -\t\t/* Additional safety */\n     -\t\tif (strcmp(branch->refname, upstream_ref))\n    -+\tif (!triangular)\n    ++\tif (same_remote)\n     +\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n      \t\t\tdie_push_simple(branch, remote);\n     -\t}\n 8:  e31eba87d8 !  8:  d0cedd5c81 push: get rid of all the setup_push_* functions\n    @@ builtin/push.c: static const char *get_upstream_ref(struct branch *branch, const\n      }\n      \n     -static const char *setup_push_upstream(struct remote *remote, struct branch *branch,\n    --\tint triangular)\n    +-\tint same_remote)\n     -{\n    --\tif (triangular)\n    +-\tif (!same_remote)\n     -\t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n     -\t\t      \"your current branch '%s', without telling me what to push\\n\"\n     -\t\t      \"to update which remote branch.\"),\n    @@ builtin/push.c: static const char *get_upstream_ref(struct branch *branch, const\n     -\treturn branch->refname;\n     -}\n     -\n    --static const char *setup_push_simple(struct remote *remote, struct branch *branch, int triangular)\n    +-static const char *setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n     -{\n    --\tif (!triangular)\n    +-\tif (same_remote)\n     -\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n     -\t\t\tdie_push_simple(branch, remote);\n     -\treturn branch->refname;\n     -}\n     -\n    - static int is_workflow_triangular(struct remote *remote)\n    + static int is_same_remote(struct remote *remote)\n      {\n      \tstruct remote *fetch_remote = remote_get(NULL);\n     @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n      \tdefault:\n      \tcase PUSH_DEFAULT_UNSPECIFIED:\n      \tcase PUSH_DEFAULT_SIMPLE:\n    --\t\tdst = setup_push_simple(remote, branch, triangular);\n    -+\t\tif (!triangular)\n    +-\t\tdst = setup_push_simple(remote, branch, same_remote);\n    ++\t\tif (same_remote)\n     +\t\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n     +\t\t\t\tdie_push_simple(branch, remote);\n     +\t\tdst = branch->refname;\n      \t\tbreak;\n      \n      \tcase PUSH_DEFAULT_UPSTREAM:\n    --\t\tdst = setup_push_upstream(remote, branch, triangular);\n    -+\t\tif (triangular)\n    +-\t\tdst = setup_push_upstream(remote, branch, same_remote);\n    ++\t\tif (!same_remote)\n     +\t\t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n     +\t\t\t      \"your current branch '%s', without telling me what to push\\n\"\n     +\t\t\t      \"to update which remote branch.\"),\n 9:  d5f60ad791 !  9:  47bbad5a47 push: factor out the typical case\n    @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n      \tdefault:\n      \tcase PUSH_DEFAULT_UNSPECIFIED:\n      \tcase PUSH_DEFAULT_SIMPLE:\n    --\t\tif (!triangular)\n    +-\t\tif (same_remote)\n     -\t\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n     -\t\t\t\tdie_push_simple(branch, remote);\n     -\t\tdst = branch->refname;\n    -+\t\tif (triangular)\n    ++\t\tif (!same_remote)\n     +\t\t\tbreak;\n     +\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n     +\t\t\tdie_push_simple(branch, remote);\n10:  e1945bb451 <  -:  ---------- push: remove redundant check\n11:  93f8b38364 <  -:  ---------- push: fix Yoda condition\n12:  cdf961d231 <  -:  ---------- push: remove trivial function\n -:  ---------- > 10:  6a8e30bf38 push: remove redundant check\n -:  ---------- > 11:  976d7b9f3a push: remove trivial function\n13:  e5e55c00e7 ! 12:  d9df139855 push: only get triangular when needed\n    @@ Metadata\n     Author: Felipe Contreras <felipe.contreras@gmail.com>\n     \n      ## Commit message ##\n    -    push: only get triangular when needed\n    +    push: only check same_remote when needed\n     \n         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n     \n    @@ builtin/push.c: static const char *get_upstream_ref(struct branch *branch, const\n      static void setup_default_push_refspecs(struct remote *remote)\n      {\n      \tstruct branch *branch;\n    --\tint triangular = remote != remote_get(NULL);\n    +-\tint same_remote = remote == remote_get(NULL);\n      \tconst char *dst;\n    -+\tint triangular;\n    ++\tint same_remote;\n      \n      \tswitch (push_default) {\n      \tcase PUSH_DEFAULT_MATCHING:\n    @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n      \t\tdie(_(message_detached_head_die), remote->name);\n      \n      \tdst = branch->refname;\n    -+\ttriangular = remote != remote_get(NULL);\n    ++\tsame_remote = remote == remote_get(NULL);\n      \n      \tswitch (push_default) {\n      \tdefault:\n14:  2fd84a4312 ! 13:  ffc52d649c push: don't get a full remote object\n    @@ Metadata\n      ## Commit message ##\n         push: don't get a full remote object\n     \n    -    All we need to know is that their names are different.\n    +    All we need to know is that their names are the same.\n    +\n    +    Additionally this might be easier to parse for some since\n    +    remote_for_branch is more descriptive than remote_get(NULL).\n     \n         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n     \n    @@ builtin/push.c: static void setup_default_push_refspecs(struct remote *remote)\n      \t\tdie(_(message_detached_head_die), remote->name);\n      \n      \tdst = branch->refname;\n    --\ttriangular = remote != remote_get(NULL);\n    -+\ttriangular = strcmp(remote->name, remote_for_branch(branch, NULL));\n    +-\tsame_remote = remote == remote_get(NULL);\n    ++\tsame_remote = !strcmp(remote->name, remote_for_branch(branch, NULL));\n      \n      \tswitch (push_default) {\n      \tdefault:\n15:  2a203239e4 <  -:  ---------- push: rename !triangular to same_remote\n-- \n2.32.0.rc0\n\n"},{"id":"426064","messageId":"20210531195124.218325-2-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 01/13] push: create new get_upstream_ref() helper","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:12Z","receivedAt":"2021-05-31T19:51:36Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"This code is duplicated among multiple functions.\n\nNo functional changes.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 36 ++++++++++++++++++------------------\n 1 file changed, 18 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 29fea70ff1..e3e792c69c 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -185,29 +185,37 @@ static const char message_detached_head_die[] =\n \t   \"\\n\"\n \t   \"    git push %s HEAD:<name-of-remote-branch>\\n\");\n \n-static void setup_push_upstream(struct remote *remote, struct branch *branch,\n-\t\t\t\tint same_remote)\n+static const char *get_upstream_ref(struct branch *branch, const char *remote_name)\n {\n-\tif (!branch)\n-\t\tdie(_(message_detached_head_die), remote->name);\n \tif (!branch->merge_nr || !branch->merge || !branch->remote_name)\n \t\tdie(_(\"The current branch %s has no upstream branch.\\n\"\n \t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n \t\t    \"\\n\"\n \t\t    \"    git push --set-upstream %s %s\\n\"),\n \t\t    branch->name,\n-\t\t    remote->name,\n+\t\t    remote_name,\n \t\t    branch->name);\n \tif (branch->merge_nr != 1)\n \t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n \t\t    \"refusing to push.\"), branch->name);\n+\n+\treturn branch->merge[0]->src;\n+}\n+\n+static void setup_push_upstream(struct remote *remote, struct branch *branch,\n+\t\t\t\tint same_remote)\n+{\n+\tconst char *upstream_ref;\n+\tif (!branch)\n+\t\tdie(_(message_detached_head_die), remote->name);\n+\tupstream_ref = get_upstream_ref(branch, remote->name);\n \tif (!same_remote)\n \t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n \t\t      \"your current branch '%s', without telling me what to push\\n\"\n \t\t      \"to update which remote branch.\"),\n \t\t    remote->name, branch->name);\n \n-\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->merge[0]->src);\n+\trefspec_appendf(&rs, \"%s:%s\", branch->refname, upstream_ref);\n }\n \n static void setup_push_current(struct remote *remote, struct branch *branch)\n@@ -223,20 +231,12 @@ static void setup_push_simple(struct remote *remote, struct branch *branch, int\n \t\tdie(_(message_detached_head_die), remote->name);\n \n \tif (same_remote) {\n-\t\tif (!branch->merge_nr || !branch->merge || !branch->remote_name)\n-\t\t\tdie(_(\"The current branch %s has no upstream branch.\\n\"\n-\t\t\t    \"To push the current branch and set the remote as upstream, use\\n\"\n-\t\t\t    \"\\n\"\n-\t\t\t    \"    git push --set-upstream %s %s\\n\"),\n-\t\t\t    branch->name,\n-\t\t\t    remote->name,\n-\t\t\t    branch->name);\n-\t\tif (branch->merge_nr != 1)\n-\t\t\tdie(_(\"The current branch %s has multiple upstream branches, \"\n-\t\t\t    \"refusing to push.\"), branch->name);\n+\t\tconst char *upstream_ref;\n+\n+\t\tupstream_ref = get_upstream_ref(branch, remote->name);\n \n \t\t/* Additional safety */\n-\t\tif (strcmp(branch->refname, branch->merge[0]->src))\n+\t\tif (strcmp(branch->refname, upstream_ref))\n \t\t\tdie_push_simple(branch, remote);\n \t}\n \trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n-- \n2.32.0.rc0\n\n"},{"id":"426065","messageId":"20210531195124.218325-3-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 02/13] push: return immediately in trivial switch case","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:13Z","receivedAt":"2021-05-31T19:51:50Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"There's no need to break when nothing else will be executed.\n\nWill help next patches.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex e3e792c69c..0aa1d0f07d 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -257,25 +257,25 @@ static void setup_default_push_refspecs(struct remote *remote)\n \tdefault:\n \tcase PUSH_DEFAULT_MATCHING:\n \t\trefspec_append(&rs, \":\");\n-\t\tbreak;\n+\t\treturn;\n \n \tcase PUSH_DEFAULT_UNSPECIFIED:\n \tcase PUSH_DEFAULT_SIMPLE:\n \t\tsetup_push_simple(remote, branch, same_remote);\n-\t\tbreak;\n+\t\treturn;\n \n \tcase PUSH_DEFAULT_UPSTREAM:\n \t\tsetup_push_upstream(remote, branch, same_remote);\n-\t\tbreak;\n+\t\treturn;\n \n \tcase PUSH_DEFAULT_CURRENT:\n \t\tsetup_push_current(remote, branch);\n-\t\tbreak;\n+\t\treturn;\n \n \tcase PUSH_DEFAULT_NOTHING:\n \t\tdie(_(\"You didn't specify any refspecs to push, and \"\n \t\t    \"push.default is \\\"nothing\\\".\"));\n-\t\tbreak;\n+\t\treturn;\n \t}\n }\n \n-- \n2.32.0.rc0\n\n"},{"id":"426066","messageId":"20210531195124.218325-4-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 03/13] push: split switch cases","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:14Z","receivedAt":"2021-05-31T19:51:53Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We want all the cases that don't do anything with a branch first, and\nthen the rest. That way we will be able to get the branch and die if\nthere's a problem in the parent function, instead of inside the function\nof each mode.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 16 ++++++++++------\n 1 file changed, 10 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 0aa1d0f07d..f64b7100f0 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -254,11 +254,20 @@ static void setup_default_push_refspecs(struct remote *remote)\n \tint same_remote = is_same_remote(remote);\n \n \tswitch (push_default) {\n-\tdefault:\n \tcase PUSH_DEFAULT_MATCHING:\n \t\trefspec_append(&rs, \":\");\n \t\treturn;\n \n+\tcase PUSH_DEFAULT_NOTHING:\n+\t\tdie(_(\"You didn't specify any refspecs to push, and \"\n+\t\t    \"push.default is \\\"nothing\\\".\"));\n+\t\treturn;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\tswitch (push_default) {\n+\tdefault:\n \tcase PUSH_DEFAULT_UNSPECIFIED:\n \tcase PUSH_DEFAULT_SIMPLE:\n \t\tsetup_push_simple(remote, branch, same_remote);\n@@ -271,11 +280,6 @@ static void setup_default_push_refspecs(struct remote *remote)\n \tcase PUSH_DEFAULT_CURRENT:\n \t\tsetup_push_current(remote, branch);\n \t\treturn;\n-\n-\tcase PUSH_DEFAULT_NOTHING:\n-\t\tdie(_(\"You didn't specify any refspecs to push, and \"\n-\t\t    \"push.default is \\\"nothing\\\".\"));\n-\t\treturn;\n \t}\n }\n \n-- \n2.32.0.rc0\n\n"},{"id":"426067","messageId":"20210531195124.218325-5-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 04/13] push: factor out null branch check","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:15Z","receivedAt":"2021-05-31T19:51:55Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"No need to do it in every single function.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 10 +++-------\n 1 file changed, 3 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex f64b7100f0..8fcbd2878d 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -206,8 +206,6 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,\n \t\t\t\tint same_remote)\n {\n \tconst char *upstream_ref;\n-\tif (!branch)\n-\t\tdie(_(message_detached_head_die), remote->name);\n \tupstream_ref = get_upstream_ref(branch, remote->name);\n \tif (!same_remote)\n \t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n@@ -220,16 +218,11 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,\n \n static void setup_push_current(struct remote *remote, struct branch *branch)\n {\n-\tif (!branch)\n-\t\tdie(_(message_detached_head_die), remote->name);\n \trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n }\n \n static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n {\n-\tif (!branch)\n-\t\tdie(_(message_detached_head_die), remote->name);\n-\n \tif (same_remote) {\n \t\tconst char *upstream_ref;\n \n@@ -266,6 +259,9 @@ static void setup_default_push_refspecs(struct remote *remote)\n \t\tbreak;\n \t}\n \n+\tif (!branch)\n+\t\tdie(_(message_detached_head_die), remote->name);\n+\n \tswitch (push_default) {\n \tdefault:\n \tcase PUSH_DEFAULT_UNSPECIFIED:\n-- \n2.32.0.rc0\n\n"},{"id":"426068","messageId":"20210531195124.218325-6-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 05/13] push: only get the branch when needed","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:16Z","receivedAt":"2021-05-31T19:51:58Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 8fcbd2878d..d9f9d20f39 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -243,7 +243,7 @@ static int is_same_remote(struct remote *remote)\n \n static void setup_default_push_refspecs(struct remote *remote)\n {\n-\tstruct branch *branch = branch_get(NULL);\n+\tstruct branch *branch;\n \tint same_remote = is_same_remote(remote);\n \n \tswitch (push_default) {\n@@ -259,6 +259,7 @@ static void setup_default_push_refspecs(struct remote *remote)\n \t\tbreak;\n \t}\n \n+\tbranch = branch_get(NULL);\n \tif (!branch)\n \t\tdie(_(message_detached_head_die), remote->name);\n \n-- \n2.32.0.rc0\n\n"},{"id":"426069","messageId":"20210531195124.218325-9-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 08/13] push: get rid of all the setup_push_* functions","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:19Z","receivedAt":"2021-05-31T19:51:59Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Their code is much simpler now and can move into the parent function.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 38 +++++++++++---------------------------\n 1 file changed, 11 insertions(+), 27 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 43c039a2e3..da406fc890 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -202,30 +202,6 @@ static const char *get_upstream_ref(struct branch *branch, const char *remote_na\n \treturn branch->merge[0]->src;\n }\n \n-static const char *setup_push_upstream(struct remote *remote, struct branch *branch,\n-\tint same_remote)\n-{\n-\tif (!same_remote)\n-\t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n-\t\t      \"your current branch '%s', without telling me what to push\\n\"\n-\t\t      \"to update which remote branch.\"),\n-\t\t    remote->name, branch->name);\n-\treturn get_upstream_ref(branch, remote->name);\n-}\n-\n-static const char *setup_push_current(struct remote *remote, struct branch *branch)\n-{\n-\treturn branch->refname;\n-}\n-\n-static const char *setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n-{\n-\tif (same_remote)\n-\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n-\t\t\tdie_push_simple(branch, remote);\n-\treturn branch->refname;\n-}\n-\n static int is_same_remote(struct remote *remote)\n {\n \tstruct remote *fetch_remote = remote_get(NULL);\n@@ -259,15 +235,23 @@ static void setup_default_push_refspecs(struct remote *remote)\n \tdefault:\n \tcase PUSH_DEFAULT_UNSPECIFIED:\n \tcase PUSH_DEFAULT_SIMPLE:\n-\t\tdst = setup_push_simple(remote, branch, same_remote);\n+\t\tif (same_remote)\n+\t\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n+\t\t\t\tdie_push_simple(branch, remote);\n+\t\tdst = branch->refname;\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_UPSTREAM:\n-\t\tdst = setup_push_upstream(remote, branch, same_remote);\n+\t\tif (!same_remote)\n+\t\t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n+\t\t\t      \"your current branch '%s', without telling me what to push\\n\"\n+\t\t\t      \"to update which remote branch.\"),\n+\t\t\t    remote->name, branch->name);\n+\t\tdst = get_upstream_ref(branch, remote->name);\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_CURRENT:\n-\t\tdst = setup_push_current(remote, branch);\n+\t\tdst = branch->refname;\n \t\tbreak;\n \t}\n \n-- \n2.32.0.rc0\n\n"},{"id":"426070","messageId":"20210531195124.218325-8-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 07/13] push: trivial simplifications","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:18Z","receivedAt":"2021-05-31T19:52:02Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 14 +++-----------\n 1 file changed, 3 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 933b1cc6c0..43c039a2e3 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -205,14 +205,12 @@ static const char *get_upstream_ref(struct branch *branch, const char *remote_na\n static const char *setup_push_upstream(struct remote *remote, struct branch *branch,\n \tint same_remote)\n {\n-\tconst char *upstream_ref;\n-\tupstream_ref = get_upstream_ref(branch, remote->name);\n \tif (!same_remote)\n \t\tdie(_(\"You are pushing to remote '%s', which is not the upstream of\\n\"\n \t\t      \"your current branch '%s', without telling me what to push\\n\"\n \t\t      \"to update which remote branch.\"),\n \t\t    remote->name, branch->name);\n-\treturn upstream_ref;\n+\treturn get_upstream_ref(branch, remote->name);\n }\n \n static const char *setup_push_current(struct remote *remote, struct branch *branch)\n@@ -222,15 +220,9 @@ static const char *setup_push_current(struct remote *remote, struct branch *bran\n \n static const char *setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n {\n-\tif (same_remote) {\n-\t\tconst char *upstream_ref;\n-\n-\t\tupstream_ref = get_upstream_ref(branch, remote->name);\n-\n-\t\t/* Additional safety */\n-\t\tif (strcmp(branch->refname, upstream_ref))\n+\tif (same_remote)\n+\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n \t\t\tdie_push_simple(branch, remote);\n-\t}\n \treturn branch->refname;\n }\n \n-- \n2.32.0.rc0\n\n"},{"id":"426071","messageId":"20210531195124.218325-10-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 09/13] push: factor out the typical case","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:20Z","receivedAt":"2021-05-31T19:52:06Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Only override dst on the odd case.\n\nThis allows a preemptive break on the `simple` case.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 11 ++++++-----\n 1 file changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex da406fc890..b5e951bf59 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -231,14 +231,16 @@ static void setup_default_push_refspecs(struct remote *remote)\n \tif (!branch)\n \t\tdie(_(message_detached_head_die), remote->name);\n \n+\tdst = branch->refname;\n+\n \tswitch (push_default) {\n \tdefault:\n \tcase PUSH_DEFAULT_UNSPECIFIED:\n \tcase PUSH_DEFAULT_SIMPLE:\n-\t\tif (same_remote)\n-\t\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n-\t\t\t\tdie_push_simple(branch, remote);\n-\t\tdst = branch->refname;\n+\t\tif (!same_remote)\n+\t\t\tbreak;\n+\t\tif (strcmp(branch->refname, get_upstream_ref(branch, remote->name)))\n+\t\t\tdie_push_simple(branch, remote);\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_UPSTREAM:\n@@ -251,7 +253,6 @@ static void setup_default_push_refspecs(struct remote *remote)\n \t\tbreak;\n \n \tcase PUSH_DEFAULT_CURRENT:\n-\t\tdst = branch->refname;\n \t\tbreak;\n \t}\n \n-- \n2.32.0.rc0\n\n"},{"id":"426072","messageId":"20210531195124.218325-13-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 12/13] push: only check same_remote when needed","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:23Z","receivedAt":"2021-05-31T19:52:08Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex a873f8da92..f3916c66d1 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -205,8 +205,8 @@ static const char *get_upstream_ref(struct branch *branch, const char *remote_na\n static void setup_default_push_refspecs(struct remote *remote)\n {\n \tstruct branch *branch;\n-\tint same_remote = remote == remote_get(NULL);\n \tconst char *dst;\n+\tint same_remote;\n \n \tswitch (push_default) {\n \tcase PUSH_DEFAULT_MATCHING:\n@@ -226,6 +226,7 @@ static void setup_default_push_refspecs(struct remote *remote)\n \t\tdie(_(message_detached_head_die), remote->name);\n \n \tdst = branch->refname;\n+\tsame_remote = remote == remote_get(NULL);\n \n \tswitch (push_default) {\n \tdefault:\n-- \n2.32.0.rc0\n\n"},{"id":"426073","messageId":"20210531195124.218325-12-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 11/13] push: remove trivial function","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:22Z","receivedAt":"2021-05-31T19:52:11Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It's a single line that is used in a single place, and the variable has\nthe same name as the function.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 7 +------\n 1 file changed, 1 insertion(+), 6 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex aa22d6a8e5..a873f8da92 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -202,15 +202,10 @@ static const char *get_upstream_ref(struct branch *branch, const char *remote_na\n \treturn branch->merge[0]->src;\n }\n \n-static int is_same_remote(struct remote *remote)\n-{\n-\treturn remote == remote_get(NULL);\n-}\n-\n static void setup_default_push_refspecs(struct remote *remote)\n {\n \tstruct branch *branch;\n-\tint same_remote = is_same_remote(remote);\n+\tint same_remote = remote == remote_get(NULL);\n \tconst char *dst;\n \n \tswitch (push_default) {\n-- \n2.32.0.rc0\n\n"},{"id":"426074","messageId":"20210531195124.218325-7-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 06/13] push: make setup_push_* return the dst","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:17Z","receivedAt":"2021-05-31T19:52:15Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"All of the setup_push_* functions are appending a refspec. Do this only\nonce on the parent function.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 30 ++++++++++++++++--------------\n 1 file changed, 16 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex d9f9d20f39..933b1cc6c0 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -202,8 +202,8 @@ static const char *get_upstream_ref(struct branch *branch, const char *remote_na\n \treturn branch->merge[0]->src;\n }\n \n-static void setup_push_upstream(struct remote *remote, struct branch *branch,\n-\t\t\t\tint same_remote)\n+static const char *setup_push_upstream(struct remote *remote, struct branch *branch,\n+\tint same_remote)\n {\n \tconst char *upstream_ref;\n \tupstream_ref = get_upstream_ref(branch, remote->name);\n@@ -212,16 +212,15 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,\n \t\t      \"your current branch '%s', without telling me what to push\\n\"\n \t\t      \"to update which remote branch.\"),\n \t\t    remote->name, branch->name);\n-\n-\trefspec_appendf(&rs, \"%s:%s\", branch->refname, upstream_ref);\n+\treturn upstream_ref;\n }\n \n-static void setup_push_current(struct remote *remote, struct branch *branch)\n+static const char *setup_push_current(struct remote *remote, struct branch *branch)\n {\n-\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n+\treturn branch->refname;\n }\n \n-static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n+static const char *setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)\n {\n \tif (same_remote) {\n \t\tconst char *upstream_ref;\n@@ -232,7 +231,7 @@ static void setup_push_simple(struct remote *remote, struct branch *branch, int\n \t\tif (strcmp(branch->refname, upstream_ref))\n \t\t\tdie_push_simple(branch, remote);\n \t}\n-\trefspec_appendf(&rs, \"%s:%s\", branch->refname, branch->refname);\n+\treturn branch->refname;\n }\n \n static int is_same_remote(struct remote *remote)\n@@ -245,6 +244,7 @@ static void setup_default_push_refspecs(struct remote *remote)\n {\n \tstruct branch *branch;\n \tint same_remote = is_same_remote(remote);\n+\tconst char *dst;\n \n \tswitch (push_default) {\n \tcase PUSH_DEFAULT_MATCHING:\n@@ -267,17 +267,19 @@ static void setup_default_push_refspecs(struct remote *remote)\n \tdefault:\n \tcase PUSH_DEFAULT_UNSPECIFIED:\n \tcase PUSH_DEFAULT_SIMPLE:\n-\t\tsetup_push_simple(remote, branch, same_remote);\n-\t\treturn;\n+\t\tdst = setup_push_simple(remote, branch, same_remote);\n+\t\tbreak;\n \n \tcase PUSH_DEFAULT_UPSTREAM:\n-\t\tsetup_push_upstream(remote, branch, same_remote);\n-\t\treturn;\n+\t\tdst = setup_push_upstream(remote, branch, same_remote);\n+\t\tbreak;\n \n \tcase PUSH_DEFAULT_CURRENT:\n-\t\tsetup_push_current(remote, branch);\n-\t\treturn;\n+\t\tdst = setup_push_current(remote, branch);\n+\t\tbreak;\n \t}\n+\n+\trefspec_appendf(&rs, \"%s:%s\", branch->refname, dst);\n }\n \n static const char message_advice_pull_before_push[] =\n-- \n2.32.0.rc0\n\n"},{"id":"426075","messageId":"20210531195124.218325-14-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 13/13] push: don't get a full remote object","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:24Z","receivedAt":"2021-05-31T19:52:17Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"All we need to know is that their names are the same.\n\nAdditionally this might be easier to parse for some since\nremote_for_branch is more descriptive than remote_get(NULL).\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex f3916c66d1..e8b10a9b7e 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -226,7 +226,7 @@ static void setup_default_push_refspecs(struct remote *remote)\n \t\tdie(_(message_detached_head_die), remote->name);\n \n \tdst = branch->refname;\n-\tsame_remote = remote == remote_get(NULL);\n+\tsame_remote = !strcmp(remote->name, remote_for_branch(branch, NULL));\n \n \tswitch (push_default) {\n \tdefault:\n-- \n2.32.0.rc0\n\n"},{"id":"426076","messageId":"20210531195124.218325-11-felipe.contreras@gmail.com","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"[PATCH v2 10/13] push: remove redundant check","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-31T19:51:21Z","receivedAt":"2021-05-31T19:52:21Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"If fetch_remote is NULL (i.e. the branch remote is invalid), then it\ncan't possibly be same as remote, which can't be NULL.\n\nThe check is redundant, and so is the extra variable.\n\nAlso, fix the Yoda condition: we want to check if remote is the same as\nthe branch remote, not the other way around.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/push.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex b5e951bf59..aa22d6a8e5 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -204,8 +204,7 @@ static const char *get_upstream_ref(struct branch *branch, const char *remote_na\n \n static int is_same_remote(struct remote *remote)\n {\n-\tstruct remote *fetch_remote = remote_get(NULL);\n-\treturn (!fetch_remote || fetch_remote == remote);\n+\treturn remote == remote_get(NULL);\n }\n \n static void setup_default_push_refspecs(struct remote *remote)\n-- \n2.32.0.rc0\n\n"},{"id":"426185","messageId":"xmqqr1hlqd5v.fsf@gitster.g","threadId":"55811","inReplyTo":"20210531195124.218325-1-felipe.contreras@gmail.com","subject":"Re: [PATCH v2 00/13] push: revamp push.default","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-02T01:16:12Z","receivedAt":"2021-06-02T01:16:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> The end result is almost identical to v1, only the way we get there\n> changes (plus there's an extra cosmetic break).\n\nGood.  The endpoint matches exactly to what was queued, with the\nSQUASH??? fix for the \"break\" thing, which is necessary to make\n\"make sparse\" happy (so it is not just \"cosmetic\").\n\nIOW, this series allows us to drop the following.\n\ncommit c1964311c404afaadffd57d14d769a4051281c2b\nAuthor: Junio C Hamano <gitster@pobox.com>\nDate:   Mon May 31 12:41:06 2021 +0900\n\n    SQUASH??? fix compilation breakage\n    \n    make sparse found these:\n    \n    builtin/push.c:221:9: error: Expected ; at end of statement\n    builtin/push.c:221:9: error: got }\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex f1ac531252..e8b10a9b7e 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -218,6 +218,7 @@ static void setup_default_push_refspecs(struct remote *remote)\n \t\t    \"push.default is \\\"nothing\\\".\"));\n \t\treturn;\n \tdefault:\n+\t\tbreak;\n \t}\n \n \tbranch = branch_get(NULL);\n"},{"id":"426193","messageId":"60b7036e8eaf1_511920821@natae.notmuch","threadId":"55811","inReplyTo":"xmqqr1hlqd5v.fsf@gitster.g","subject":"Re: [PATCH v2 00/13] push: revamp push.default","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-06-02T04:05:02Z","receivedAt":"2021-06-02T04:05:07Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Junio C Hamano wrote:\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n> \n> > The end result is almost identical to v1, only the way we get there\n> > changes (plus there's an extra cosmetic break).\n> \n> Good.  The endpoint matches exactly to what was queued, with the\n> SQUASH??? fix for the \"break\" thing, which is necessary to make\n> \"make sparse\" happy (so it is not just \"cosmetic\").\n> \n> IOW, this series allows us to drop the following.\n\nIndeed.\n\n> commit c1964311c404afaadffd57d14d769a4051281c2b\n> Author: Junio C Hamano <gitster@pobox.com>\n> Date:   Mon May 31 12:41:06 2021 +0900\n> \n>     SQUASH??? fix compilation breakage\n>     \n>     make sparse found these:\n>     \n>     builtin/push.c:221:9: error: Expected ; at end of statement\n>     builtin/push.c:221:9: error: got }\n\nIs it really a \"compilation breakage\"?\n\nDocumentation/SubmittingPatches doesn't mention sparse. I do remember\nsetting up sparse when I worked with Linux in the past, but it's not\nprecisely a standard thing. At least in Arch Linux it's not even part of\nthe main packages [1].\n\nCheers.\n\n[1] https://aur.archlinux.org/packages/sparse/\n\n-- \nFelipe Contreras\n"}]}