diff --git a/fetch-pack.c b/fetch-pack.c
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -16,20 +16,27 @@ static int find_common(int fd[2], unsign
int count = 0, flushes = 0, retval;
FILE *revs;
- revs = popen("git-rev-list $(git-rev-parse --all)", "r");
- if (!revs)
- die("unable to run 'git-rev-list'");
-
while (refs) {
unsigned char *remote = refs->old_sha1;
- if (verbose)
- fprintf(stderr,
- "want %s (%s)\n", sha1_to_hex(remote),
- refs->name);
- packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
+ if(!has_sha1_file(remote)) {
+ if (verbose)
+ fprintf(stderr,
+ "want %s (%s)\n", sha1_to_hex(remote),
+ refs->name);
+ packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
+ count++;
+ }
refs = refs->next;
}
packet_flush(fd[1]);
+
+ if(count==0)
+ return 1;
+
+ revs = popen("git-rev-list $(git-rev-parse --all)", "r");
+ if (!revs)
+ die("unable to run 'git-rev-list'");
+
flushes = 1;
retval = -1;
while (fgets(line, sizeof(line), revs) != NULL) {@@ -74,7 +81,7 @@ static int find_common(int fd[2], unsign
return retval;
}
-static int fetch_pack(int fd[2], int nr_match, char **match)
+static struct ref *fetch_pack(int fd[2], int nr_match, char **match)
{
struct ref *ref;
unsigned char sha1[20];@@ -86,7 +93,10 @@ static int fetch_pack(int fd[2], int nr_
packet_flush(fd[1]);
die("no matching remote head");
}
- if (find_common(fd, sha1, ref) < 0)
+ status = find_common(fd, sha1, ref);
+ if(status > 0)
+ return ref;
+ if(status < 0)
fprintf(stderr, "warning: no common commits\n");
pid = fork();
if (pid < 0)@@ -109,12 +119,7 @@ static int fetch_pack(int fd[2], int nr_
int code = WEXITSTATUS(status);
if (code)
die("git-unpack-objects died with error code %d", code);
- while (ref) {
- printf("%s %s\n",
- sha1_to_hex(ref->old_sha1), ref->name);
- ref = ref->next;
- }
- return 0;
+ return ref;
}
if (WIFSIGNALED(status)) {
int sig = WTERMSIG(status);@@ -125,10 +130,11 @@ static int fetch_pack(int fd[2], int nr_
int main(int argc, char **argv)
{
- int i, ret, nr_heads;
+ int i, nr_heads;
char *dest = NULL, **heads;
int fd[2];
pid_t pid;
+ struct ref *ref;
nr_heads = 0;
heads = NULL;@@ -160,9 +166,19 @@ int main(int argc, char **argv)
pid = git_connect(fd, dest, exec);
if (pid < 0)
return 1;
- ret = fetch_pack(fd, nr_heads, heads);
+ ref = fetch_pack(fd, nr_heads, heads);
+ if(!ref)
+ return 1;
+
+ while (ref) {
+ printf("%s %s\n",
+ sha1_to_hex(ref->old_sha1), ref->name);
+ ref = ref->next;
+ }
+
close(fd[0]);
close(fd[1]);
finish_connect(pid);
- return ret;
+
+ return 0;
}