From: konglu@minatec.inpg.fr Date: Mon, 11 Jun 2012 19:07:45 GMT Subject: Re: [PATCH v3] add 'git credential' plumbing command Message-ID: <20120611210745.Horde.72y3YnwdC4BP1kIBup3BWrA@webmail.minatec.grenoble-inp.fr> In-Reply-To: <1339440294-8010-1-git-send-email-Javier.Roucher-Iglesias@ensimag.imag.fr> Javier.Roucher-Iglesias@ensimag.imag.fr a écrit : > +Git-credential permits to the user of the script to save: > +username, password, host, path and protocol. When the user of script > +invoke git-credential, the script can ask for a password, using the command > +'git credential fill'. > +Taking data from the standard input, the program treats each line as a > +separate data item, and the end of series of data item is signalled by a > +blank line. > + > + username=admin\n > + protocol=[http|https]\n > + host=localhost\n > + path=/dir\n\n > + > +-If git-credential system has the password already stored > +git-credential will answer with by STDOUT: > + > + username=admin > + password=***** > + > +-If it is not stored, the user will be prompt for a password: > + > + > Password for '[http|https]admin@localhost': Whitespaces detected (and also some more after in the doc) > diff --git a/builtin/credential.c b/builtin/credential.c > new file mode 100644 > index 0000000..a6b6962 > --- /dev/null > +++ b/builtin/credential.c > @@ -0,0 +1,37 @@ > +#include > +#include "cache.h" > +#include "credential.h" > +#include "string-list.h" > + > +static const char usage_msg[] = > +"credential "; > + > +void cmd_credential (int argc, char **argv, const char *prefix) { > + const char *op; > + struct credential c = CREDENTIAL_INIT; > + int i; > + > + op = argv[1]; > + if (!op) > + usage(usage_msg); > + > + if (credential_read(&c, stdin) < 0) > + die("unable to read credential from stdin"); > + > + if (!strcmp(op, "fill")) { > + credential_fill(&c); > + if (c.username) > + printf("username=%s\n", c.username); > + if (c.password) > + printf("password=%s\n", c.password); > + } > + else if (!strcmp(op, "approve")) { > + credential_approve(&c); > + } > + else if (!strcmp(op, "reject")) { > + credential_reject(&c); > + } > + else { > + usage(usage_msg); > + } > +} Structure: if (!strcmp(op, "fill")) { credential_fill(&c); if (c.username) printf("username=%s\n", c.username); if (c.password) printf("password=%s\n", c.password); } else if (!strcmp(op, "approve")) { credential_approve(&c); } else if (!strcmp(op, "reject")) { credential_reject(&c); } else { usage(usage_msg); }