Skip to content

Commit

Permalink
vcs-svn: eliminate repo_tree structure
Browse files Browse the repository at this point in the history
Rely on fast-import for information about previous revs.

This requires always setting up backward flow of information, even for
v2 dumps.  On the plus side, it simplifies the code by quite a bit and
opens the door to further simplifications.

[db: adjusted to support final version of the cat-blob patch]
[jn: avoiding hard-coding git's name for the empty tree for
 portability to other backends]

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
  • Loading branch information
Jonathan Nieder committed Mar 7, 2011
1 parent 7e11902 commit 723b7a2
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 340 deletions.
108 changes: 94 additions & 14 deletions vcs-svn/fast_export.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "line_buffer.h"
#include "repo_tree.h"
#include "string_pool.h"
#include "strbuf.h"

#define MAX_GITSVN_LINE_LEN 4096

Expand All @@ -31,30 +32,35 @@ void fast_export_reset(void)
buffer_reset(&report_buffer);
}

void fast_export_delete(uint32_t depth, uint32_t *path)
void fast_export_delete(uint32_t depth, const uint32_t *path)
{
putchar('D');
putchar(' ');
pool_print_seq(depth, path, '/', stdout);
putchar('\n');
}

void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
uint32_t mark)
static void fast_export_truncate(uint32_t depth, const uint32_t *path, uint32_t mode)
{
/* Mode must be 100644, 100755, 120000, or 160000. */
printf("M %06"PRIo32" :%"PRIu32" ", mode, mark);
pool_print_seq(depth, path, '/', stdout);
putchar('\n');
fast_export_modify(depth, path, mode, "inline");
printf("data 0\n\n");
}

void fast_export_begin_commit(uint32_t revision)
void fast_export_modify(uint32_t depth, const uint32_t *path, uint32_t mode,
const char *dataref)
{
printf("# commit %"PRIu32".\n", revision);
/* Mode must be 100644, 100755, 120000, or 160000. */
if (!dataref) {
fast_export_truncate(depth, path, mode);
return;
}
printf("M %06"PRIo32" %s ", mode, dataref);
pool_print_seq(depth, path, '/', stdout);
putchar('\n');
}

static char gitsvnline[MAX_GITSVN_LINE_LEN];
void fast_export_commit(uint32_t revision, uint32_t author, char *log,
void fast_export_begin_commit(uint32_t revision, uint32_t author, char *log,
uint32_t uuid, uint32_t url,
unsigned long timestamp)
{
Expand All @@ -81,12 +87,31 @@ void fast_export_commit(uint32_t revision, uint32_t author, char *log,
printf("from refs/heads/master^0\n");
first_commit_done = 1;
}
repo_diff(revision - 1, revision);
fputc('\n', stdout);
}

void fast_export_end_commit(uint32_t revision)
{
printf("progress Imported commit %"PRIu32".\n\n", revision);
}

static void ls_from_rev(uint32_t rev, uint32_t depth, const uint32_t *path)
{
/* ls :5 path/to/old/file */
printf("ls :%"PRIu32" ", rev);
pool_print_seq(depth, path, '/', stdout);
putchar('\n');
fflush(stdout);
}

static void ls_from_active_commit(uint32_t depth, const uint32_t *path)
{
/* ls "path/to/file" */
printf("ls \"");
pool_print_seq(depth, path, '/', stdout);
printf("\"\n");
fflush(stdout);
}

static const char *get_response_line(void)
{
const char *line = buffer_read_line(&report_buffer);
Expand All @@ -97,14 +122,69 @@ static const char *get_response_line(void)
die("unexpected end of fast-import feedback");
}

void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
void fast_export_data(uint32_t mode, uint32_t len, struct line_buffer *input)
{
if (mode == REPO_MODE_LNK) {
/* svn symlink blobs start with "link " */
buffer_skip_bytes(input, 5);
len -= 5;
}
printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
printf("data %"PRIu32"\n", len);
buffer_copy_bytes(input, len);
fputc('\n', stdout);
}

static int parse_ls_response(const char *response, uint32_t *mode,
struct strbuf *dataref)
{
const char *tab;
const char *response_end;

assert(response);
response_end = response + strlen(response);

if (*response == 'm') { /* Missing. */
errno = ENOENT;
return -1;
}

/* Mode. */
if (response_end - response < strlen("100644") ||
response[strlen("100644")] != ' ')
die("invalid ls response: missing mode: %s", response);
*mode = 0;
for (; *response != ' '; response++) {
char ch = *response;
if (ch < '0' || ch > '7')
die("invalid ls response: mode is not octal: %s", response);
*mode *= 8;
*mode += ch - '0';
}

/* ' blob ' or ' tree ' */
if (response_end - response < strlen(" blob ") ||
(response[1] != 'b' && response[1] != 't'))
die("unexpected ls response: not a tree or blob: %s", response);
response += strlen(" blob ");

/* Dataref. */
tab = memchr(response, '\t', response_end - response);
if (!tab)
die("invalid ls response: missing tab: %s", response);
strbuf_add(dataref, response, tab - response);
return 0;
}

int fast_export_ls_rev(uint32_t rev, uint32_t depth, const uint32_t *path,
uint32_t *mode, struct strbuf *dataref)
{
ls_from_rev(rev, depth, path);
return parse_ls_response(get_response_line(), mode, dataref);
}

int fast_export_ls(uint32_t depth, const uint32_t *path,
uint32_t *mode, struct strbuf *dataref)
{
ls_from_active_commit(depth, path);
return parse_ls_response(get_response_line(), mode, dataref);
}
22 changes: 14 additions & 8 deletions vcs-svn/fast_export.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#ifndef FAST_EXPORT_H_
#define FAST_EXPORT_H_

#include "line_buffer.h"
struct strbuf;
struct line_buffer;

void fast_export_init(int fd);
void fast_export_deinit(void);
void fast_export_reset(void);

void fast_export_delete(uint32_t depth, uint32_t *path);
void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
uint32_t mark);
void fast_export_begin_commit(uint32_t revision);
void fast_export_commit(uint32_t revision, uint32_t author, char *log,
void fast_export_delete(uint32_t depth, const uint32_t *path);
void fast_export_modify(uint32_t depth, const uint32_t *path,
uint32_t mode, const char *dataref);
void fast_export_begin_commit(uint32_t revision, uint32_t author, char *log,
uint32_t uuid, uint32_t url, unsigned long timestamp);
void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len,
struct line_buffer *input);
void fast_export_end_commit(uint32_t revision);
void fast_export_data(uint32_t mode, uint32_t len, struct line_buffer *input);

/* If there is no such file at that rev, returns -1, errno == ENOENT. */
int fast_export_ls_rev(uint32_t rev, uint32_t depth, const uint32_t *path,
uint32_t *mode_out, struct strbuf *dataref_out);
int fast_export_ls(uint32_t depth, const uint32_t *path,
uint32_t *mode_out, struct strbuf *dataref_out);

#endif
Loading

0 comments on commit 723b7a2

Please sign in to comment.