* [PATCH] upload-pack.c: use of parse-options API @ 2016-05-18 16:40 Antoine Queru 2016-05-18 18:08 ` Jeff King 2016-05-19 15:39 ` [PATCH v2] " Antoine Queru 0 siblings, 2 replies; 26+ messages in thread From: Antoine Queru @ 2016-05-18 16:40 UTC (permalink / raw) To: git Cc: william.duclot, simon.rabourg, francois.beutin, Matthieu.Moy, Antoine Queru, Antoine Queru, Matthieu Moy Option parsing now uses the parser API instead of a local parser. Code is now more compact. Signed-off-by: Antoine Queru <antoine.queru@grenoble-inp.fr> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> --- This is our first project as a warm up. It was taken from the GSoC microproject list. upload-pack.c | 51 ++++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index dc802a0..80f65eb 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -14,8 +14,12 @@ #include "sigchain.h" #include "version.h" #include "string-list.h" +#include "parse-options.h" -static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>"; +static const char * const upload_pack_usage[] = { + N_("git upload-pack [--strict] [--timeout=<n>] <dir>"), + NULL +}; /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) @@ -820,49 +824,26 @@ static int upload_pack_config(const char *var, const char *value, void *unused) int main(int argc, char **argv) { char *dir; - int i; int strict = 0; + struct option options[] = { + OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc, NULL), + OPT_HIDDEN_BOOL(0, "advertise-refs", &advertise_refs, NULL), + OPT_BOOL(0, "strict", &strict, NULL), + OPT_INTEGER(0, "timeout", &timeout, NULL), + OPT_END() + }; git_setup_gettext(); packet_trace_identity("upload-pack"); git_extract_argv0_path(argv[0]); check_replace_refs = 0; - - for (i = 1; i < argc; i++) { - char *arg = argv[i]; - - if (arg[0] != '-') - break; - if (!strcmp(arg, "--advertise-refs")) { - advertise_refs = 1; - continue; - } - if (!strcmp(arg, "--stateless-rpc")) { - stateless_rpc = 1; - continue; - } - if (!strcmp(arg, "--strict")) { - strict = 1; - continue; - } - if (starts_with(arg, "--timeout=")) { - timeout = atoi(arg+10); - daemon_mode = 1; - continue; - } - if (!strcmp(arg, "--")) { - i++; - break; - } - } - - if (i != argc-1) - usage(upload_pack_usage); - + argc = parse_options(argc, (const char **)argv, NULL, options, upload_pack_usage, 0); + if (timeout != 0) + daemon_mode = 1; setup_path(); - dir = argv[i]; + dir = argv[0]; if (!enter_repo(dir, strict)) die("'%s' does not appear to be a git repository", dir); -- 2.8.2.403.gaa9c3f6 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH] upload-pack.c: use of parse-options API 2016-05-18 16:40 [PATCH] upload-pack.c: use of parse-options API Antoine Queru @ 2016-05-18 18:08 ` Jeff King 2016-05-19 10:10 ` Antoine Queru 2016-05-19 15:39 ` [PATCH v2] " Antoine Queru 1 sibling, 1 reply; 26+ messages in thread From: Jeff King @ 2016-05-18 18:08 UTC (permalink / raw) To: Antoine Queru Cc: git, william.duclot, simon.rabourg, francois.beutin, Matthieu.Moy, Antoine Queru On Wed, May 18, 2016 at 06:40:19PM +0200, Antoine Queru wrote: > Option parsing now uses the parser API instead of a local parser. > Code is now more compact. Sounds like a good goal. > -static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>"; > +static const char * const upload_pack_usage[] = { > + N_("git upload-pack [--strict] [--timeout=<n>] <dir>"), > + NULL > +}; Do we need to enumerate the options here now? The usage message should list the options from "struct options", which make these redundant. Something like: git -upload-pack [options] <dir> probably makes more sense. Of course, it's hard to read the usage message because... > + struct option options[] = { > + OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc, NULL), > + OPT_HIDDEN_BOOL(0, "advertise-refs", &advertise_refs, NULL), > + OPT_BOOL(0, "strict", &strict, NULL), > + OPT_INTEGER(0, "timeout", &timeout, NULL), > + OPT_END() > + }; You've left the description text for each of these options as NULL, so running "git-upload-pack -h" segfaults. I'm not sure whether it is worth hiding the first two options. We typically hide "internal" options like this for user-facing programs, so as not to clutter the "-h" output. But upload-pack isn't a user-facing program. Anybody who is calling it directly with "-h" may be interested in even its more esoteric options. > - for (i = 1; i < argc; i++) { > - char *arg = argv[i]; > - > - if (arg[0] != '-') > - break; > - if (!strcmp(arg, "--advertise-refs")) { > - advertise_refs = 1; > - continue; > - } > - if (!strcmp(arg, "--stateless-rpc")) { > - stateless_rpc = 1; > - continue; > - } > - if (!strcmp(arg, "--strict")) { > - strict = 1; > - continue; > - } > - if (starts_with(arg, "--timeout=")) { > - timeout = atoi(arg+10); > - daemon_mode = 1; > - continue; > - } > - if (!strcmp(arg, "--")) { > - i++; > - break; > - } > - } A common pitfall in converting a for-loop to parse-options is when there is anything stateful in the parsing loop. But I don't see anything here. The trickiest thing is that --timeout implies daemon_mode. You've handled that below as: > + if (timeout != 0) > + daemon_mode = 1; I think that is OK. It would not be correct if, for example, some other code set "timeout" to a non-zero value (e.g., a config option), but I don't see that here. As a style nit, we usually spell comparison-with-zero as just: if (timeout) daemon_mode = 1; Looking at at daemon_mode, though, it appears that it cannot be set in any other way except here. And it does nothing except to disable progress in some cases. Weird. There may be some opportunities for refactoring or simplification there, but I that is outside the scope of your patch. > + argc = parse_options(argc, (const char **)argv, NULL, options, upload_pack_usage, 0); Perhaps this is a good opportunity to use "const" in the declaration of main(), as most other git programs do. Then you can drop this cast. > setup_path(); > > - dir = argv[i]; > + dir = argv[0]; > > if (!enter_repo(dir, strict)) > die("'%s' does not appear to be a git repository", dir); Prior to your patch, we used to check: - if (i != argc-1) - usage(upload_pack_usage); which ensured that "dir" was non-NULL. But with your patch, we may pass NULL to enter_repo. It fortunately catches this, but then we pass the NULL to die, which can segfault (though on glibc systems, stdio is kind enough to replace it with the "(null)"). Related, we silently accept extra arguments after your patch (whereas before we showed the usage message). You probably want to check "argc == 1", and otherwise show the usage message. -Peff ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] upload-pack.c: use of parse-options API 2016-05-18 18:08 ` Jeff King @ 2016-05-19 10:10 ` Antoine Queru 2016-05-19 11:57 ` Jeff King 0 siblings, 1 reply; 26+ messages in thread From: Antoine Queru @ 2016-05-19 10:10 UTC (permalink / raw) To: Jeff King Cc: git, william duclot, simon rabourg, francois beutin, Matthieu Moy, Antoine Queru Thanks for your input. > > -static const char upload_pack_usage[] = "git upload-pack [--strict] > > [--timeout=<n>] <dir>"; > > +static const char * const upload_pack_usage[] = { > > + N_("git upload-pack [--strict] [--timeout=<n>] <dir>"), > > + NULL > > +}; > > Do we need to enumerate the options here now? The usage message should > list the options from "struct options", which make these redundant. > > Something like: > > git -upload-pack [options] <dir> > > probably makes more sense. > Yes, you are right. > Of course, it's hard to read the usage message because... > > > + struct option options[] = { > > + OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc, NULL), > > + OPT_HIDDEN_BOOL(0, "advertise-refs", &advertise_refs, NULL), > > + OPT_BOOL(0, "strict", &strict, NULL), > > + OPT_INTEGER(0, "timeout", &timeout, NULL), > > + OPT_END() > > + }; > > You've left the description text for each of these options as NULL, so > running "git-upload-pack -h" segfaults. > > I'm not sure whether it is worth hiding the first two options. We > typically hide "internal" options like this for user-facing programs, so > as not to clutter the "-h" output. But upload-pack isn't a user-facing > program. Anybody who is calling it directly with "-h" may be interested > in even its more esoteric options. > In fact, to do this, I looked at builtin/receive-pack.c, where the parser API was already implemented, and these first two options were hidden. There were also no description for any options, so I thought it was not needed. Maybe we could update this file too ? > As a style nit, we usually spell comparison-with-zero as just: > > if (timeout) > daemon_mode = 1; Because timeout is an int, I personnally think it is more understable to treat it as it. But I'll update itfor consistency. > > + argc = parse_options(argc, (const char **)argv, NULL, options, > > upload_pack_usage, 0); > > Perhaps this is a good opportunity to use "const" in the declaration of > main(), as most other git programs do. Then you can drop this cast. > Ok. > > setup_path(); > > > > - dir = argv[i]; > > + dir = argv[0]; > > > > if (!enter_repo(dir, strict)) > > die("'%s' does not appear to be a git repository", dir); > > Prior to your patch, we used to check: > > - if (i != argc-1) > - usage(upload_pack_usage); > > which ensured that "dir" was non-NULL. But with your patch, we may pass > NULL to enter_repo. It fortunately catches this, but then we pass the > NULL to die, which can segfault (though on glibc systems, stdio is kind > enough to replace it with the "(null)"). > > Related, we silently accept extra arguments after your patch (whereas > before we showed the usage message). You probably want to check "argc == > 1", and otherwise show the usage message. Ok. -Antoine ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] upload-pack.c: use of parse-options API 2016-05-19 10:10 ` Antoine Queru @ 2016-05-19 11:57 ` Jeff King 2016-05-19 14:36 ` Matthieu Moy 0 siblings, 1 reply; 26+ messages in thread From: Jeff King @ 2016-05-19 11:57 UTC (permalink / raw) To: Antoine Queru Cc: git, william duclot, simon rabourg, francois beutin, Matthieu Moy, Antoine Queru On Thu, May 19, 2016 at 12:10:31PM +0200, Antoine Queru wrote: > > I'm not sure whether it is worth hiding the first two options. We > > typically hide "internal" options like this for user-facing programs, so > > as not to clutter the "-h" output. But upload-pack isn't a user-facing > > program. Anybody who is calling it directly with "-h" may be interested > > in even its more esoteric options. > > In fact, to do this, I looked at builtin/receive-pack.c, where the parser API > was already implemented, and these first two options were hidden. There were > also no description for any options, so I thought it was not needed. Maybe we > could update this file too ? Yeah, I don't think it's that bad to hide them, and perhaps consistency with receive-pack is better. AFAICT, descriptions for hidden options are pointless; they are never shown (in fact, it seems like OPT_HIDDEN_BOOL probably shouldn't even take such an option?). But the non-hidden options _do_ need non-NULL descriptions. -Peff ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] upload-pack.c: use of parse-options API 2016-05-19 11:57 ` Jeff King @ 2016-05-19 14:36 ` Matthieu Moy 0 siblings, 0 replies; 26+ messages in thread From: Matthieu Moy @ 2016-05-19 14:36 UTC (permalink / raw) To: Jeff King Cc: Antoine Queru, git, william duclot, simon rabourg, francois beutin, Antoine Queru Jeff King wrote: > On Thu, May 19, 2016 at 12:10:31PM +0200, Antoine Queru wrote: > > > > I'm not sure whether it is worth hiding the first two options. We > > > typically hide "internal" options like this for user-facing programs, so > > > as not to clutter the "-h" output. But upload-pack isn't a user-facing > > > program. Anybody who is calling it directly with "-h" may be interested > > > in even its more esoteric options. > > > > In fact, to do this, I looked at builtin/receive-pack.c, where the parser > > API > > was already implemented, and these first two options were hidden. There > > were > > also no description for any options, so I thought it was not needed. Maybe > > we > > could update this file too ? > > Yeah, I don't think it's that bad to hide them, and perhaps consistency > with receive-pack is better. IIRC, part of the reason receive-pack has hidden options is that it was a GSoC microproject, and writing an accurate description is much harder than what we expect from a microproject. IOW, I'm all for un-hiding these options, but that shouldn't be a requirement for a beginner's project. -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2] upload-pack.c: use of parse-options API 2016-05-18 16:40 [PATCH] upload-pack.c: use of parse-options API Antoine Queru 2016-05-18 18:08 ` Jeff King @ 2016-05-19 15:39 ` Antoine Queru 2016-05-19 16:10 ` Matthieu Moy 2016-05-23 13:02 ` [PATCH v3] " Antoine Queru 1 sibling, 2 replies; 26+ messages in thread From: Antoine Queru @ 2016-05-19 15:39 UTC (permalink / raw) To: git; +Cc: william.duclot, simon.rabourg, francois.beutin, Matthieu.Moy Option parsing now uses the parser API instead of a local parser. Code is now more compact. Description for -stateless-rpc and --advertise-refs come from the commit (gmane/131517) where there were implemented. Signed-off-by: Antoine Queru <antoine.queru@grenoble-inp.fr> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> --- diff v1 v2: Usage display "[options]" instead of "[--strict] [--timeout=<n>]". "argv" is now "const char **". "-stateless-rpc and --advertise-refs" are no more hidden. Description has been added for every option. Usage is displayed if there is not exactly one non option argument. If we agree on not having hidden option anymore, I will update the doc. upload-pack.c | 62 +++++++++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index dc802a0..a8617ac 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -14,8 +14,12 @@ #include "sigchain.h" #include "version.h" #include "string-list.h" +#include "parse-options.h" -static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>"; +static const char * const upload_pack_usage[] = { + N_("git upload-pack [options] <dir>"), + NULL +}; /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) @@ -817,11 +821,21 @@ static int upload_pack_config(const char *var, const char *value, void *unused) return parse_hide_refs_config(var, value, "uploadpack"); } -int main(int argc, char **argv) +int main(int argc, const char **argv) { - char *dir; - int i; + const char *dir; int strict = 0; + struct option options[] = { + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, + N_("may perform only a single read-write cycle with stdin and stdout")), + OPT_BOOL(0, "advertise-refs", &advertise_refs, + N_("only the initial ref advertisement is output, program exits immediately")), + OPT_BOOL(0, "strict", &strict, + N_("do not try <directory>/.git/ if <directory> is no Git directory")), + OPT_INTEGER(0, "timeout", &timeout, + N_("interrupt transfer after <n> seconds of inactivity")), + OPT_END() + }; git_setup_gettext(); @@ -829,41 +843,17 @@ int main(int argc, char **argv) git_extract_argv0_path(argv[0]); check_replace_refs = 0; - for (i = 1; i < argc; i++) { - char *arg = argv[i]; - - if (arg[0] != '-') - break; - if (!strcmp(arg, "--advertise-refs")) { - advertise_refs = 1; - continue; - } - if (!strcmp(arg, "--stateless-rpc")) { - stateless_rpc = 1; - continue; - } - if (!strcmp(arg, "--strict")) { - strict = 1; - continue; - } - if (starts_with(arg, "--timeout=")) { - timeout = atoi(arg+10); - daemon_mode = 1; - continue; - } - if (!strcmp(arg, "--")) { - i++; - break; - } - } - - if (i != argc-1) - usage(upload_pack_usage); + argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0); + + if (argc != 1) + usage_with_options(upload_pack_usage, options); - setup_path(); + if (timeout) + daemon_mode = 1; - dir = argv[i]; + setup_path(); + dir = argv[0]; if (!enter_repo(dir, strict)) die("'%s' does not appear to be a git repository", dir); -- 2.8.2.403.gf2352ca ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2] upload-pack.c: use of parse-options API 2016-05-19 15:39 ` [PATCH v2] " Antoine Queru @ 2016-05-19 16:10 ` Matthieu Moy 2016-05-19 16:46 ` Junio C Hamano 2016-05-19 16:58 ` Junio C Hamano 2016-05-23 13:02 ` [PATCH v3] " Antoine Queru 1 sibling, 2 replies; 26+ messages in thread From: Matthieu Moy @ 2016-05-19 16:10 UTC (permalink / raw) To: Antoine Queru Cc: git, william duclot, simon rabourg, francois beutin, Matthieu Moy Antoine.Queru@ensimag.grenoble-inp.fr wrote: > Option parsing now uses the parser API instead of a local parser. > Code is now more compact. > Description for -stateless-rpc and --advertise-refs > come from the commit (gmane/131517) Please, use a real commit id instead of a Gmane link. We don't know how long Gmane will remain up, but a self reference from Git's history to itself will always remain valid. The following alias is handy for this: [alias] whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short In your case it would allow writing: Description for --stateless-rpc and --advertise-refs is taken from commit 42526b4 (Add stateless RPC options to upload-pack, receive-pack, 2009-10-30). > diff v1 v2: We usually say "diff" to refer to an actual diff. I'd write "changes since v1" here. > + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, > + N_("may perform only a single read-write cycle with stdin and stdout")), It's weird to define what an option does with "may". It's a property of --stateless-rpc, but does not really define it. > + if (argc != 1) > + usage_with_options(upload_pack_usage, options); > > - setup_path(); > + if (timeout) > + daemon_mode = 1; > > - dir = argv[i]; > + setup_path(); > > + dir = argv[0]; Not a problem with your code, but the patch shows "setup_path()" as moved while it is not really. Maybe using "send-email --patience" or some other diff option could make the patch nicer. Not really important as it does not change the final state. -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] upload-pack.c: use of parse-options API 2016-05-19 16:10 ` Matthieu Moy @ 2016-05-19 16:46 ` Junio C Hamano 2016-05-20 6:55 ` Matthieu Moy 2016-05-19 16:58 ` Junio C Hamano 1 sibling, 1 reply; 26+ messages in thread From: Junio C Hamano @ 2016-05-19 16:46 UTC (permalink / raw) To: Matthieu Moy Cc: Antoine Queru, git, william duclot, simon rabourg, francois beutin Matthieu Moy <matthieu.moy@grenoble-inp.fr> writes: > Antoine.Queru@ensimag.grenoble-inp.fr wrote: >> Option parsing now uses the parser API instead of a local parser. >> Code is now more compact. >> Description for -stateless-rpc and --advertise-refs >> come from the commit (gmane/131517) > > Please, use a real commit id instead of a Gmane link. > > We don't know how long Gmane will remain up, but a self > reference from Git's history to itself will always remain valid. > > The following alias is handy for this: > > [alias] > whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short > > In your case it would allow writing: > > Description for --stateless-rpc and --advertise-refs is taken > from commit 42526b4 (Add stateless RPC options to upload-pack, > receive-pack, 2009-10-30). Good suggestion; a real question may be how you went from $gmane/131517 to 42526b4 (I vaguely recall that you have and publish a database of sort; this would be a good place to advertise it ;-). > >> diff v1 v2: > > We usually say "diff" to refer to an actual diff. I'd write "changes since v1" here. > >> + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, >> + N_("may perform only a single read-write cycle with stdin and stdout")), > > It's weird to define what an option does with "may". It's a > property of --stateless-rpc, but does not really define it. If this "may" were to express "The program might or might not do this, and we do not know what it would do until we try", then it indeed would be weird. But the way the word "may" was used in 42526b4 is "the program is ALLOWED to do only a single exchange". I agree that the phrasing is bad, in the sense that it can be misread as a non-definition; perhaps quit after a single request/response exchange or something? ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] upload-pack.c: use of parse-options API 2016-05-19 16:46 ` Junio C Hamano @ 2016-05-20 6:55 ` Matthieu Moy 0 siblings, 0 replies; 26+ messages in thread From: Matthieu Moy @ 2016-05-20 6:55 UTC (permalink / raw) To: Junio C Hamano Cc: Matthieu Moy, Antoine Queru, git, william duclot, simon rabourg, francois beutin Junio Hamano wrote: > Matthieu Moy <matthieu.moy@grenoble-inp.fr> writes: > > > Antoine.Queru@ensimag.grenoble-inp.fr wrote: > >> come from the commit (gmane/131517) > > > > Please, use a real commit id instead of a Gmane link. > > > > We don't know how long Gmane will remain up, but a self > > reference from Git's history to itself will always remain valid. > > > > The following alias is handy for this: > > > > [alias] > > whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short > > > > In your case it would allow writing: > > > > Description for --stateless-rpc and --advertise-refs is taken > > from commit 42526b4 (Add stateless RPC options to upload-pack, > > receive-pack, 2009-10-30). > > Good suggestion; a real question may be how you went from > $gmane/131517 to 42526b4 (I vaguely recall that you have and publish > a database of sort; this would be a good place to advertise it ;-). I don't (I think someone has, but I'm not this someone). I just "git log --grep"-ed the subject line in Git's history. > quit after a single request/response exchange Seems much clearer to me. -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] upload-pack.c: use of parse-options API 2016-05-19 16:10 ` Matthieu Moy 2016-05-19 16:46 ` Junio C Hamano @ 2016-05-19 16:58 ` Junio C Hamano 2016-05-20 6:53 ` Matthieu Moy 1 sibling, 1 reply; 26+ messages in thread From: Junio C Hamano @ 2016-05-19 16:58 UTC (permalink / raw) To: Matthieu Moy Cc: Antoine Queru, git, william duclot, simon rabourg, francois beutin Matthieu Moy <matthieu.moy@grenoble-inp.fr> writes: >> + if (argc != 1) >> + usage_with_options(upload_pack_usage, options); >> >> - setup_path(); >> + if (timeout) >> + daemon_mode = 1; >> >> - dir = argv[i]; >> + setup_path(); >> >> + dir = argv[0]; > > Not a problem with your code, but the patch shows "setup_path()" > as moved while it is not really. Maybe using "send-email > --patience" or some other diff option could make the patch nicer. Encouraging use of "send-email" with "--patience" is a losing approach if your goal is to present more reviewable diff, isn't it? Using "send-email" as if it is a front-end of "format-patch" means you lose the opportunity for the final proof-reading (not just finding typoes in the message, but the shape of diff, like you are pointing out). Using "format-patch --patience" or some other diff option, and pick the best one to give to "send-email" would indeed be a way to do so. > Not really important as it does not change the final state. I wondered if this is an example of real-world fallout from 0018da1^2~1 (xdiff: implement empty line chunk heuristic, 2016-04-19), but it does not seem to be so. What is happening is that Antoine's patch (which is slightly different from what you quoted above) has trailing whitespace after "setup_path();", so it indeed is the original setup_path(); is removed, a few lines were inserted, argv[i] reference is removed and then a totally different "setup_path(); " was added there. With that whitespace-breakage corrected, the resulting patch ends more like this: + if (argc != 1) + usage_with_options(upload_pack_usage, options); - if (i != argc-1) - usage(upload_pack_usage); + if (timeout) + daemon_mode = 1; setup_path(); - dir = argv[i]; - + dir = argv[0]; if (!enter_repo(dir, strict)) die("'%s' does not appear to be a git repository", dir); which is more reasonable. So in the end, this was not "Not a problem with your code" ;-) It was. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] upload-pack.c: use of parse-options API 2016-05-19 16:58 ` Junio C Hamano @ 2016-05-20 6:53 ` Matthieu Moy 2016-05-20 16:52 ` Junio C Hamano 0 siblings, 1 reply; 26+ messages in thread From: Matthieu Moy @ 2016-05-20 6:53 UTC (permalink / raw) To: Junio C Hamano Cc: Matthieu Moy, Antoine Queru, git, william duclot, simon rabourg, francois beutin Junio C Hamano wrote: > Encouraging use of "send-email" with "--patience" is a losing > approach if your goal is to present more reviewable diff, isn't it? > Using "send-email" as if it is a front-end of "format-patch" means > you lose the opportunity for the final proof-reading (not just > finding typoes in the message, but the shape of diff, like you are > pointing out). > > Using "format-patch --patience" or some other diff option, and pick > the best one to give to "send-email" would indeed be a way to do so. It's a matter of taste. My flow is "send-email-only", I do as much as possible in-tree, and when I notice something to do during "git send-email", I just abort and retry. So "Oops, looks ugly, I'll try with another option" is OK in this flow. > What is happening is that Antoine's patch (which is slightly > different from what you quoted above) has trailing whitespace after > "setup_path();" Nice catch! -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] upload-pack.c: use of parse-options API 2016-05-20 6:53 ` Matthieu Moy @ 2016-05-20 16:52 ` Junio C Hamano 0 siblings, 0 replies; 26+ messages in thread From: Junio C Hamano @ 2016-05-20 16:52 UTC (permalink / raw) To: Matthieu Moy Cc: Antoine Queru, git, william duclot, simon rabourg, francois beutin Matthieu Moy <matthieu.moy@grenoble-inp.fr> writes: >> Using "format-patch --patience" or some other diff option, and pick >> the best one to give to "send-email" would indeed be a way to do so. > > It's a matter of taste. My flow is "send-email-only", I do as much as > possible in-tree, and when I notice something to do during "git send-email", > I just abort and retry. So "Oops, looks ugly, I'll try with another > option" is OK in this flow. Ah, I didn't consider "final-review in send-email and aborting". I agree that it is just the matter of preference, if it is easy to review everything that you would be sending out, and decide to abort. I just thought that final review would be cumbersome in that flow. ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v3] upload-pack.c: use of parse-options API 2016-05-19 15:39 ` [PATCH v2] " Antoine Queru 2016-05-19 16:10 ` Matthieu Moy @ 2016-05-23 13:02 ` Antoine Queru 2016-05-23 18:03 ` Matthieu Moy 2016-05-27 14:16 ` [PATCH v4] " Antoine Queru 1 sibling, 2 replies; 26+ messages in thread From: Antoine Queru @ 2016-05-23 13:02 UTC (permalink / raw) To: git Cc: william.duclot, simon.rabourg, francois.beutin, Matthieu.Moy, gitster, peff Option parsing now uses the parser API instead of a local parser. Code is now more compact. Description for -stateless-rpc and --advertise-refs come from the commit 42526b4 (Add stateless RPC options to upload-pack, receive-pack, 2009-10-30). Signed-off-by: Antoine Queru <antoine.queru@grenoble-inp.fr> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> --- Change since v2: Commit message updated. WhiteSpace removed after the "setup_path();". Description for --stateless-rpc changed to : "quit after a single request/response exchange". For the description, i don't really understand what this option is doing, so i just copy pasted Junio's sentence. upload-pack.c | 59 +++++++++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index dc802a0..2d53c7b 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -14,8 +14,12 @@ #include "sigchain.h" #include "version.h" #include "string-list.h" +#include "parse-options.h" -static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>"; +static const char * const upload_pack_usage[] = { + N_("git upload-pack [options] <dir>"), + NULL +}; /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) @@ -817,11 +821,21 @@ static int upload_pack_config(const char *var, const char *value, void *unused) return parse_hide_refs_config(var, value, "uploadpack"); } -int main(int argc, char **argv) +int main(int argc, const char **argv) { - char *dir; - int i; + const char *dir; int strict = 0; + struct option options[] = { + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, + N_("quit after a single request/response exchange")), + OPT_BOOL(0, "advertise-refs", &advertise_refs, + N_("only the initial ref advertisement is output, program exits immediately")), + OPT_BOOL(0, "strict", &strict, + N_("do not try <directory>/.git/ if <directory> is no Git directory")), + OPT_INTEGER(0, "timeout", &timeout, + N_("interrupt transfer after <n> seconds of inactivity")), + OPT_END() + }; git_setup_gettext(); @@ -829,40 +843,17 @@ int main(int argc, char **argv) git_extract_argv0_path(argv[0]); check_replace_refs = 0; - for (i = 1; i < argc; i++) { - char *arg = argv[i]; - - if (arg[0] != '-') - break; - if (!strcmp(arg, "--advertise-refs")) { - advertise_refs = 1; - continue; - } - if (!strcmp(arg, "--stateless-rpc")) { - stateless_rpc = 1; - continue; - } - if (!strcmp(arg, "--strict")) { - strict = 1; - continue; - } - if (starts_with(arg, "--timeout=")) { - timeout = atoi(arg+10); - daemon_mode = 1; - continue; - } - if (!strcmp(arg, "--")) { - i++; - break; - } - } + argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0); + + if (argc != 1) + usage_with_options(upload_pack_usage, options); - if (i != argc-1) - usage(upload_pack_usage); + if (timeout) + daemon_mode = 1; setup_path(); - dir = argv[i]; + dir = argv[0]; if (!enter_repo(dir, strict)) die("'%s' does not appear to be a git repository", dir); -- 2.8.2.403.gf2352ca ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v3] upload-pack.c: use of parse-options API 2016-05-23 13:02 ` [PATCH v3] " Antoine Queru @ 2016-05-23 18:03 ` Matthieu Moy 2016-05-27 14:16 ` [PATCH v4] " Antoine Queru 1 sibling, 0 replies; 26+ messages in thread From: Matthieu Moy @ 2016-05-23 18:03 UTC (permalink / raw) To: Antoine Queru Cc: git, william.duclot, simon.rabourg, francois.beutin, gitster, peff Antoine Queru <Antoine.Queru@ensimag.grenoble-inp.fr> writes: > Option parsing now uses the parser API instead of a local parser. > Code is now more compact. > Description for -stateless-rpc and --advertise-refs > come from the commit 42526b4 (Add stateless RPC options to upload-pack, receive-pack, 2009-10-30). We usually wrap commit messages before 80 columns, and separate paragraphs with blank lines. Have a look at "git log --no-merges" and compare with your message. -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v4] upload-pack.c: use of parse-options API 2016-05-23 13:02 ` [PATCH v3] " Antoine Queru 2016-05-23 18:03 ` Matthieu Moy @ 2016-05-27 14:16 ` Antoine Queru 2016-05-27 14:52 ` Matthieu Moy ` (2 more replies) 1 sibling, 3 replies; 26+ messages in thread From: Antoine Queru @ 2016-05-27 14:16 UTC (permalink / raw) To: git Cc: william.duclot, simon.rabourg, francois.beutin, Matthieu.Moy, gitster, peff Option parsing now uses the parser API instead of a local parser. Code is now more compact. Description for --stateless-rpc and --advertise-refs come from the commit 42526b4 (Add stateless RPC options to upload-pack, receive-pack, 2009-10-30). Signed-off-by: Antoine Queru <antoine.queru@grenoble-inp.fr> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> --- Change since v3 : Commit message is now well formated. Updated documentation. Documentation/git-upload-pack.txt | 17 +++++++++-- upload-pack.c | 59 +++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/Documentation/git-upload-pack.txt b/Documentation/git-upload-pack.txt index 0abc806..22ddf8a 100644 --- a/Documentation/git-upload-pack.txt +++ b/Documentation/git-upload-pack.txt @@ -9,8 +9,8 @@ git-upload-pack - Send objects packed back to git-fetch-pack SYNOPSIS -------- [verse] -'git-upload-pack' [--strict] [--timeout=<n>] <directory> - +'git-upload-pack' [--strict] [--timeout=<n>] [--stateless-rpc] + [--advertise-refs] <directory> DESCRIPTION ----------- Invoked by 'git fetch-pack', learns what @@ -31,6 +31,19 @@ OPTIONS --timeout=<n>:: Interrupt transfer after <n> seconds of inactivity. +--stateless-rpc:: + the programs now assume they may perform only a single read-write + cycle with stdin and stdout. This fits with the HTTP POST request + processing model where a program may read the request, write a + response, and must exit. + +--advertise-refs:: + When --advertise-refs is passed as a command line parameter only + the initial ref advertisement is output, and the program exits + immediately. This fits with the HTTP GET request model, where + no request content is received but a response must be produced. + + <directory>:: The repository to sync from. diff --git a/upload-pack.c b/upload-pack.c index dc802a0..2d53c7b 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -14,8 +14,12 @@ #include "sigchain.h" #include "version.h" #include "string-list.h" +#include "parse-options.h" -static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>"; +static const char * const upload_pack_usage[] = { + N_("git upload-pack [options] <dir>"), + NULL +}; /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) @@ -817,11 +821,21 @@ static int upload_pack_config(const char *var, const char *value, void *unused) return parse_hide_refs_config(var, value, "uploadpack"); } -int main(int argc, char **argv) +int main(int argc, const char **argv) { - char *dir; - int i; + const char *dir; int strict = 0; + struct option options[] = { + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, + N_("quit after a single request/response exchange")), + OPT_BOOL(0, "advertise-refs", &advertise_refs, + N_("only the initial ref advertisement is output, program exits immediately")), + OPT_BOOL(0, "strict", &strict, + N_("do not try <directory>/.git/ if <directory> is no Git directory")), + OPT_INTEGER(0, "timeout", &timeout, + N_("interrupt transfer after <n> seconds of inactivity")), + OPT_END() + }; git_setup_gettext(); @@ -829,40 +843,17 @@ int main(int argc, char **argv) git_extract_argv0_path(argv[0]); check_replace_refs = 0; - for (i = 1; i < argc; i++) { - char *arg = argv[i]; - - if (arg[0] != '-') - break; - if (!strcmp(arg, "--advertise-refs")) { - advertise_refs = 1; - continue; - } - if (!strcmp(arg, "--stateless-rpc")) { - stateless_rpc = 1; - continue; - } - if (!strcmp(arg, "--strict")) { - strict = 1; - continue; - } - if (starts_with(arg, "--timeout=")) { - timeout = atoi(arg+10); - daemon_mode = 1; - continue; - } - if (!strcmp(arg, "--")) { - i++; - break; - } - } + argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0); + + if (argc != 1) + usage_with_options(upload_pack_usage, options); - if (i != argc-1) - usage(upload_pack_usage); + if (timeout) + daemon_mode = 1; setup_path(); - dir = argv[i]; + dir = argv[0]; if (!enter_repo(dir, strict)) die("'%s' does not appear to be a git repository", dir); -- 2.8.2.403.g31e708f ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v4] upload-pack.c: use of parse-options API 2016-05-27 14:16 ` [PATCH v4] " Antoine Queru @ 2016-05-27 14:52 ` Matthieu Moy 2016-05-27 16:59 ` Eric Sunshine 2016-05-30 14:53 ` [PATCH v5] upload-pack.c: use " Antoine Queru 2 siblings, 0 replies; 26+ messages in thread From: Matthieu Moy @ 2016-05-27 14:52 UTC (permalink / raw) To: Antoine Queru Cc: git, william.duclot, simon.rabourg, francois.beutin, gitster, peff > Subject: [PATCH v4] upload-pack.c: use of parse-options API I'd drop the "of" and say just "use parse-options API" Antoine Queru <Antoine.Queru@ensimag.grenoble-inp.fr> writes: > Description for --stateless-rpc and --advertise-refs come from > the commit 42526b4 (Add stateless RPC options to upload-pack, Nit: s/the// > +--advertise-refs:: > + When --advertise-refs is passed as a command line parameter only > + the initial ref advertisement is output, and the program exits > + immediately. This fits with the HTTP GET request model, where > + no request content is received but a response must be produced. Another nit: mix space/tab in indentation (renders badly on some configurations). -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v4] upload-pack.c: use of parse-options API 2016-05-27 14:16 ` [PATCH v4] " Antoine Queru 2016-05-27 14:52 ` Matthieu Moy @ 2016-05-27 16:59 ` Eric Sunshine 2016-05-30 14:27 ` Antoine Queru 2016-05-30 14:53 ` [PATCH v5] upload-pack.c: use " Antoine Queru 2 siblings, 1 reply; 26+ messages in thread From: Eric Sunshine @ 2016-05-27 16:59 UTC (permalink / raw) To: Antoine Queru Cc: Git List, William Duclot, simon rabourg, francois beutin, Matthieu Moy, Junio C Hamano, Jeff King On Fri, May 27, 2016 at 10:16 AM, Antoine Queru <Antoine.Queru@ensimag.grenoble-inp.fr> wrote: > upload-pack.c: use of parse-options API Matthieu already mentioned that this should use imperative mood: upload-pack: use parse-options API > Option parsing now uses the parser API instead of a local parser. > Code is now more compact. Imperative: Use the parse-options API rather than a hand-rolled option parser. That the code becomes more compact is a nice result of this change, but not particularly important, thus not really worth a mention in the commit message. > Description for --stateless-rpc and --advertise-refs come from > the commit 42526b4 (Add stateless RPC options to upload-pack, > receive-pack, 2009-10-30). s/from the commit/from/ > Signed-off-by: Antoine Queru <antoine.queru@grenoble-inp.fr> > Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> > --- > diff --git a/Documentation/git-upload-pack.txt b/Documentation/git-upload-pack.txt > @@ -31,6 +31,19 @@ OPTIONS > +--stateless-rpc:: > + the programs now assume they may perform only a single read-write s/the/The/ Also, to what "programs" does this refer? And what does "now" mean here? > + cycle with stdin and stdout. This fits with the HTTP POST request > + processing model where a program may read the request, write a > + response, and must exit. > + > +--advertise-refs:: > + When --advertise-refs is passed as a command line parameter only The entire "When ... parameter" bit is redundant, isn't it? Why not just say "Perform only..."? > + the initial ref advertisement is output, and the program exits > + immediately. This fits with the HTTP GET request model, where > + no request content is received but a response must be produced. > + > + Style: Drop the extra blank line. > <directory>:: > The repository to sync from. > > diff --git a/upload-pack.c b/upload-pack.c > @@ -817,11 +821,21 @@ static int upload_pack_config(const char *var, const char *value, void *unused) > -int main(int argc, char **argv) > +int main(int argc, const char **argv) > { > - char *dir; > - int i; > + const char *dir; > int strict = 0; > + struct option options[] = { > + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, > + N_("quit after a single request/response exchange")), > + OPT_BOOL(0, "advertise-refs", &advertise_refs, > + N_("only the initial ref advertisement is output, program exits immediately")), Possible rewrite: "exit immediately after initial ref advertisement" > + OPT_BOOL(0, "strict", &strict, > + N_("do not try <directory>/.git/ if <directory> is no Git directory")), Use of OPT_BOOL introduces a --no-strict option which didn't exist before. Does this need to be documented? (Genuine question.) > + OPT_INTEGER(0, "timeout", &timeout, > + N_("interrupt transfer after <n> seconds of inactivity")), > + OPT_END() > + }; ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v4] upload-pack.c: use of parse-options API 2016-05-27 16:59 ` Eric Sunshine @ 2016-05-30 14:27 ` Antoine Queru 0 siblings, 0 replies; 26+ messages in thread From: Antoine Queru @ 2016-05-30 14:27 UTC (permalink / raw) To: Eric Sunshine Cc: Git List, William Duclot, simon rabourg, francois beutin, Matthieu Moy, Junio C Hamano, Jeff King Hello Eric, Thank you for answer. Your remarks have been added in the next version. > > + OPT_BOOL(0, "strict", &strict, > > + N_("do not try <directory>/.git/ if <directory> is > > no Git directory")), > > Use of OPT_BOOL introduces a --no-strict option which didn't exist > before. Does this need to be documented? (Genuine question.) > You're right. I've added it in the documentation. Antoine ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v5] upload-pack.c: use parse-options API 2016-05-27 14:16 ` [PATCH v4] " Antoine Queru 2016-05-27 14:52 ` Matthieu Moy 2016-05-27 16:59 ` Eric Sunshine @ 2016-05-30 14:53 ` Antoine Queru 2016-05-30 15:06 ` Matthieu Moy ` (2 more replies) 2 siblings, 3 replies; 26+ messages in thread From: Antoine Queru @ 2016-05-30 14:53 UTC (permalink / raw) To: git Cc: william.duclot, simon.rabourg, francois.beutin, Matthieu.Moy, gitster, peff, sunshine, Antoine Queru From: Antoine Queru <Antoine.Queru@ensimag.grenoble-inp.fr> Use the parse-options API rather than a hand-rolled option parser. Description for --stateless-rpc and --advertise-refs come from 42526b4 (Add stateless RPC options to upload-pack, receive-pack, 2009-10-30). Signed-off-by: Antoine Queru <antoine.queru@grenoble-inp.fr> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> --- Change since v4: Imperative mood for the commit message. "Code is now more compact." removed. Documentation for option is now clearer. Help message for "--advertise-refs" rewritten. "no" for "strict" option added to the doc. Documentation/git-upload-pack.txt | 16 +++++++++-- upload-pack.c | 59 +++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/Documentation/git-upload-pack.txt b/Documentation/git-upload-pack.txt index 0abc806..8a03bed 100644 --- a/Documentation/git-upload-pack.txt +++ b/Documentation/git-upload-pack.txt @@ -9,8 +9,8 @@ git-upload-pack - Send objects packed back to git-fetch-pack SYNOPSIS -------- [verse] -'git-upload-pack' [--strict] [--timeout=<n>] <directory> - +'git-upload-pack' [--[no-]strict] [--timeout=<n>] [--stateless-rpc] + [--advertise-refs] <directory> DESCRIPTION ----------- Invoked by 'git fetch-pack', learns what @@ -25,12 +25,22 @@ repository. For push operations, see 'git send-pack'. OPTIONS ------- ---strict:: +--[no-]strict:: Do not try <directory>/.git/ if <directory> is no Git directory. --timeout=<n>:: Interrupt transfer after <n> seconds of inactivity. +--stateless-rpc:: + Perform only a single read-write cycle with stdin and stdout. + This fits with the HTTP POST request processing model where + a program may read the request, write a response, and must exit. + +--advertise-refs:: + Only the initial ref advertisement is output, and the program exits + immediately. This fits with the HTTP GET request model, where + no request content is received but a response must be produced. + <directory>:: The repository to sync from. diff --git a/upload-pack.c b/upload-pack.c index dc802a0..083d068 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -14,8 +14,12 @@ #include "sigchain.h" #include "version.h" #include "string-list.h" +#include "parse-options.h" -static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>"; +static const char * const upload_pack_usage[] = { + N_("git upload-pack [options] <dir>"), + NULL +}; /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) @@ -817,11 +821,21 @@ static int upload_pack_config(const char *var, const char *value, void *unused) return parse_hide_refs_config(var, value, "uploadpack"); } -int main(int argc, char **argv) +int main(int argc, const char **argv) { - char *dir; - int i; + const char *dir; int strict = 0; + struct option options[] = { + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, + N_("quit after a single request/response exchange")), + OPT_BOOL(0, "advertise-refs", &advertise_refs, + N_("exit immediately after intial ref advertisement")), + OPT_BOOL(0, "strict", &strict, + N_("do not try <directory>/.git/ if <directory> is no Git directory")), + OPT_INTEGER(0, "timeout", &timeout, + N_("interrupt transfer after <n> seconds of inactivity")), + OPT_END() + }; git_setup_gettext(); @@ -829,40 +843,17 @@ int main(int argc, char **argv) git_extract_argv0_path(argv[0]); check_replace_refs = 0; - for (i = 1; i < argc; i++) { - char *arg = argv[i]; - - if (arg[0] != '-') - break; - if (!strcmp(arg, "--advertise-refs")) { - advertise_refs = 1; - continue; - } - if (!strcmp(arg, "--stateless-rpc")) { - stateless_rpc = 1; - continue; - } - if (!strcmp(arg, "--strict")) { - strict = 1; - continue; - } - if (starts_with(arg, "--timeout=")) { - timeout = atoi(arg+10); - daemon_mode = 1; - continue; - } - if (!strcmp(arg, "--")) { - i++; - break; - } - } + argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0); + + if (argc != 1) + usage_with_options(upload_pack_usage, options); - if (i != argc-1) - usage(upload_pack_usage); + if (timeout) + daemon_mode = 1; setup_path(); - dir = argv[i]; + dir = argv[0]; if (!enter_repo(dir, strict)) die("'%s' does not appear to be a git repository", dir); -- 2.8.2.403.g897e5a5 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v5] upload-pack.c: use parse-options API 2016-05-30 14:53 ` [PATCH v5] upload-pack.c: use " Antoine Queru @ 2016-05-30 15:06 ` Matthieu Moy 2016-05-30 19:26 ` Junio C Hamano 2016-05-31 9:57 ` [PATCH v6] " Antoine Queru 2 siblings, 0 replies; 26+ messages in thread From: Matthieu Moy @ 2016-05-30 15:06 UTC (permalink / raw) To: Antoine Queru Cc: git, william.duclot, simon.rabourg, francois.beutin, gitster, peff, sunshine Antoine Queru <antoine.queru@ensimag.grenoble-inp.fr> writes: > From: Antoine Queru <Antoine.Queru@ensimag.grenoble-inp.fr> [ Insert here the sentence I've been repeating a lot lately about this useless From ;-) ] > Documentation/git-upload-pack.txt | 16 +++++++++-- > upload-pack.c | 59 +++++++++++++++++---------------------- > 2 files changed, 38 insertions(+), 37 deletions(-) The patch contains a few whitespace errors: Documentation/git-upload-pack.txt:41: space before tab in indent. + immediately. This fits with the HTTP GET request model, where Documentation/git-upload-pack.txt:42: space before tab in indent. + no request content is received but a response must be produced. upload-pack.c:846: trailing whitespace. + You should notice them immediately if you use "git add -p" (big red warning in the patch hunk), and you can see all of them with "git diff --check" or "git show --check". Not sure if it deserves a reroll. Junio? Other than that, the patch is now Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] upload-pack.c: use parse-options API 2016-05-30 14:53 ` [PATCH v5] upload-pack.c: use " Antoine Queru 2016-05-30 15:06 ` Matthieu Moy @ 2016-05-30 19:26 ` Junio C Hamano 2016-05-31 9:53 ` Antoine Queru 2016-05-31 11:27 ` Matthieu Moy 2016-05-31 9:57 ` [PATCH v6] " Antoine Queru 2 siblings, 2 replies; 26+ messages in thread From: Junio C Hamano @ 2016-05-30 19:26 UTC (permalink / raw) To: Antoine Queru Cc: git, william.duclot, simon.rabourg, francois.beutin, Matthieu.Moy, peff, sunshine Antoine Queru <antoine.queru@ensimag.grenoble-inp.fr> writes: > From: Antoine Queru <Antoine.Queru@ensimag.grenoble-inp.fr> Don't you want to be known to the project as the email that matches your Signed-off-by: line? > Use the parse-options API rather than a hand-rolled option parser. > > Description for --stateless-rpc and --advertise-refs come from > 42526b4 (Add stateless RPC options to upload-pack, > receive-pack, 2009-10-30). > > Signed-off-by: Antoine Queru <antoine.queru@grenoble-inp.fr> > Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> > --- > ---strict:: > +--[no-]strict:: > Do not try <directory>/.git/ if <directory> is no Git directory. Not a new problem, but "is no Git ..." may technically be correct, but it would be easier to read if phrased "is not a Git ..." or something like that. I am NOT asking _you_ to change/fix that in this patch. It is just a note for "a low hanging fruit" for people to pick up with a separate patch. > +--stateless-rpc:: > + Perform only a single read-write cycle with stdin and stdout. > + This fits with the HTTP POST request processing model where > + a program may read the request, write a response, and must exit. > + > +--advertise-refs:: > + Only the initial ref advertisement is output, and the program exits > + immediately. This fits with the HTTP GET request model, where > + no request content is received but a response must be produced. > + Good. > diff --git a/upload-pack.c b/upload-pack.c > index dc802a0..083d068 100644 > --- a/upload-pack.c > +++ b/upload-pack.c > @@ -14,8 +14,12 @@ > #include "sigchain.h" > #include "version.h" > #include "string-list.h" > +#include "parse-options.h" > > -static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>"; > +static const char * const upload_pack_usage[] = { > + N_("git upload-pack [options] <dir>"), > + NULL > +}; Output from "git grep -e '\[option' -e '\[<option' -- \*.c" tells me that "[<options>]" would be more in line with the established convention than "[options]". I personally wish if all these hits from the above grep consistently spelled it as "[options]", because there is not much gained by enclosing the word in <> to highlight it as a placeholder. An argument that "it is done for uniformity with descriptions for other non option arguments, i.e. not to special case 'options'" would not hold water, e.g. in builtin/merge.c: N_("git merge [<options>] [<commit>...]"), <options> is still special-cased in that it implies multiple things, unlike "<commit>..." notation that has to explicitly say that can have multiple. [<options>...] would have been justifiable with the "make it uniform with non-option args", though. BUT this patch is not about "make usage string better" patch, so I do NOT want you to switch upload-pack's usage string to use the "options is special anyway, so let's not waste two display columns with enclosing <>" convention. So, in conclusion, "git upload-pack [<options>] <dir>". The remainder of the patch looked OK to me. Thanks. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] upload-pack.c: use parse-options API 2016-05-30 19:26 ` Junio C Hamano @ 2016-05-31 9:53 ` Antoine Queru 2016-05-31 11:27 ` Matthieu Moy 1 sibling, 0 replies; 26+ messages in thread From: Antoine Queru @ 2016-05-31 9:53 UTC (permalink / raw) To: Junio C Hamano Cc: git, william duclot, simon rabourg, francois beutin, Matthieu Moy, peff, sunshine Hello Junio, thanks for your answer. The next version (and hopefully the last) will come fast. > > From: Antoine Queru <Antoine.Queru@ensimag.grenoble-inp.fr> > > Don't you want to be known to the project as the email that matches > your Signed-off-by: line? Thanks for noticing it, it will be updated. > > +--[no-]strict:: > > Do not try <directory>/.git/ if <directory> is no Git directory. > > Not a new problem, but "is no Git ..." may technically be correct, > but it would be easier to read if phrased "is not a Git ..." or > something like that. > > I am NOT asking _you_ to change/fix that in this patch. It > is just a note for "a low hanging fruit" for people to pick > up with a separate patch. > Ok, so this will not be changed. > > diff --git a/upload-pack.c b/upload-pack.c > > index dc802a0..083d068 100644 > > --- a/upload-pack.c > > +++ b/upload-pack.c > > @@ -14,8 +14,12 @@ > > #include "sigchain.h" > > #include "version.h" > > #include "string-list.h" > > +#include "parse-options.h" > > > > -static const char upload_pack_usage[] = "git upload-pack [--strict] > > [--timeout=<n>] <dir>"; > > +static const char * const upload_pack_usage[] = { > > + N_("git upload-pack [options] <dir>"), > > + NULL > > +}; > > Output from "git grep -e '\[option' -e '\[<option' -- \*.c" tells me > that "[<options>]" would be more in line with the established > convention than "[options]". > > I personally wish if all these hits from the above grep > consistently spelled it as "[options]", because there is not > much gained by enclosing the word in <> to highlight it as a > placeholder. An argument that "it is done for uniformity > with descriptions for other non option arguments, i.e. not > to special case 'options'" would not hold water, e.g. in > > builtin/merge.c: N_("git merge [<options>] [<commit>...]"), > > <options> is still special-cased in that it implies multiple > things, unlike "<commit>..." notation that has to explicitly > say that can have multiple. [<options>...] would have been > justifiable with the "make it uniform with non-option args", > though. > > BUT this patch is not about "make usage string better" > patch, so I do NOT want you to switch upload-pack's usage > string to use the "options is special anyway, so let's not > waste two display columns with enclosing <>" convention. > > So, in conclusion, "git upload-pack [<options>] <dir>". > Ok, so it will be fixed. I didn't notice this convention, my goal wasn't to change it, my bad. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] upload-pack.c: use parse-options API 2016-05-30 19:26 ` Junio C Hamano 2016-05-31 9:53 ` Antoine Queru @ 2016-05-31 11:27 ` Matthieu Moy 2016-05-31 17:16 ` Junio C Hamano 1 sibling, 1 reply; 26+ messages in thread From: Matthieu Moy @ 2016-05-31 11:27 UTC (permalink / raw) To: Junio C Hamano Cc: Antoine Queru, git, william.duclot, simon.rabourg, francois.beutin, peff, sunshine Junio C Hamano <gitster@pobox.com> writes: > Antoine Queru <antoine.queru@ensimag.grenoble-inp.fr> writes: > >> From: Antoine Queru <Antoine.Queru@ensimag.grenoble-inp.fr> >> Signed-off-by: Antoine Queru <antoine.queru@grenoble-inp.fr> > > Don't you want to be known to the project as the email that matches > your Signed-off-by: line? Actually, that's even: don't you want to use a valid email address in your Signed-off-by: ? ;-) @ensimag.grenoble-inp.fr => student's current adress @grenoble-inp.org => students lifelong address. If not already done, students can already set it up to redirect to their current address. @grenoble-inp.fr => only for staff (i.e. me but not students). I have a preference for the @grenoble-inp.org in the From and Signed-off-by as the Git history will remain after the current adress become invalid. -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] upload-pack.c: use parse-options API 2016-05-31 11:27 ` Matthieu Moy @ 2016-05-31 17:16 ` Junio C Hamano 2016-06-01 15:49 ` Antoine Queru 0 siblings, 1 reply; 26+ messages in thread From: Junio C Hamano @ 2016-05-31 17:16 UTC (permalink / raw) To: Matthieu Moy Cc: Antoine Queru, git, william.duclot, simon.rabourg, francois.beutin, peff, sunshine Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes: > Actually, that's even: don't you want to use a valid email address in > your Signed-off-by: ? ;-) > > @ensimag.grenoble-inp.fr => student's current adress > @grenoble-inp.org => students lifelong address. If not already done, > students can already set it up to redirect to their > current address. > @grenoble-inp.fr => only for staff (i.e. me but not students). > > I have a preference for the @grenoble-inp.org in the From and > Signed-off-by as the Git history will remain after the current adress > become invalid. I was wondering about that "ensimag." part myself as I had a vague recollection of your mentioning it in your class projects in previous years. Antoine? I can munge the author and sign-off in your v6 to name you as Antoine Queru <Antoine.Queru@grenoble-inp.org> if you want locally, or I can queue it as-is. What's your preference? ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] upload-pack.c: use parse-options API 2016-05-31 17:16 ` Junio C Hamano @ 2016-06-01 15:49 ` Antoine Queru 0 siblings, 0 replies; 26+ messages in thread From: Antoine Queru @ 2016-06-01 15:49 UTC (permalink / raw) To: Junio C Hamano Cc: Matthieu Moy, git, william duclot, simon rabourg, francois beutin, peff, sunshine > Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes: > > > Actually, that's even: don't you want to use a valid email address in > > your Signed-off-by: ? ;-) > > > > @ensimag.grenoble-inp.fr => student's current adress > > @grenoble-inp.org => students lifelong address. If not already done, > > students can already set it up to redirect to their > > current address. > > @grenoble-inp.fr => only for staff (i.e. me but not students). > > > > I have a preference for the @grenoble-inp.org in the From and > > Signed-off-by as the Git history will remain after the current adress > > become invalid. > > I was wondering about that "ensimag." part myself as I had a vague > recollection of your mentioning it in your class projects in > previous years. > > Antoine? I can munge the author and sign-off in your v6 to name you > as > > Antoine Queru <Antoine.Queru@grenoble-inp.org> > > if you want locally, or I can queue it as-is. What's your > preference? > Ok thanks for telling me, we weren't sure what to do about this. So yeah, it will be better with Antoine.Queru@grenoble-inp.org in the v6, thanks. ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v6] upload-pack.c: use parse-options API 2016-05-30 14:53 ` [PATCH v5] upload-pack.c: use " Antoine Queru 2016-05-30 15:06 ` Matthieu Moy 2016-05-30 19:26 ` Junio C Hamano @ 2016-05-31 9:57 ` Antoine Queru 2 siblings, 0 replies; 26+ messages in thread From: Antoine Queru @ 2016-05-31 9:57 UTC (permalink / raw) To: git Cc: william.duclot, simon.rabourg, francois.beutin, Matthieu.Moy, gitster, peff, sunshine Use the parse-options API rather than a hand-rolled option parser. Description for --stateless-rpc and --advertise-refs come from 42526b4 (Add stateless RPC options to upload-pack, receive-pack, 2009-10-30). Signed-off-by: Antoine Queru <antoine.queru@ensimag.grenoble-inp.fr> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> --- Change since v5 : Signed-off fixed. Whitespace in doc removed. "[options]" replaced by "[<options>]" in usage. Documentation/git-upload-pack.txt | 16 ++++++++--- upload-pack.c | 57 +++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/Documentation/git-upload-pack.txt b/Documentation/git-upload-pack.txt index 0abc806..822ad59 100644 --- a/Documentation/git-upload-pack.txt +++ b/Documentation/git-upload-pack.txt @@ -9,8 +9,8 @@ git-upload-pack - Send objects packed back to git-fetch-pack SYNOPSIS -------- [verse] -'git-upload-pack' [--strict] [--timeout=<n>] <directory> - +'git-upload-pack' [--[no-]strict] [--timeout=<n>] [--stateless-rpc] + [--advertise-refs] <directory> DESCRIPTION ----------- Invoked by 'git fetch-pack', learns what @@ -25,12 +25,22 @@ repository. For push operations, see 'git send-pack'. OPTIONS ------- ---strict:: +--[no-]strict:: Do not try <directory>/.git/ if <directory> is no Git directory. --timeout=<n>:: Interrupt transfer after <n> seconds of inactivity. +--stateless-rpc:: + Perform only a single read-write cycle with stdin and stdout. + This fits with the HTTP POST request processing model where + a program may read the request, write a response, and must exit. + +--advertise-refs:: + Only the initial ref advertisement is output, and the program exits + immediately. This fits with the HTTP GET request model, where + no request content is received but a response must be produced. + <directory>:: The repository to sync from. diff --git a/upload-pack.c b/upload-pack.c index dc802a0..d653404 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -14,8 +14,12 @@ #include "sigchain.h" #include "version.h" #include "string-list.h" +#include "parse-options.h" -static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>"; +static const char * const upload_pack_usage[] = { + N_("git upload-pack [<options>] <dir>"), + NULL +}; /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) @@ -817,11 +821,21 @@ static int upload_pack_config(const char *var, const char *value, void *unused) return parse_hide_refs_config(var, value, "uploadpack"); } -int main(int argc, char **argv) +int main(int argc, const char **argv) { - char *dir; - int i; + const char *dir; int strict = 0; + struct option options[] = { + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, + N_("quit after a single request/response exchange")), + OPT_BOOL(0, "advertise-refs", &advertise_refs, + N_("exit immediately after intial ref advertisement")), + OPT_BOOL(0, "strict", &strict, + N_("do not try <directory>/.git/ if <directory> is no Git directory")), + OPT_INTEGER(0, "timeout", &timeout, + N_("interrupt transfer after <n> seconds of inactivity")), + OPT_END() + }; git_setup_gettext(); @@ -829,40 +843,17 @@ int main(int argc, char **argv) git_extract_argv0_path(argv[0]); check_replace_refs = 0; - for (i = 1; i < argc; i++) { - char *arg = argv[i]; + argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0); - if (arg[0] != '-') - break; - if (!strcmp(arg, "--advertise-refs")) { - advertise_refs = 1; - continue; - } - if (!strcmp(arg, "--stateless-rpc")) { - stateless_rpc = 1; - continue; - } - if (!strcmp(arg, "--strict")) { - strict = 1; - continue; - } - if (starts_with(arg, "--timeout=")) { - timeout = atoi(arg+10); - daemon_mode = 1; - continue; - } - if (!strcmp(arg, "--")) { - i++; - break; - } - } + if (argc != 1) + usage_with_options(upload_pack_usage, options); - if (i != argc-1) - usage(upload_pack_usage); + if (timeout) + daemon_mode = 1; setup_path(); - dir = argv[i]; + dir = argv[0]; if (!enter_repo(dir, strict)) die("'%s' does not appear to be a git repository", dir); -- 2.8.2.403.gef8af9c.dirty ^ permalink raw reply related [flat|nested] 26+ messages in thread
end of thread, other threads:[~2016-06-01 15:42 UTC | newest] Thread overview: 26+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-05-18 16:40 [PATCH] upload-pack.c: use of parse-options API Antoine Queru 2016-05-18 18:08 ` Jeff King 2016-05-19 10:10 ` Antoine Queru 2016-05-19 11:57 ` Jeff King 2016-05-19 14:36 ` Matthieu Moy 2016-05-19 15:39 ` [PATCH v2] " Antoine Queru 2016-05-19 16:10 ` Matthieu Moy 2016-05-19 16:46 ` Junio C Hamano 2016-05-20 6:55 ` Matthieu Moy 2016-05-19 16:58 ` Junio C Hamano 2016-05-20 6:53 ` Matthieu Moy 2016-05-20 16:52 ` Junio C Hamano 2016-05-23 13:02 ` [PATCH v3] " Antoine Queru 2016-05-23 18:03 ` Matthieu Moy 2016-05-27 14:16 ` [PATCH v4] " Antoine Queru 2016-05-27 14:52 ` Matthieu Moy 2016-05-27 16:59 ` Eric Sunshine 2016-05-30 14:27 ` Antoine Queru 2016-05-30 14:53 ` [PATCH v5] upload-pack.c: use " Antoine Queru 2016-05-30 15:06 ` Matthieu Moy 2016-05-30 19:26 ` Junio C Hamano 2016-05-31 9:53 ` Antoine Queru 2016-05-31 11:27 ` Matthieu Moy 2016-05-31 17:16 ` Junio C Hamano 2016-06-01 15:49 ` Antoine Queru 2016-05-31 9:57 ` [PATCH v6] " Antoine Queru
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).