#include "cache.h"
#include "pkt-line.h"
#include "quote.h"
+#include "refs.h"
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
/*
* Read all the refs from the other end
*/
-struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match)
+struct ref **get_remote_heads(int in, struct ref **list,
+ int nr_match, char **match, int ignore_funny)
{
*list = NULL;
for (;;) {
if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
die("protocol error: expected sha/ref, got '%s'", buffer);
name = buffer + 41;
+
+ if (ignore_funny && 45 < len && !memcmp(name, "refs/", 5) &&
+ check_ref_format(name + 5))
+ continue;
+
if (nr_match && !path_match(name, nr_match, match))
continue;
ref = xcalloc(1, sizeof(*ref) + len - 40);
struct refspec {
char *src;
char *dst;
+ char force;
};
+/*
+ * A:B means fast forward remote B with local A.
+ * +A:B means overwrite remote B with local A.
+ * +A is a shorthand for +A:A.
+ * A is a shorthand for A:A.
+ */
static struct refspec *parse_ref_spec(int nr_refspec, char **refspec)
{
int i;
- struct refspec *rs = xmalloc(sizeof(*rs) * (nr_refspec + 1));
+ struct refspec *rs = xcalloc(sizeof(*rs), (nr_refspec + 1));
for (i = 0; i < nr_refspec; i++) {
char *sp, *dp, *ep;
sp = refspec[i];
+ if (*sp == '+') {
+ rs[i].force = 1;
+ sp++;
+ }
ep = strchr(sp, ':');
if (ep) {
dp = ep + 1;
error("dst ref %s receives from more than one src.",
matched_dst->name);
}
- else
+ else {
matched_dst->peer_ref = matched_src;
+ matched_dst->force = rs[i].force;
+ }
}
return -errs;
}
close(pipefd[1][0]);
close(pipefd[1][1]);
if (protocol == PROTO_SSH) {
- const char *ssh = getenv("GIT_SSH") ? : "ssh";
- const char *ssh_basename = strrchr(ssh, '/');
+ const char *ssh, *ssh_basename;
+ ssh = getenv("GIT_SSH");
+ if (!ssh) ssh = "ssh";
+ ssh_basename = strrchr(ssh, '/');
if (!ssh_basename)
ssh_basename = ssh;
else