Fossil SCM

Make sure that pending deletes from "fossil rm" operations are preserved across a "fossil update".

drh 2012-11-06 19:42 trunk
Commit 28272fa125bb160cad334e47d5c3e10ae5349208
+17 -7
--- src/update.c
+++ src/update.c
@@ -217,19 +217,20 @@
217217
" islinkv BOOLEAN," /* True if current file is a link */
218218
" islinkt BOOLEAN," /* True if target file is a link */
219219
" ridv INTEGER," /* Record ID for current version */
220220
" ridt INTEGER," /* Record ID for target */
221221
" isexe BOOLEAN," /* Does target have execute permission? */
222
+ " deleted BOOLEAN DEFAULT 0,"/* File marke by "rm" to become unmanaged */
222223
" fnt TEXT" /* Filename of same file on target version */
223224
");"
224225
);
225226
226227
/* Add files found in the current version
227228
*/
228229
db_multi_exec(
229
- "INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged)"
230
- " SELECT pathname, pathname, id, 0, rid, 0, isexe, chnged"
230
+ "INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged,deleted)"
231
+ " SELECT pathname, pathname, id, 0, rid, 0, isexe, chnged, deleted"
231232
" FROM vfile WHERE vid=%d",
232233
vid
233234
);
234235
235236
/* Compute file name changes on V->T. Record name changes in files that
@@ -339,11 +340,11 @@
339340
** Alter the content of the checkout so that it conforms with the
340341
** target
341342
*/
342343
db_prepare(&q,
343344
"SELECT fn, idv, ridv, idt, ridt, chnged, fnt,"
344
- " isexe, islinkv, islinkt FROM fv ORDER BY 1"
345
+ " isexe, islinkv, islinkt, deleted FROM fv ORDER BY 1"
345346
);
346347
db_prepare(&mtimeXfer,
347348
"UPDATE vfile SET mtime=(SELECT mtime FROM vfile WHERE id=:idv)"
348349
" WHERE id=:idt"
349350
);
@@ -359,43 +360,52 @@
359360
int chnged = db_column_int(&q, 5); /* Current is edited */
360361
const char *zNewName = db_column_text(&q,6);/* New filename */
361362
int isexe = db_column_int(&q, 7); /* EXE perm for new file */
362363
int islinkv = db_column_int(&q, 8); /* Is current file is a link */
363364
int islinkt = db_column_int(&q, 9); /* Is target file is a link */
365
+ int deleted = db_column_int(&q, 10); /* Marked for deletion */
364366
char *zFullPath; /* Full pathname of the file */
365367
char *zFullNewPath; /* Full pathname of dest */
366368
char nameChng; /* True if the name changed */
367369
368370
zFullPath = mprintf("%s%s", g.zLocalRoot, zName);
369371
zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
370372
nameChng = fossil_strcmp(zName, zNewName);
371373
nUpdate++;
374
+ if( deleted ){
375
+ db_multi_exec("UPDATE vfile SET deleted=1 WHERE id=%d", idt);
376
+ }
372377
if( idv>0 && ridv==0 && idt>0 && ridt>0 ){
373378
/* Conflict. This file has been added to the current checkout
374379
** but also exists in the target checkout. Use the current version.
375380
*/
376381
fossil_print("CONFLICT %s\n", zName);
377382
nConflict++;
378383
}else if( idt>0 && idv==0 ){
379384
/* File added in the target. */
380385
if( file_wd_isfile_or_link(zFullPath) ){
381
- fossil_print("ADD %s (overwrites an unmanaged file)\n", zName);
386
+ fossil_print("ADD %s - overwrites an unmanaged file\n", zName);
382387
nOverwrite++;
383388
}else{
384389
fossil_print("ADD %s\n", zName);
385390
}
386391
undo_save(zName);
387392
if( !nochangeFlag ) vfile_to_disk(0, idt, 0, 0);
388
- }else if( idt>0 && idv>0 && ridt!=ridv && chnged==0 ){
393
+ }else if( idt>0 && idv>0 && ridt!=ridv && (chnged==0 || deleted) ){
389394
/* The file is unedited. Change it to the target version */
390395
undo_save(zName);
391
- fossil_print("UPDATE %s\n", zName);
396
+ if( deleted ){
397
+ fossil_print("UPDATE %s - change to unmanged file\n", zName);
398
+ }else{
399
+ fossil_print("UPDATE %s\n", zName);
400
+ }
392401
if( !nochangeFlag ) vfile_to_disk(0, idt, 0, 0);
393402
}else if( idt>0 && idv>0 && file_wd_size(zFullPath)<0 ){
394403
/* The file missing from the local check-out. Restore it to the
395404
** version that appears in the target. */
396
- fossil_print("UPDATE %s\n", zName);
405
+ fossil_print("UPDATE %s%s\n", zName,
406
+ deleted?" - change to unmanaged file":"");
397407
undo_save(zName);
398408
if( !nochangeFlag ) vfile_to_disk(0, idt, 0, 0);
399409
}else if( idt==0 && idv>0 ){
400410
if( ridv==0 ){
401411
/* Added in current checkout. Continue to hold the file as
402412
403413
ADDED test/update-test-1.sh
404414
ADDED test/update-test-2.sh
--- src/update.c
+++ src/update.c
@@ -217,19 +217,20 @@
217 " islinkv BOOLEAN," /* True if current file is a link */
218 " islinkt BOOLEAN," /* True if target file is a link */
219 " ridv INTEGER," /* Record ID for current version */
220 " ridt INTEGER," /* Record ID for target */
221 " isexe BOOLEAN," /* Does target have execute permission? */
 
222 " fnt TEXT" /* Filename of same file on target version */
223 ");"
224 );
225
226 /* Add files found in the current version
227 */
228 db_multi_exec(
229 "INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged)"
230 " SELECT pathname, pathname, id, 0, rid, 0, isexe, chnged"
231 " FROM vfile WHERE vid=%d",
232 vid
233 );
234
235 /* Compute file name changes on V->T. Record name changes in files that
@@ -339,11 +340,11 @@
339 ** Alter the content of the checkout so that it conforms with the
340 ** target
341 */
342 db_prepare(&q,
343 "SELECT fn, idv, ridv, idt, ridt, chnged, fnt,"
344 " isexe, islinkv, islinkt FROM fv ORDER BY 1"
345 );
346 db_prepare(&mtimeXfer,
347 "UPDATE vfile SET mtime=(SELECT mtime FROM vfile WHERE id=:idv)"
348 " WHERE id=:idt"
349 );
@@ -359,43 +360,52 @@
359 int chnged = db_column_int(&q, 5); /* Current is edited */
360 const char *zNewName = db_column_text(&q,6);/* New filename */
361 int isexe = db_column_int(&q, 7); /* EXE perm for new file */
362 int islinkv = db_column_int(&q, 8); /* Is current file is a link */
363 int islinkt = db_column_int(&q, 9); /* Is target file is a link */
 
364 char *zFullPath; /* Full pathname of the file */
365 char *zFullNewPath; /* Full pathname of dest */
366 char nameChng; /* True if the name changed */
367
368 zFullPath = mprintf("%s%s", g.zLocalRoot, zName);
369 zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
370 nameChng = fossil_strcmp(zName, zNewName);
371 nUpdate++;
 
 
 
372 if( idv>0 && ridv==0 && idt>0 && ridt>0 ){
373 /* Conflict. This file has been added to the current checkout
374 ** but also exists in the target checkout. Use the current version.
375 */
376 fossil_print("CONFLICT %s\n", zName);
377 nConflict++;
378 }else if( idt>0 && idv==0 ){
379 /* File added in the target. */
380 if( file_wd_isfile_or_link(zFullPath) ){
381 fossil_print("ADD %s (overwrites an unmanaged file)\n", zName);
382 nOverwrite++;
383 }else{
384 fossil_print("ADD %s\n", zName);
385 }
386 undo_save(zName);
387 if( !nochangeFlag ) vfile_to_disk(0, idt, 0, 0);
388 }else if( idt>0 && idv>0 && ridt!=ridv && chnged==0 ){
389 /* The file is unedited. Change it to the target version */
390 undo_save(zName);
391 fossil_print("UPDATE %s\n", zName);
 
 
 
 
392 if( !nochangeFlag ) vfile_to_disk(0, idt, 0, 0);
393 }else if( idt>0 && idv>0 && file_wd_size(zFullPath)<0 ){
394 /* The file missing from the local check-out. Restore it to the
395 ** version that appears in the target. */
396 fossil_print("UPDATE %s\n", zName);
 
397 undo_save(zName);
398 if( !nochangeFlag ) vfile_to_disk(0, idt, 0, 0);
399 }else if( idt==0 && idv>0 ){
400 if( ridv==0 ){
401 /* Added in current checkout. Continue to hold the file as
402
403 DDED test/update-test-1.sh
404 DDED test/update-test-2.sh
--- src/update.c
+++ src/update.c
@@ -217,19 +217,20 @@
217 " islinkv BOOLEAN," /* True if current file is a link */
218 " islinkt BOOLEAN," /* True if target file is a link */
219 " ridv INTEGER," /* Record ID for current version */
220 " ridt INTEGER," /* Record ID for target */
221 " isexe BOOLEAN," /* Does target have execute permission? */
222 " deleted BOOLEAN DEFAULT 0,"/* File marke by "rm" to become unmanaged */
223 " fnt TEXT" /* Filename of same file on target version */
224 ");"
225 );
226
227 /* Add files found in the current version
228 */
229 db_multi_exec(
230 "INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged,deleted)"
231 " SELECT pathname, pathname, id, 0, rid, 0, isexe, chnged, deleted"
232 " FROM vfile WHERE vid=%d",
233 vid
234 );
235
236 /* Compute file name changes on V->T. Record name changes in files that
@@ -339,11 +340,11 @@
340 ** Alter the content of the checkout so that it conforms with the
341 ** target
342 */
343 db_prepare(&q,
344 "SELECT fn, idv, ridv, idt, ridt, chnged, fnt,"
345 " isexe, islinkv, islinkt, deleted FROM fv ORDER BY 1"
346 );
347 db_prepare(&mtimeXfer,
348 "UPDATE vfile SET mtime=(SELECT mtime FROM vfile WHERE id=:idv)"
349 " WHERE id=:idt"
350 );
@@ -359,43 +360,52 @@
360 int chnged = db_column_int(&q, 5); /* Current is edited */
361 const char *zNewName = db_column_text(&q,6);/* New filename */
362 int isexe = db_column_int(&q, 7); /* EXE perm for new file */
363 int islinkv = db_column_int(&q, 8); /* Is current file is a link */
364 int islinkt = db_column_int(&q, 9); /* Is target file is a link */
365 int deleted = db_column_int(&q, 10); /* Marked for deletion */
366 char *zFullPath; /* Full pathname of the file */
367 char *zFullNewPath; /* Full pathname of dest */
368 char nameChng; /* True if the name changed */
369
370 zFullPath = mprintf("%s%s", g.zLocalRoot, zName);
371 zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
372 nameChng = fossil_strcmp(zName, zNewName);
373 nUpdate++;
374 if( deleted ){
375 db_multi_exec("UPDATE vfile SET deleted=1 WHERE id=%d", idt);
376 }
377 if( idv>0 && ridv==0 && idt>0 && ridt>0 ){
378 /* Conflict. This file has been added to the current checkout
379 ** but also exists in the target checkout. Use the current version.
380 */
381 fossil_print("CONFLICT %s\n", zName);
382 nConflict++;
383 }else if( idt>0 && idv==0 ){
384 /* File added in the target. */
385 if( file_wd_isfile_or_link(zFullPath) ){
386 fossil_print("ADD %s - overwrites an unmanaged file\n", zName);
387 nOverwrite++;
388 }else{
389 fossil_print("ADD %s\n", zName);
390 }
391 undo_save(zName);
392 if( !nochangeFlag ) vfile_to_disk(0, idt, 0, 0);
393 }else if( idt>0 && idv>0 && ridt!=ridv && (chnged==0 || deleted) ){
394 /* The file is unedited. Change it to the target version */
395 undo_save(zName);
396 if( deleted ){
397 fossil_print("UPDATE %s - change to unmanged file\n", zName);
398 }else{
399 fossil_print("UPDATE %s\n", zName);
400 }
401 if( !nochangeFlag ) vfile_to_disk(0, idt, 0, 0);
402 }else if( idt>0 && idv>0 && file_wd_size(zFullPath)<0 ){
403 /* The file missing from the local check-out. Restore it to the
404 ** version that appears in the target. */
405 fossil_print("UPDATE %s%s\n", zName,
406 deleted?" - change to unmanaged file":"");
407 undo_save(zName);
408 if( !nochangeFlag ) vfile_to_disk(0, idt, 0, 0);
409 }else if( idt==0 && idv>0 ){
410 if( ridv==0 ){
411 /* Added in current checkout. Continue to hold the file as
412
413 DDED test/update-test-1.sh
414 DDED test/update-test-2.sh
--- a/test/update-test-1.sh
+++ b/test/update-test-1.sh
@@ -0,0 +1,44 @@
1
+#!/bin/sh
2
+#
3
+# Run this script in an empty directory. A single argument is the full
4
+# pathname of the fossil binary. Example:
5
+#
6
+# sh update-test-1.sh /home/drh/fossil/m1/fossil
7
+#
8
+export FOSSIL=$1
9
+rm -rf aaa bbb update-test-1.fossil
10
+
11
+# Create a test repository
12
+$FOSSIL new update-test-1.fossil
13
+
14
+# In checkout aaa, add file one.txt
15
+mkdir aaa
16
+cd aaa
17
+$FOSSIL open ../update-test-1.fossil
18
+echo one >one.txt
19
+$FOSSIL add one.txt
20
+$FOSSIL commit -m add-one --tag add-one
21
+
22
+# Open checkout bbb.
23
+mkdir ../bbb
24
+cd ../bbb
25
+$FOSSIL open ../update-test-1.fossil
26
+
27
+# Back in aaa, add file two.txt
28
+cd ../aaa
29
+echo two >two.txt
30
+$FOSSIL add two.txt
31
+$FOSSIL commit -m add-two --tag add-two
32
+
33
+# In bbb, delete file one.txt. Then update the change from aaa that
34
+# adds file two. Verify that one.txt says deleted.
35
+cd ../bbb
36
+$FOSSIL rm one.txt
37
+$FOSSIL changes
38
+echo '========================================================================'
39
+$FOSSIL update
40
+echo '======== The previous should show "ADD two.txt" ========================'
41
+$FOSSIL changes
42
+echo '======== The previous should show "DELETE one.txt" ====================='
43
+$FOSSIL commit --test -m check-in
44
+echo '======== Only file two.txt is checked in ==============================='
--- a/test/update-test-1.sh
+++ b/test/update-test-1.sh
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/update-test-1.sh
+++ b/test/update-test-1.sh
@@ -0,0 +1,44 @@
1 #!/bin/sh
2 #
3 # Run this script in an empty directory. A single argument is the full
4 # pathname of the fossil binary. Example:
5 #
6 # sh update-test-1.sh /home/drh/fossil/m1/fossil
7 #
8 export FOSSIL=$1
9 rm -rf aaa bbb update-test-1.fossil
10
11 # Create a test repository
12 $FOSSIL new update-test-1.fossil
13
14 # In checkout aaa, add file one.txt
15 mkdir aaa
16 cd aaa
17 $FOSSIL open ../update-test-1.fossil
18 echo one >one.txt
19 $FOSSIL add one.txt
20 $FOSSIL commit -m add-one --tag add-one
21
22 # Open checkout bbb.
23 mkdir ../bbb
24 cd ../bbb
25 $FOSSIL open ../update-test-1.fossil
26
27 # Back in aaa, add file two.txt
28 cd ../aaa
29 echo two >two.txt
30 $FOSSIL add two.txt
31 $FOSSIL commit -m add-two --tag add-two
32
33 # In bbb, delete file one.txt. Then update the change from aaa that
34 # adds file two. Verify that one.txt says deleted.
35 cd ../bbb
36 $FOSSIL rm one.txt
37 $FOSSIL changes
38 echo '========================================================================'
39 $FOSSIL update
40 echo '======== The previous should show "ADD two.txt" ========================'
41 $FOSSIL changes
42 echo '======== The previous should show "DELETE one.txt" ====================='
43 $FOSSIL commit --test -m check-in
44 echo '======== Only file two.txt is checked in ==============================='
--- a/test/update-test-2.sh
+++ b/test/update-test-2.sh
@@ -0,0 +1,44 @@
1
+#!/bin/sh
2
+#
3
+# Run this script in an empty directory. A single argument is the full
4
+# pathname of the fossil binary. Example:
5
+#
6
+# sh update-test-2.sh /home/drh/fossil/m1/fossil
7
+#
8
+export FOSSIL=$1
9
+rm -rf aaa bbb update-test-2.fossil
10
+
11
+# Create a test repository
12
+$FOSSIL new update-test-2.fossil
13
+
14
+# In checkout aaa, add file one.txt.
15
+mkdir aaa
16
+cd aaa
17
+$FOSSIL open ../update-test-2.fossil
18
+echo one >one.txt
19
+$FOSSIL add one.txt
20
+$FOSSIL commit -m add-one --tag add-one
21
+
22
+# Create checkout bbb.
23
+mkdir ../bbb
24
+cd ../bbb
25
+$FOSSIL open ../update-test-2.fossil
26
+
27
+# Back in aaa, make changes to one.txt. Add file two.txt.
28
+cd ../aaa
29
+echo change >>one.txt
30
+echo two >two.txt
31
+$FOSSIL add two.txt
32
+$FOSSIL commit -m 'chng one and add two' --tag add-two
33
+
34
+# In bbb, remove one.txt, then update.
35
+cd ../bbb
36
+$FOSSIL rm one.txt
37
+$FOSSIL changes
38
+echo '========================================================================'
39
+$FOSSIL update
40
+echo '======== Previous should show "ADD two.txt" and conflict on one.txt ===='
41
+$FOSSIL changes
42
+echo '======== The previous should show "DELETE one.txt" ====================='
43
+$FOSSIL commit --test -m 'check-in'
44
+echo '======== Only file two.txt is checked in ==============================='
--- a/test/update-test-2.sh
+++ b/test/update-test-2.sh
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/update-test-2.sh
+++ b/test/update-test-2.sh
@@ -0,0 +1,44 @@
1 #!/bin/sh
2 #
3 # Run this script in an empty directory. A single argument is the full
4 # pathname of the fossil binary. Example:
5 #
6 # sh update-test-2.sh /home/drh/fossil/m1/fossil
7 #
8 export FOSSIL=$1
9 rm -rf aaa bbb update-test-2.fossil
10
11 # Create a test repository
12 $FOSSIL new update-test-2.fossil
13
14 # In checkout aaa, add file one.txt.
15 mkdir aaa
16 cd aaa
17 $FOSSIL open ../update-test-2.fossil
18 echo one >one.txt
19 $FOSSIL add one.txt
20 $FOSSIL commit -m add-one --tag add-one
21
22 # Create checkout bbb.
23 mkdir ../bbb
24 cd ../bbb
25 $FOSSIL open ../update-test-2.fossil
26
27 # Back in aaa, make changes to one.txt. Add file two.txt.
28 cd ../aaa
29 echo change >>one.txt
30 echo two >two.txt
31 $FOSSIL add two.txt
32 $FOSSIL commit -m 'chng one and add two' --tag add-two
33
34 # In bbb, remove one.txt, then update.
35 cd ../bbb
36 $FOSSIL rm one.txt
37 $FOSSIL changes
38 echo '========================================================================'
39 $FOSSIL update
40 echo '======== Previous should show "ADD two.txt" and conflict on one.txt ===='
41 $FOSSIL changes
42 echo '======== The previous should show "DELETE one.txt" ====================='
43 $FOSSIL commit --test -m 'check-in'
44 echo '======== Only file two.txt is checked in ==============================='

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button