upload-pack.c: use parse-options API
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.org> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Antoine Queru committed
May 31, 2016 at 11:57 UTC
9812f2136b3ebb28ccdb52e19660bffde760ff23
2 files changed
+37
-36
Documentation/git-upload-pack.txt
+13
-3
@@ -9,8 +9,8 @@ git-upload-pack - Send objects packed back to git-fetch-pack
9
SYNOPSIS
10
--------
11
[verse]
12
-'git-upload-pack' [--strict] [--timeout=<n>] <directory>
13
-
12
+'git-upload-pack' [--[no-]strict] [--timeout=<n>] [--stateless-rpc]
13
+ [--advertise-refs] <directory>
14
DESCRIPTION
15
-----------
16
Invoked by 'git fetch-pack', learns what
@@ -25,12 +25,22 @@ repository. For push operations, see 'git send-pack'.
25
OPTIONS
26
-------
27
28
---strict::
28
+--[no-]strict::
29
Do not try <directory>/.git/ if <directory> is no Git directory.
30
31
--timeout=<n>::
32
Interrupt transfer after <n> seconds of inactivity.
33
34
+--stateless-rpc::
35
+ Perform only a single read-write cycle with stdin and stdout.
36
+ This fits with the HTTP POST request processing model where
37
+ a program may read the request, write a response, and must exit.
38
+
39
+--advertise-refs::
40
+ Only the initial ref advertisement is output, and the program exits
41
+ immediately. This fits with the HTTP GET request model, where
42
+ no request content is received but a response must be produced.
43
+
44
<directory>::
45
The repository to sync from.
46
upload-pack.c
+24
-33
@@ -14,8 +14,12 @@
14
#include "sigchain.h"
15
#include "version.h"
16
#include "string-list.h"
17
+#include "parse-options.h"
18
18
-static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>";
19
+static const char * const upload_pack_usage[] = {
20
+ N_("git upload-pack [<options>] <dir>"),
21
+ NULL
22
+};
23
24
/* Remember to update object flag allocation in object.h */
25
#define THEY_HAVE (1u << 11)
@@ -816,11 +820,21 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
820
return parse_hide_refs_config(var, value, "uploadpack");
821
}
822
819
-int main(int argc, char **argv)
823
+int main(int argc, const char **argv)
824
{
821
- char *dir;
822
- int i;
825
+ const char *dir;
826
int strict = 0;
827
+ struct option options[] = {
828
+ OPT_BOOL(0, "stateless-rpc", &stateless_rpc,
829
+ N_("quit after a single request/response exchange")),
830
+ OPT_BOOL(0, "advertise-refs", &advertise_refs,
831
+ N_("exit immediately after intial ref advertisement")),
832
+ OPT_BOOL(0, "strict", &strict,
833
+ N_("do not try <directory>/.git/ if <directory> is no Git directory")),
834
+ OPT_INTEGER(0, "timeout", &timeout,
835
+ N_("interrupt transfer after <n> seconds of inactivity")),
836
+ OPT_END()
837
+ };
838
839
git_setup_gettext();
840
@@ -828,40 +842,17 @@ int main(int argc, char **argv)
842
git_extract_argv0_path(argv[0]);
843
check_replace_refs = 0;
844
831
- for (i = 1; i < argc; i++) {
832
- char *arg = argv[i];
845
+ argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0);
846
834
- if (arg[0] != '-')
835
- break;
836
- if (!strcmp(arg, "--advertise-refs")) {
837
- advertise_refs = 1;
838
- continue;
839
- }
840
- if (!strcmp(arg, "--stateless-rpc")) {
841
- stateless_rpc = 1;
842
- continue;
843
- }
844
- if (!strcmp(arg, "--strict")) {
845
- strict = 1;
846
- continue;
847
- }
848
- if (starts_with(arg, "--timeout=")) {
849
- timeout = atoi(arg+10);
850
- daemon_mode = 1;
851
- continue;
852
- }
853
- if (!strcmp(arg, "--")) {
854
- i++;
855
- break;
856
- }
857
- }
847
+ if (argc != 1)
848
+ usage_with_options(upload_pack_usage, options);
849
859
- if (i != argc-1)
860
- usage(upload_pack_usage);
850
+ if (timeout)
851
+ daemon_mode = 1;
852
853
setup_path();
854
864
- dir = argv[i];
855
+ dir = argv[0];
856
857
if (!enter_repo(dir, strict))
858
die("'%s' does not appear to be a git repository", dir);