Skip to content

Commit 9812f21

Browse files
Antoine Querugitster
authored andcommitted
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>
1 parent f3913c2 commit 9812f21

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

Documentation/git-upload-pack.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ git-upload-pack - Send objects packed back to git-fetch-pack
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git-upload-pack' [--strict] [--timeout=<n>] <directory>
13-
12+
'git-upload-pack' [--[no-]strict] [--timeout=<n>] [--stateless-rpc]
13+
[--advertise-refs] <directory>
1414
DESCRIPTION
1515
-----------
1616
Invoked by 'git fetch-pack', learns what
@@ -25,12 +25,22 @@ repository. For push operations, see 'git send-pack'.
2525
OPTIONS
2626
-------
2727

28-
--strict::
28+
--[no-]strict::
2929
Do not try <directory>/.git/ if <directory> is no Git directory.
3030

3131
--timeout=<n>::
3232
Interrupt transfer after <n> seconds of inactivity.
3333

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+
3444
<directory>::
3545
The repository to sync from.
3646

upload-pack.c

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
#include "sigchain.h"
1515
#include "version.h"
1616
#include "string-list.h"
17+
#include "parse-options.h"
1718

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+
};
1923

2024
/* Remember to update object flag allocation in object.h */
2125
#define THEY_HAVE (1u << 11)
@@ -816,52 +820,39 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
816820
return parse_hide_refs_config(var, value, "uploadpack");
817821
}
818822

819-
int main(int argc, char **argv)
823+
int main(int argc, const char **argv)
820824
{
821-
char *dir;
822-
int i;
825+
const char *dir;
823826
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+
};
824838

825839
git_setup_gettext();
826840

827841
packet_trace_identity("upload-pack");
828842
git_extract_argv0_path(argv[0]);
829843
check_replace_refs = 0;
830844

831-
for (i = 1; i < argc; i++) {
832-
char *arg = argv[i];
845+
argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0);
833846

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);
858849

859-
if (i != argc-1)
860-
usage(upload_pack_usage);
850+
if (timeout)
851+
daemon_mode = 1;
861852

862853
setup_path();
863854

864-
dir = argv[i];
855+
dir = argv[0];
865856

866857
if (!enter_repo(dir, strict))
867858
die("'%s' does not appear to be a git repository", dir);

0 commit comments

Comments
 (0)