Fix sparse warnings
Fix warnings from 'make check'.
- These files don't include 'builtin.h' causing sparse to complain that
cmd_* isn't declared:
builtin/clone.c:364, builtin/fetch-pack.c:797,
builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
builtin/merge-index.c:69, builtin/merge-recursive.c:22
builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
builtin/notes.c:822, builtin/pack-redundant.c:596,
builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
builtin/remote.c:1512, builtin/remote-ext.c:240,
builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
builtin/unpack-file.c:25, builtin/var.c:75
- These files have symbols which should be marked static since they're
only file scope:
submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
- These files redeclare symbols to be different types:
builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
usage.c:49, usage.c:58, usage.c:63, usage.c:72
- These files use a literal integer 0 when they really should use a NULL
pointer:
daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-22 07:51:05 +00:00
|
|
|
#include "builtin.h"
|
2010-10-12 16:39:43 +00:00
|
|
|
#include "transport.h"
|
|
|
|
#include "run-command.h"
|
2015-09-24 21:07:27 +00:00
|
|
|
#include "pkt-line.h"
|
2010-10-12 16:39:43 +00:00
|
|
|
|
2017-05-30 05:15:09 +00:00
|
|
|
static const char usage_msg[] =
|
|
|
|
"git remote-ext <remote> <url>";
|
|
|
|
|
2010-10-12 16:39:43 +00:00
|
|
|
/*
|
|
|
|
* URL syntax:
|
|
|
|
* 'command [arg1 [arg2 [...]]]' Invoke command with given arguments.
|
|
|
|
* Special characters:
|
|
|
|
* '% ': Literal space in argument.
|
|
|
|
* '%%': Literal percent sign.
|
|
|
|
* '%S': Name of service (git-upload-pack/git-upload-archive/
|
|
|
|
* git-receive-pack.
|
|
|
|
* '%s': Same as \s, but with possible git- prefix stripped.
|
|
|
|
* '%G': Only allowed as first 'character' of argument. Do not pass this
|
|
|
|
* Argument to command, instead send this as name of repository
|
|
|
|
* in in-line git://-style request (also activates sending this
|
|
|
|
* style of request).
|
|
|
|
* '%V': Only allowed as first 'character' of argument. Used in
|
|
|
|
* conjunction with '%G': Do not pass this argument to command,
|
|
|
|
* instead send this as vhost in git://-style request (note: does
|
|
|
|
* not activate sending git:// style request).
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char *git_req;
|
|
|
|
static char *git_req_vhost;
|
|
|
|
|
|
|
|
static char *strip_escapes(const char *str, const char *service,
|
|
|
|
const char **next)
|
|
|
|
{
|
|
|
|
size_t rpos = 0;
|
|
|
|
int escape = 0;
|
|
|
|
char special = 0;
|
2014-10-04 18:54:50 +00:00
|
|
|
const char *service_noprefix = service;
|
2010-10-12 16:39:43 +00:00
|
|
|
struct strbuf ret = STRBUF_INIT;
|
|
|
|
|
2014-10-04 18:54:50 +00:00
|
|
|
skip_prefix(service_noprefix, "git-", &service_noprefix);
|
2010-10-12 16:39:43 +00:00
|
|
|
|
|
|
|
/* Pass the service to command. */
|
|
|
|
setenv("GIT_EXT_SERVICE", service, 1);
|
2014-10-04 18:54:50 +00:00
|
|
|
setenv("GIT_EXT_SERVICE_NOPREFIX", service_noprefix, 1);
|
2010-10-12 16:39:43 +00:00
|
|
|
|
|
|
|
/* Scan the length of argument. */
|
|
|
|
while (str[rpos] && (escape || str[rpos] != ' ')) {
|
|
|
|
if (escape) {
|
|
|
|
switch (str[rpos]) {
|
|
|
|
case ' ':
|
|
|
|
case '%':
|
|
|
|
case 's':
|
|
|
|
case 'S':
|
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
case 'V':
|
|
|
|
special = str[rpos];
|
|
|
|
if (rpos == 1)
|
|
|
|
break;
|
consistently use "fallthrough" comments in switches
Gcc 7 adds -Wimplicit-fallthrough, which can warn when a
switch case falls through to the next case. The general idea
is that the compiler can't tell if this was intentional or
not, so you should annotate any intentional fall-throughs as
such, leaving it to complain about any unannotated ones.
There's a GNU __attribute__ which can be used for
annotation, but of course we'd have to #ifdef it away on
non-gcc compilers. Gcc will also recognize
specially-formatted comments, which matches our current
practice. Let's extend that practice to all of the
unannotated sites (which I did look over and verify that
they were behaving as intended).
Ideally in each case we'd actually give some reasons in the
comment about why we're falling through, or what we're
falling through to. And gcc does support that with
-Wimplicit-fallthrough=2, which relaxes the comment pattern
matching to anything that contains "fallthrough" (or a
variety of spelling variants). However, this isn't the
default for -Wimplicit-fallthrough, nor for -Wextra. In the
name of simplicity, it's probably better for us to support
the default level, which requires "fallthrough" to be the
only thing in the comment (modulo some window dressing like
"else" and some punctuation; see the gcc manual for the
complete set of patterns).
This patch suppresses all warnings due to
-Wimplicit-fallthrough. We might eventually want to add that
to the DEVELOPER Makefile knob, but we should probably wait
until gcc 7 is more widely adopted (since earlier versions
will complain about the unknown warning type).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-09-21 06:25:41 +00:00
|
|
|
/* fallthrough */
|
2010-10-12 16:39:43 +00:00
|
|
|
default:
|
|
|
|
die("Bad remote-ext placeholder '%%%c'.",
|
|
|
|
str[rpos]);
|
|
|
|
}
|
|
|
|
escape = 0;
|
|
|
|
} else
|
|
|
|
escape = (str[rpos] == '%');
|
|
|
|
rpos++;
|
|
|
|
}
|
|
|
|
if (escape && !str[rpos])
|
|
|
|
die("remote-ext command has incomplete placeholder");
|
|
|
|
*next = str + rpos;
|
|
|
|
if (**next == ' ')
|
|
|
|
++*next; /* Skip over space */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the actual placeholder substitution. The string will be short
|
|
|
|
* enough not to overflow integers.
|
|
|
|
*/
|
|
|
|
rpos = special ? 2 : 0; /* Skip first 2 bytes in specials. */
|
|
|
|
escape = 0;
|
|
|
|
while (str[rpos] && (escape || str[rpos] != ' ')) {
|
|
|
|
if (escape) {
|
|
|
|
switch (str[rpos]) {
|
|
|
|
case ' ':
|
|
|
|
case '%':
|
|
|
|
strbuf_addch(&ret, str[rpos]);
|
|
|
|
break;
|
|
|
|
case 's':
|
2014-10-04 18:54:50 +00:00
|
|
|
strbuf_addstr(&ret, service_noprefix);
|
2010-10-12 16:39:43 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
strbuf_addstr(&ret, service);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
escape = 0;
|
|
|
|
} else
|
|
|
|
switch (str[rpos]) {
|
|
|
|
case '%':
|
|
|
|
escape = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strbuf_addch(&ret, str[rpos]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rpos++;
|
|
|
|
}
|
|
|
|
switch (special) {
|
|
|
|
case 'G':
|
|
|
|
git_req = strbuf_detach(&ret, NULL);
|
|
|
|
return NULL;
|
|
|
|
case 'V':
|
|
|
|
git_req_vhost = strbuf_detach(&ret, NULL);
|
|
|
|
return NULL;
|
|
|
|
default:
|
|
|
|
return strbuf_detach(&ret, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-22 22:44:21 +00:00
|
|
|
static void parse_argv(struct argv_array *out, const char *arg, const char *service)
|
2010-10-12 16:39:43 +00:00
|
|
|
{
|
|
|
|
while (*arg) {
|
2016-02-22 22:44:21 +00:00
|
|
|
char *expanded = strip_escapes(arg, service, &arg);
|
2010-10-12 16:39:43 +00:00
|
|
|
if (expanded)
|
2016-02-22 22:44:21 +00:00
|
|
|
argv_array_push(out, expanded);
|
|
|
|
free(expanded);
|
2010-10-12 16:39:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void send_git_request(int stdin_fd, const char *serv, const char *repo,
|
|
|
|
const char *vhost)
|
|
|
|
{
|
2015-09-24 21:07:27 +00:00
|
|
|
if (!vhost)
|
2016-10-16 23:20:29 +00:00
|
|
|
packet_write_fmt(stdin_fd, "%s %s%c", serv, repo, 0);
|
2010-10-12 16:39:43 +00:00
|
|
|
else
|
2016-10-16 23:20:29 +00:00
|
|
|
packet_write_fmt(stdin_fd, "%s %s%chost=%s%c", serv, repo, 0,
|
2015-09-24 21:07:27 +00:00
|
|
|
vhost, 0);
|
2010-10-12 16:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int run_child(const char *arg, const char *service)
|
|
|
|
{
|
|
|
|
int r;
|
2014-08-19 19:09:35 +00:00
|
|
|
struct child_process child = CHILD_PROCESS_INIT;
|
2010-10-12 16:39:43 +00:00
|
|
|
|
|
|
|
child.in = -1;
|
|
|
|
child.out = -1;
|
|
|
|
child.err = 0;
|
2016-02-22 22:44:21 +00:00
|
|
|
parse_argv(&child.args, arg, service);
|
2010-10-12 16:39:43 +00:00
|
|
|
|
|
|
|
if (start_command(&child) < 0)
|
|
|
|
die("Can't run specified command");
|
|
|
|
|
|
|
|
if (git_req)
|
|
|
|
send_git_request(child.in, service, git_req, git_req_vhost);
|
|
|
|
|
|
|
|
r = bidirectional_transfer_loop(child.out, child.in);
|
|
|
|
if (!r)
|
|
|
|
r = finish_command(&child);
|
|
|
|
else
|
|
|
|
finish_command(&child);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAXCOMMAND 4096
|
|
|
|
|
|
|
|
static int command_loop(const char *child)
|
|
|
|
{
|
|
|
|
char buffer[MAXCOMMAND];
|
|
|
|
|
|
|
|
while (1) {
|
2011-01-16 03:49:40 +00:00
|
|
|
size_t i;
|
2010-10-12 16:39:43 +00:00
|
|
|
if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
|
|
|
|
if (ferror(stdin))
|
2016-05-06 12:36:46 +00:00
|
|
|
die("Command input error");
|
2010-10-12 16:39:43 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* Strip end of line characters. */
|
2011-01-16 03:49:40 +00:00
|
|
|
i = strlen(buffer);
|
|
|
|
while (i > 0 && isspace(buffer[i - 1]))
|
|
|
|
buffer[--i] = 0;
|
2010-10-12 16:39:43 +00:00
|
|
|
|
|
|
|
if (!strcmp(buffer, "capabilities")) {
|
|
|
|
printf("*connect\n\n");
|
|
|
|
fflush(stdout);
|
|
|
|
} else if (!strncmp(buffer, "connect ", 8)) {
|
|
|
|
printf("\n");
|
|
|
|
fflush(stdout);
|
|
|
|
return run_child(child, buffer + 8);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Bad command");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_remote_ext(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2010-11-17 17:15:34 +00:00
|
|
|
if (argc != 3)
|
2017-05-30 05:15:09 +00:00
|
|
|
usage(usage_msg);
|
2010-10-12 16:39:43 +00:00
|
|
|
|
|
|
|
return command_loop(argv[2]);
|
|
|
|
}
|