Skip to content
Permalink
Browse files

helper: Add support for passing through bundle2 instead of cg1

  • Loading branch information...
glandium committed Jun 22, 2016
1 parent b95ad9a commit 188c53d0a2a07a9cad3c4844c5c784aa3c0ee4af
Showing with 51 additions and 13 deletions.
  1. +48 −10 hg-bundle.c
  2. +1 −1 hg-bundle.h
  3. +1 −1 hg-connect-stdio.c
  4. +1 −1 hg-connect.c
@@ -2,30 +2,43 @@
#include "hg-bundle.h"
#include <stdint.h>

static size_t copy_changegroup_chunk(FILE *in, FILE *out)
static size_t copy_data(uint32_t len, FILE *in, FILE *out)
{
unsigned char buf[4096];
size_t ret = len;
while (len) {
uint32_t sz = len > sizeof(buf) ? sizeof(buf) : len;
fread(buf, 1, sz, in);
fwrite(buf, 1, sz, out);
len -= sz;
}
return ret;
}

static size_t copy_chunk(int adjust, FILE *in, FILE *out)
{
unsigned char buf[4];
const unsigned char *p = buf;
uint32_t len;
size_t ret = 0;
//TODO: Check for errors, etc.
fread(buf, 1, 4, in);
fwrite(buf, 1, 4, out);
len = get_be32(p);
if (len <= 4)
if (len <= adjust)
//TODO: len != 0 is actually invalid
return 0;
ret = len -= 4;
while (len) {
uint32_t sz = len > sizeof(buf) ? sizeof(buf) : len;
fread(buf, 1, sz, in);
fwrite(buf, 1, sz, out);
len -= sz;
}
ret = len -= adjust;
copy_data(len, in, out);
return ret;
}

void copy_changegroup(FILE *in, FILE *out)
static size_t copy_changegroup_chunk(FILE *in, FILE *out)
{
return copy_chunk(4, in, out);
}

static void copy_changegroup(FILE *in, FILE *out)
{
/* changesets */
while (copy_changegroup_chunk(in, out)) {}
@@ -36,3 +49,28 @@ void copy_changegroup(FILE *in, FILE *out)
while (copy_changegroup_chunk(in, out)) {}
}
}

static size_t copy_bundle2_chunk(FILE *in, FILE *out)
{
return copy_chunk(0, in, out);
}

void copy_bundle(FILE *in, FILE *out)
{
unsigned char buf[4];
const unsigned char *p = buf;
//TODO: Check for errors, etc.
fread(buf, 1, 4, in);
fwrite(buf, 1, 4, out);
if (memcmp(buf, "HG20", 4)) {
copy_data(get_be32(p) - 4, in, out);
copy_changegroup(in, out);
return;
}
// bundle2 parameters
copy_bundle2_chunk(in, out);
// bundle2 parts
while (copy_bundle2_chunk(in, out)) {
while (copy_bundle2_chunk(in, out)) {}
}
}
@@ -3,6 +3,6 @@

#include <stdio.h>

extern void copy_changegroup(FILE *in, FILE *out);
extern void copy_bundle(FILE *in, FILE *out);

#endif
@@ -112,7 +112,7 @@ static void stdio_changegroup_command(struct hg_connection *conn, FILE *out,
* going to be in advance, so we have to read it according to its
* format: the changegroup format. For now, only support changegroupv1
*/
copy_changegroup(conn->stdio.out, out);
copy_bundle(conn->stdio.out, out);
va_end(ap);
}

@@ -181,7 +181,7 @@ void hg_unbundle(struct hg_connection *conn, struct strbuf *response, FILE *in,
//TODO: error checking
mks_tempfile_ts(tmpfile, "hg-bundle-XXXXXX.hg", 3);
file = fdopen_tempfile(tmpfile, "w");
copy_changegroup(in, file);
copy_bundle(in, file);
close_tempfile(tmpfile);

file = fopen(tmpfile->filename.buf, "r");

0 comments on commit 188c53d

Please sign in to comment.
You can’t perform that action at this time.