@matheusbsbs / matheus-bagliano / commits / 1d13e9f600
Fork 0

vcs-svn: Eliminate node_ctx.srcRev global

The srcRev variable is only used in handle_node(); its purpose is to hold the old mode for a path, to only be used if properties are not being changed. Narrow its scope to make its meaningful lifetime more obvious. No functional change intended. Add some tests as a sanity-check for the simplest case (no renames). 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:46 UTC 1d13e9f600986b7ced8db37a9a9c4967ee7ff9d5
2 files changed +166 -7
t/t9010-svn-fe.sh
+158
@@ -252,6 +252,164 @@ test_expect_success 'directory with files' '
252 test_cmp hi directory/file2
253 '
254
255 +test_expect_failure 'change file mode but keep old content' '
256 + reinit_git &&
257 + cat >expect <<-\EOF &&
258 + OBJID
259 + :120000 100644 OBJID OBJID T greeting
260 + OBJID
261 + :100644 120000 OBJID OBJID T greeting
262 + OBJID
263 + :000000 100644 OBJID OBJID A greeting
264 + EOF
265 + echo "link hello" >expect.blob &&
266 + echo hello >hello &&
267 + cat >filemode.dump <<-\EOF &&
268 + SVN-fs-dump-format-version: 3
269 +
270 + Revision-number: 1
271 + Prop-content-length: 10
272 + Content-length: 10
273 +
274 + PROPS-END
275 +
276 + Node-path: greeting
277 + Node-kind: file
278 + Node-action: add
279 + Prop-content-length: 10
280 + Text-content-length: 11
281 + Content-length: 21
282 +
283 + PROPS-END
284 + link hello
285 +
286 + Revision-number: 2
287 + Prop-content-length: 10
288 + Content-length: 10
289 +
290 + PROPS-END
291 +
292 + Node-path: greeting
293 + Node-kind: file
294 + Node-action: change
295 + Prop-content-length: 33
296 + Content-length: 33
297 +
298 + K 11
299 + svn:special
300 + V 1
301 + *
302 + PROPS-END
303 +
304 + Revision-number: 3
305 + Prop-content-length: 10
306 + Content-length: 10
307 +
308 + PROPS-END
309 +
310 + Node-path: greeting
311 + Node-kind: file
312 + Node-action: change
313 + Prop-content-length: 10
314 + Content-length: 10
315 +
316 + PROPS-END
317 + EOF
318 + test-svn-fe filemode.dump >stream &&
319 + git fast-import <stream &&
320 + {
321 + git rev-list HEAD |
322 + git diff-tree --root --stdin |
323 + sed "s/$_x40/OBJID/g"
324 + } >actual &&
325 + git show HEAD:greeting >actual.blob &&
326 + git show HEAD^:greeting >actual.target &&
327 + test_cmp expect actual &&
328 + test_cmp expect.blob actual.blob &&
329 + test_cmp hello actual.target
330 +'
331 +
332 +test_expect_success 'change file mode and reiterate content' '
333 + reinit_git &&
334 + cat >expect <<-\EOF &&
335 + OBJID
336 + :120000 100644 OBJID OBJID T greeting
337 + OBJID
338 + :100644 120000 OBJID OBJID T greeting
339 + OBJID
340 + :000000 100644 OBJID OBJID A greeting
341 + EOF
342 + echo "link hello" >expect.blob &&
343 + echo hello >hello &&
344 + cat >filemode.dump <<-\EOF &&
345 + SVN-fs-dump-format-version: 3
346 +
347 + Revision-number: 1
348 + Prop-content-length: 10
349 + Content-length: 10
350 +
351 + PROPS-END
352 +
353 + Node-path: greeting
354 + Node-kind: file
355 + Node-action: add
356 + Prop-content-length: 10
357 + Text-content-length: 11
358 + Content-length: 21
359 +
360 + PROPS-END
361 + link hello
362 +
363 + Revision-number: 2
364 + Prop-content-length: 10
365 + Content-length: 10
366 +
367 + PROPS-END
368 +
369 + Node-path: greeting
370 + Node-kind: file
371 + Node-action: change
372 + Prop-content-length: 33
373 + Text-content-length: 11
374 + Content-length: 44
375 +
376 + K 11
377 + svn:special
378 + V 1
379 + *
380 + PROPS-END
381 + link hello
382 +
383 + Revision-number: 3
384 + Prop-content-length: 10
385 + Content-length: 10
386 +
387 + PROPS-END
388 +
389 + Node-path: greeting
390 + Node-kind: file
391 + Node-action: change
392 + Prop-content-length: 10
393 + Text-content-length: 11
394 + Content-length: 21
395 +
396 + PROPS-END
397 + link hello
398 + EOF
399 + test-svn-fe filemode.dump >stream &&
400 + git fast-import <stream &&
401 + {
402 + git rev-list HEAD |
403 + git diff-tree --root --stdin |
404 + sed "s/$_x40/OBJID/g"
405 + } >actual &&
406 + git show HEAD:greeting >actual.blob &&
407 + git show HEAD^:greeting >actual.target &&
408 + test_cmp expect actual &&
409 + test_cmp expect.blob actual.blob &&
410 + test_cmp hello actual.target
411 +'
412 +
413 test_expect_success 'deltas not supported' '
414 {
415 # (old) h + (inline) ello + (old) \n
vcs-svn/svndump.c
+8 -7
@@ -40,7 +40,7 @@ static char* log_copy(uint32_t length, char *log)
40 }
41
42 static struct {
43 - uint32_t action, propLength, textLength, srcRev, srcMode, mark, type;
43 + uint32_t action, propLength, textLength, srcRev, mark, type;
44 uint32_t src[REPO_MAX_PATH_DEPTH], dst[REPO_MAX_PATH_DEPTH];
45 uint32_t text_delta, prop_delta;
46 } node_ctx;
@@ -72,7 +72,6 @@ static void reset_node_ctx(char *fname)
72 node_ctx.textLength = LENGTH_UNKNOWN;
73 node_ctx.src[0] = ~0;
74 node_ctx.srcRev = 0;
75 - node_ctx.srcMode = 0;
75 pool_tok_seq(REPO_MAX_PATH_DEPTH, node_ctx.dst, "/", fname);
76 node_ctx.mark = 0;
77 node_ctx.text_delta = 0;
@@ -152,6 +151,8 @@ static void read_props(void)
151
152 static void handle_node(void)
153 {
154 + uint32_t old_mode = 0;
155 +
156 if (node_ctx.text_delta || node_ctx.prop_delta)
157 die("text and property deltas not supported");
158
@@ -159,7 +160,7 @@ static void handle_node(void)
160 read_props();
161
162 if (node_ctx.srcRev)
162 - node_ctx.srcMode = repo_copy(node_ctx.srcRev, node_ctx.src, node_ctx.dst);
163 + old_mode = repo_copy(node_ctx.srcRev, node_ctx.src, node_ctx.dst);
164
165 if (node_ctx.textLength != LENGTH_UNKNOWN &&
166 node_ctx.type != REPO_MODE_DIR)
@@ -175,19 +176,19 @@ static void handle_node(void)
176 else if (node_ctx.propLength != LENGTH_UNKNOWN)
177 repo_modify(node_ctx.dst, node_ctx.type, node_ctx.mark);
178 else if (node_ctx.textLength != LENGTH_UNKNOWN)
178 - node_ctx.srcMode = repo_replace(node_ctx.dst, node_ctx.mark);
179 + old_mode = repo_replace(node_ctx.dst, node_ctx.mark);
180 } else if (node_ctx.action == NODEACT_ADD) {
181 if (node_ctx.srcRev && node_ctx.propLength != LENGTH_UNKNOWN)
182 repo_modify(node_ctx.dst, node_ctx.type, node_ctx.mark);
183 else if (node_ctx.srcRev && node_ctx.textLength != LENGTH_UNKNOWN)
183 - node_ctx.srcMode = repo_replace(node_ctx.dst, node_ctx.mark);
184 + old_mode = repo_replace(node_ctx.dst, node_ctx.mark);
185 else if ((node_ctx.type == REPO_MODE_DIR && !node_ctx.srcRev) ||
186 node_ctx.textLength != LENGTH_UNKNOWN)
187 repo_add(node_ctx.dst, node_ctx.type, node_ctx.mark);
188 }
189
189 - if (node_ctx.propLength == LENGTH_UNKNOWN && node_ctx.srcMode)
190 - node_ctx.type = node_ctx.srcMode;
190 + if (node_ctx.propLength == LENGTH_UNKNOWN && old_mode)
191 + node_ctx.type = old_mode;
192
193 if (node_ctx.mark)
194 fast_export_blob(node_ctx.type, node_ctx.mark, node_ctx.textLength);