Skip to content

Commit 43155cf

Browse files
barrbrainjrn
authored andcommitted
vcs-svn: avoid using ls command twice
Currently there are two functions to retrieve the mode and content at a path: const char *repo_read_path(const uint32_t *path); uint32_t repo_read_mode(const uint32_t *path) Replace them with a single function with two return values. This means we can use one round-trip to get the same information from fast-import that previously took two. Signed-off-by: David Barr <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]>
1 parent dd3f42a commit 43155cf

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

vcs-svn/repo_tree.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,23 @@
88
#include "repo_tree.h"
99
#include "fast_export.h"
1010

11-
const char *repo_read_path(const uint32_t *path)
11+
const char *repo_read_path(const uint32_t *path, uint32_t *mode_out)
1212
{
1313
int err;
14-
uint32_t dummy;
1514
static struct strbuf buf = STRBUF_INIT;
1615

1716
strbuf_reset(&buf);
18-
err = fast_export_ls(REPO_MAX_PATH_DEPTH, path, &dummy, &buf);
17+
err = fast_export_ls(REPO_MAX_PATH_DEPTH, path, mode_out, &buf);
1918
if (err) {
2019
if (errno != ENOENT)
2120
die_errno("BUG: unexpected fast_export_ls error");
21+
/* Treat missing paths as directories. */
22+
*mode_out = REPO_MODE_DIR;
2223
return NULL;
2324
}
2425
return buf.buf;
2526
}
2627

27-
uint32_t repo_read_mode(const uint32_t *path)
28-
{
29-
int err;
30-
uint32_t result;
31-
static struct strbuf dummy = STRBUF_INIT;
32-
33-
strbuf_reset(&dummy);
34-
err = fast_export_ls(REPO_MAX_PATH_DEPTH, path, &result, &dummy);
35-
if (err) {
36-
if (errno != ENOENT)
37-
die_errno("BUG: unexpected fast_export_ls error");
38-
/* Treat missing paths as directories. */
39-
return REPO_MODE_DIR;
40-
}
41-
return result;
42-
}
43-
4428
void repo_copy(uint32_t revision, const uint32_t *src, const uint32_t *dst)
4529
{
4630
int err;

vcs-svn/repo_tree.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
uint32_t next_blob_mark(void);
1515
void repo_copy(uint32_t revision, const uint32_t *src, const uint32_t *dst);
1616
void repo_add(uint32_t *path, uint32_t mode, uint32_t blob_mark);
17-
const char *repo_read_path(const uint32_t *path);
18-
uint32_t repo_read_mode(const uint32_t *path);
17+
const char *repo_read_path(const uint32_t *path, uint32_t *mode_out);
1918
void repo_delete(uint32_t *path);
2019
void repo_commit(uint32_t revision, uint32_t author, char *log, uint32_t uuid,
2120
uint32_t url, long unsigned timestamp);

vcs-svn/svndump.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ static void handle_node(void)
246246
old_data = NULL;
247247
} else if (node_ctx.action == NODEACT_CHANGE) {
248248
uint32_t mode;
249-
old_data = repo_read_path(node_ctx.dst);
250-
mode = repo_read_mode(node_ctx.dst);
249+
old_data = repo_read_path(node_ctx.dst, &mode);
251250
if (mode == REPO_MODE_DIR && type != REPO_MODE_DIR)
252251
die("invalid dump: cannot modify a directory into a file");
253252
if (mode != REPO_MODE_DIR && type == REPO_MODE_DIR)

0 commit comments

Comments
 (0)