Skip to content

Commit

Permalink
Merge branch 'db/length-as-hash' (early part) into db/svn-fe-code-purge
Browse files Browse the repository at this point in the history
* 'db/length-as-hash' (early part):
  vcs-svn: implement perfect hash for top-level keys
  vcs-svn: implement perfect hash for node-prop keys
  vcs-svn: improve reporting of input errors
  vcs-svn: make buffer_copy_bytes return length read
  vcs-svn: make buffer_skip_bytes return length read
  vcs-svn: improve support for reading large files

Conflicts:
	vcs-svn/fast_export.c
	vcs-svn/svndump.c
  • Loading branch information
Jonathan Nieder committed Mar 22, 2011
2 parents dd3f42a + 90c0a3c commit 5c67486
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 93 deletions.
13 changes: 11 additions & 2 deletions vcs-svn/fast_export.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,24 @@ static const char *get_response_line(void)
die("unexpected end of fast-import feedback");
}

static void die_short_read(struct line_buffer *input)
{
if (buffer_ferror(input))
die_errno("error reading dump file");
die("invalid dump: unexpected end of file");
}

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;
if (buffer_skip_bytes(input, 5) != 5)
die_short_read(input);
}
printf("data %"PRIu32"\n", len);
buffer_copy_bytes(input, len);
if (buffer_copy_bytes(input, len) != len)
die_short_read(input);
fputc('\n', stdout);
}

Expand Down
31 changes: 16 additions & 15 deletions vcs-svn/line_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,32 @@ void buffer_read_binary(struct line_buffer *buf,
strbuf_fread(sb, size, buf->infile);
}

void buffer_copy_bytes(struct line_buffer *buf, uint32_t len)
off_t buffer_copy_bytes(struct line_buffer *buf, off_t nbytes)
{
char byte_buffer[COPY_BUFFER_LEN];
uint32_t in;
while (len > 0 && !feof(buf->infile) && !ferror(buf->infile)) {
in = len < COPY_BUFFER_LEN ? len : COPY_BUFFER_LEN;
off_t done = 0;
while (done < nbytes && !feof(buf->infile) && !ferror(buf->infile)) {
off_t len = nbytes - done;
size_t in = len < COPY_BUFFER_LEN ? len : COPY_BUFFER_LEN;
in = fread(byte_buffer, 1, in, buf->infile);
len -= in;
done += in;
fwrite(byte_buffer, 1, in, stdout);
if (ferror(stdout)) {
buffer_skip_bytes(buf, len);
return;
}
if (ferror(stdout))
return done + buffer_skip_bytes(buf, nbytes - done);
}
return done;
}

void buffer_skip_bytes(struct line_buffer *buf, uint32_t len)
off_t buffer_skip_bytes(struct line_buffer *buf, off_t nbytes)
{
char byte_buffer[COPY_BUFFER_LEN];
uint32_t in;
while (len > 0 && !feof(buf->infile) && !ferror(buf->infile)) {
in = len < COPY_BUFFER_LEN ? len : COPY_BUFFER_LEN;
in = fread(byte_buffer, 1, in, buf->infile);
len -= in;
off_t done = 0;
while (done < nbytes && !feof(buf->infile) && !ferror(buf->infile)) {
off_t len = nbytes - done;
size_t in = len < COPY_BUFFER_LEN ? len : COPY_BUFFER_LEN;
done += fread(byte_buffer, 1, in, buf->infile);
}
return done;
}

void buffer_reset(struct line_buffer *buf)
Expand Down
5 changes: 3 additions & 2 deletions vcs-svn/line_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ char *buffer_read_line(struct line_buffer *buf);
char *buffer_read_string(struct line_buffer *buf, uint32_t len);
int buffer_read_char(struct line_buffer *buf);
void buffer_read_binary(struct line_buffer *buf, struct strbuf *sb, uint32_t len);
void buffer_copy_bytes(struct line_buffer *buf, uint32_t len);
void buffer_skip_bytes(struct line_buffer *buf, uint32_t len);
/* Returns number of bytes read (not necessarily written). */
off_t buffer_copy_bytes(struct line_buffer *buf, off_t len);
off_t buffer_skip_bytes(struct line_buffer *buf, off_t len);

#endif
3 changes: 2 additions & 1 deletion vcs-svn/line_buffer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Functions

`buffer_skip_bytes`::
Discards `len` bytes from the input stream (stopping early
if necessary because of an error or eof).
if necessary because of an error or eof). Return value is
the number of bytes successfully read.

`buffer_reset`::
Deallocates non-static buffers.
Loading

0 comments on commit 5c67486

Please sign in to comment.