{"thread":{"id":"49448","subject":"[PATCH] Improvement to only call Git Credential Helper once","startedAt":"2018-09-28T15:11:02Z","lastAt":"2018-09-28T15:51:05Z","messageCount":2,"participants":["Kyle Hubert"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"359205","messageId":"CAJoZ4U2G5rhZnOxsHjxByfYQvDCc-CJ=1-JjyrjW_B-CWForEA@mail.gmail.com","threadId":"49448","inReplyTo":null,"subject":"[PATCH] Improvement to only call Git Credential Helper once","fromName":"Kyle Hubert","fromEmail":"khubert@gmail.com","sentAt":"2018-09-28T15:10:49Z","receivedAt":"2018-09-28T15:11:02Z","isPatch":true,"sender":{"key":"khubert@gmail.com","avatar":"https://gravatar.com/avatar/84db3960dbec8e65d7b11a2708b965b25a242832a9f303604433aa066d742a90?d=mp&s=160"},"body":"When calling the Git Credential Helper that is set in the git config,\nthe get command can return a credential. Git immediately turns around\nand calls the store command, even though that credential was just\nretrieved by the Helper. This creates two side effects. First of all,\nif the Helper requires a passphrase, the user has to type it in\ntwice. Secondly, if the user has a number of helpers, this retrieves\nthe credential from one service and writes it to all services.\n\nThis commit introduces a new field in the credential struct that\ndetects when the credential was retrieved using the Helper, and early\nexits when called to store the credential.\n---\n credential.c | 8 +++++++-\n credential.h | 3 ++-\n 2 files changed, 9 insertions(+), 2 deletions(-)\n\ndiff --git a/credential.c b/credential.c\nindex 62be651b0..79bf62d49 100644\n--- a/credential.c\n+++ b/credential.c\n@@ -280,8 +280,10 @@ void credential_fill(struct credential *c)\n\n  for (i = 0; i < c->helpers.nr; i++) {\n  credential_do(c, c->helpers.items[i].string, \"get\");\n- if (c->username && c->password)\n+ if (c->username && c->password) {\n+ c->retrieved = 1;\n  return;\n+ }\n  if (c->quit)\n  die(\"credential helper '%s' told us to quit\",\n      c->helpers.items[i].string);\n@@ -300,6 +302,10 @@ void credential_approve(struct credential *c)\n  return;\n  if (!c->username || !c->password)\n  return;\n+ if (c->retrieved) {\n+ c->approved = 1;\n+ return;\n+ }\n\n  credential_apply_config(c);\n\ndiff --git a/credential.h b/credential.h\nindex 6b0cd16be..d99df2f52 100644\n--- a/credential.h\n+++ b/credential.h\n@@ -8,7 +8,8 @@ struct credential {\n  unsigned approved:1,\n  configured:1,\n  quit:1,\n- use_http_path:1;\n+ use_http_path:1,\n+ retrieved:1;\n\n  char *username;\n  char *password;\n"},{"id":"359208","messageId":"CAJoZ4U1cKjbgYq3=S--KbV8Yhce83z1WhTQJHTFyBTRRe2-DHg@mail.gmail.com","threadId":"49448","inReplyTo":"CAJoZ4U2G5rhZnOxsHjxByfYQvDCc-CJ=1-JjyrjW_B-CWForEA@mail.gmail.com","subject":"Re: [PATCH] Improvement to only call Git Credential Helper once","fromName":"Kyle Hubert","fromEmail":"khubert@gmail.com","sentAt":"2018-09-28T15:50:50Z","receivedAt":"2018-09-28T15:51:05Z","isPatch":true,"sender":{"key":"khubert@gmail.com","avatar":"https://gravatar.com/avatar/84db3960dbec8e65d7b11a2708b965b25a242832a9f303604433aa066d742a90?d=mp&s=160"},"body":"Sorry, this patch is damaged. I'm moving to `git send-email` now.\n\n-Kyle\n\nOn Fri, Sep 28, 2018 at 11:10 AM Kyle Hubert <khubert@gmail.com> wrote:\n>\n> When calling the Git Credential Helper that is set in the git config,\n> the get command can return a credential. Git immediately turns around\n> and calls the store command, even though that credential was just\n> retrieved by the Helper. This creates two side effects. First of all,\n> if the Helper requires a passphrase, the user has to type it in\n> twice. Secondly, if the user has a number of helpers, this retrieves\n> the credential from one service and writes it to all services.\n>\n> This commit introduces a new field in the credential struct that\n> detects when the credential was retrieved using the Helper, and early\n> exits when called to store the credential.\n> ---\n>  credential.c | 8 +++++++-\n>  credential.h | 3 ++-\n>  2 files changed, 9 insertions(+), 2 deletions(-)\n>\n> diff --git a/credential.c b/credential.c\n> index 62be651b0..79bf62d49 100644\n> --- a/credential.c\n> +++ b/credential.c\n> @@ -280,8 +280,10 @@ void credential_fill(struct credential *c)\n>\n>   for (i = 0; i < c->helpers.nr; i++) {\n>   credential_do(c, c->helpers.items[i].string, \"get\");\n> - if (c->username && c->password)\n> + if (c->username && c->password) {\n> + c->retrieved = 1;\n>   return;\n> + }\n>   if (c->quit)\n>   die(\"credential helper '%s' told us to quit\",\n>       c->helpers.items[i].string);\n> @@ -300,6 +302,10 @@ void credential_approve(struct credential *c)\n>   return;\n>   if (!c->username || !c->password)\n>   return;\n> + if (c->retrieved) {\n> + c->approved = 1;\n> + return;\n> + }\n>\n>   credential_apply_config(c);\n>\n> diff --git a/credential.h b/credential.h\n> index 6b0cd16be..d99df2f52 100644\n> --- a/credential.h\n> +++ b/credential.h\n> @@ -8,7 +8,8 @@ struct credential {\n>   unsigned approved:1,\n>   configured:1,\n>   quit:1,\n> - use_http_path:1;\n> + use_http_path:1,\n> + retrieved:1;\n>\n>   char *username;\n>   char *password;\n"}]}