@matheusbsbs / matheus-bagliano / commits / 43155cfe14
Fork 0

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 <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

David Barr committed Dec 13, 2010 at 17:09 UTC 43155cfe1415f5547791613a5de6399112ba3560
3 files changed +6 -24
vcs-svn/repo_tree.c
+4 -20
@@ -8,39 +8,23 @@
8 #include "repo_tree.h"
9 #include "fast_export.h"
10
11 -const char *repo_read_path(const uint32_t *path)
11 +const char *repo_read_path(const uint32_t *path, uint32_t *mode_out)
12 {
13 int err;
14 - uint32_t dummy;
14 static struct strbuf buf = STRBUF_INIT;
15
16 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);
18 if (err) {
19 if (errno != ENOENT)
20 die_errno("BUG: unexpected fast_export_ls error");
21 + /* Treat missing paths as directories. */
22 + *mode_out = REPO_MODE_DIR;
23 return NULL;
24 }
25 return buf.buf;
26 }
27
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 -
28 void repo_copy(uint32_t revision, const uint32_t *src, const uint32_t *dst)
29 {
30 int err;
vcs-svn/repo_tree.h
+1 -2
@@ -14,8 +14,7 @@
14 uint32_t next_blob_mark(void);
15 void repo_copy(uint32_t revision, const uint32_t *src, const uint32_t *dst);
16 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);
18 void repo_delete(uint32_t *path);
19 void repo_commit(uint32_t revision, uint32_t author, char *log, uint32_t uuid,
20 uint32_t url, long unsigned timestamp);
vcs-svn/svndump.c
+1 -2
@@ -246,8 +246,7 @@ static void handle_node(void)
246 old_data = NULL;
247 } else if (node_ctx.action == NODEACT_CHANGE) {
248 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);
250 if (mode == REPO_MODE_DIR && type != REPO_MODE_DIR)
251 die("invalid dump: cannot modify a directory into a file");
252 if (mode != REPO_MODE_DIR && type == REPO_MODE_DIR)