@matheusbsbs / matheus-bagliano / commits / 08c39b5c44
Fork 0

vcs-svn: Combine repo_replace and repo_modify functions

There are two functions to change the staged content for a path in the svn importer's active commit: repo_replace, which changes the text and returns the mode, and repo_modify, which changes the text and mode and returns nothing. Worse, there are more subtle differences: - A mark of 0 passed to repo_modify means "use the existing content". repo_replace uses it as mark :0 and produces a corrupt stream. - When passed a path that is not part of the active commit, repo_replace returns without doing anything. repo_modify transparently adds a new directory entry. Get rid of both and introduce a new function with the best features of both: repo_modify_path modifies the mode, content, or both for a path, depending on which arguments are zero. If no such dirent already exists, it does nothing and reports the error by returning 0. Otherwise, the return value is the resulting mode. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Nov 19, 2010 at 18:51 UTC 08c39b5c44449cb649ac32274e27be8046e373d4
3 files changed +12 -20
vcs-svn/repo_tree.c
+7 -14
@@ -175,25 +175,18 @@ void repo_add(uint32_t *path, uint32_t mode, uint32_t blob_mark)
175 repo_write_dirent(path, mode, blob_mark, 0);
176 }
177
178 -uint32_t repo_replace(uint32_t *path, uint32_t blob_mark)
178 +uint32_t repo_modify_path(uint32_t *path, uint32_t mode, uint32_t blob_mark)
179 {
180 - uint32_t mode = 0;
180 struct repo_dirent *src_dent;
181 src_dent = repo_read_dirent(active_commit, path);
183 - if (src_dent != NULL) {
184 - mode = src_dent->mode;
185 - repo_write_dirent(path, mode, blob_mark, 0);
186 - }
187 - return mode;
188 -}
189 -
190 -void repo_modify(uint32_t *path, uint32_t mode, uint32_t blob_mark)
191 -{
192 - struct repo_dirent *src_dent;
193 - src_dent = repo_read_dirent(active_commit, path);
194 - if (src_dent != NULL && blob_mark == 0)
182 + if (!src_dent)
183 + return 0;
184 + if (!blob_mark)
185 blob_mark = src_dent->content_offset;
186 + if (!mode)
187 + mode = src_dent->mode;
188 repo_write_dirent(path, mode, blob_mark, 0);
189 + return mode;
190 }
191
192 void repo_delete(uint32_t *path)
vcs-svn/repo_tree.h
+1 -2
@@ -14,8 +14,7 @@
14 uint32_t next_blob_mark(void);
15 uint32_t repo_copy(uint32_t revision, uint32_t *src, uint32_t *dst);
16 void repo_add(uint32_t *path, uint32_t mode, uint32_t blob_mark);
17 -uint32_t repo_replace(uint32_t *path, uint32_t blob_mark);
18 -void repo_modify(uint32_t *path, uint32_t mode, uint32_t blob_mark);
17 +uint32_t repo_modify_path(uint32_t *path, uint32_t mode, uint32_t blob_mark);
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
+4 -4
@@ -182,14 +182,14 @@ static void handle_node(void)
182
183 if (node_ctx.action == NODEACT_CHANGE) {
184 if (have_props)
185 - repo_modify(node_ctx.dst, node_ctx.type, mark);
185 + repo_modify_path(node_ctx.dst, node_ctx.type, mark);
186 else if (mark)
187 - old_mode = repo_replace(node_ctx.dst, mark);
187 + old_mode = repo_modify_path(node_ctx.dst, 0, mark);
188 } else if (node_ctx.action == NODEACT_ADD) {
189 if (node_ctx.srcRev && have_props)
190 - repo_modify(node_ctx.dst, node_ctx.type, mark);
190 + repo_modify_path(node_ctx.dst, node_ctx.type, mark);
191 else if (node_ctx.srcRev && mark)
192 - old_mode = repo_replace(node_ctx.dst, mark);
192 + old_mode = repo_modify_path(node_ctx.dst, 0, mark);
193 else if ((node_ctx.type == REPO_MODE_DIR && !node_ctx.srcRev) ||
194 mark)
195 repo_add(node_ctx.dst, node_ctx.type, mark);