summaryrefslogtreecommitdiff
path: root/send-pack.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-30 12:28:24 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-30 12:28:24 -0700
commitd0efc8a71da1855c705fd2074b219bcb158b6dbd (patch)
treef26b700095ec30154fede14638a099f49744981d /send-pack.c
parentf65fdf04a13d2252de8b2b4b161db7c43f2c28ad (diff)
downloadgit-d0efc8a71da1855c705fd2074b219bcb158b6dbd.tar.gz
Do ref matching on the sender side rather than on receiver
This makes the receiver always send a full list of valid refs, which will allow us to do better packs, as well as handle creation of new refs. Eventually. Right now we just moved the matching and enabled it. So now you can do git-send-pack host:path branch1 branch2 to only send branches "branch1" and "branch2".
Diffstat (limited to 'send-pack.c')
-rw-r--r--send-pack.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/send-pack.c b/send-pack.c
index 45198674ab..93674d8e4f 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -3,9 +3,29 @@
#include <sys/wait.h>
static const char send_pack_usage[] = "git-send-pack [--exec=other] destination [heads]*";
-
static const char *exec = "git-receive-pack";
+static int path_match(const char *path, int nr, char **match)
+{
+ int i;
+ int pathlen = strlen(path);
+
+ for (i = 0; i < nr; i++) {
+ char *s = match[i];
+ int len = strlen(s);
+
+ if (!len || len > pathlen)
+ continue;
+ if (memcmp(path + pathlen - len, s, len))
+ continue;
+ if (pathlen > len && path[pathlen - len - 1] != '/')
+ continue;
+ *s = 0;
+ return 1;
+ }
+ return 0;
+}
+
struct ref {
struct ref *next;
unsigned char old_sha1[20];
@@ -108,7 +128,7 @@ static int read_ref(const char *ref, unsigned char *sha1)
return ret;
}
-static int send_pack(int in, int out)
+static int send_pack(int in, int out, int nr_match, char **match)
{
struct ref *ref_list = NULL, **last_ref = &ref_list;
struct ref *ref;
@@ -129,6 +149,8 @@ static int send_pack(int in, int out)
if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
die("protocol error: expected sha/ref, got '%s'", buffer);
name = buffer + 41;
+ if (nr_match && !path_match(name, nr_match, match))
+ continue;
if (read_ref(name, new_sha1) < 0)
return error("no such local reference '%s'", name);
if (!has_sha1_file(old_sha1))
@@ -260,7 +282,7 @@ int main(int argc, char **argv)
pid = setup_connection(fd, dest, heads);
if (pid < 0)
return 1;
- ret = send_pack(fd[0], fd[1]);
+ ret = send_pack(fd[0], fd[1], nr_heads, heads);
close(fd[0]);
close(fd[1]);
waitpid(pid, NULL, 0);