Fossil SCM

Fix the "revert" command so that it restores the correct execute permission to the file. Ticket [baf9b6b11e08c1]

drh 2011-02-27 21:45 trunk
Commit 3c39caac39b3d89e149accf25f7727c252e09e7d
3 files changed +3 -3 +1 -1 +16 -22
+3 -3
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -186,11 +186,11 @@
186186
int ignoreEolWs /* Ignore whitespace changes at end of lines */
187187
){
188188
Blob fname;
189189
Blob content;
190190
file_tree_name(g.argv[2], &fname, 1);
191
- historical_version_of_file(zFrom, blob_str(&fname), &content, 0);
191
+ historical_version_of_file(zFrom, blob_str(&fname), &content, 0, 0);
192192
diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
193193
blob_reset(&content);
194194
blob_reset(&fname);
195195
}
196196
@@ -308,12 +308,12 @@
308308
char *zName;
309309
Blob fname;
310310
Blob v1, v2;
311311
file_tree_name(g.argv[2], &fname, 1);
312312
zName = blob_str(&fname);
313
- historical_version_of_file(zFrom, zName, &v1, 0);
314
- historical_version_of_file(zTo, zName, &v2, 0);
313
+ historical_version_of_file(zFrom, zName, &v1, 0, 0);
314
+ historical_version_of_file(zTo, zName, &v2, 0, 0);
315315
diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
316316
blob_reset(&v1);
317317
blob_reset(&v2);
318318
blob_reset(&fname);
319319
}
320320
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -186,11 +186,11 @@
186 int ignoreEolWs /* Ignore whitespace changes at end of lines */
187 ){
188 Blob fname;
189 Blob content;
190 file_tree_name(g.argv[2], &fname, 1);
191 historical_version_of_file(zFrom, blob_str(&fname), &content, 0);
192 diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
193 blob_reset(&content);
194 blob_reset(&fname);
195 }
196
@@ -308,12 +308,12 @@
308 char *zName;
309 Blob fname;
310 Blob v1, v2;
311 file_tree_name(g.argv[2], &fname, 1);
312 zName = blob_str(&fname);
313 historical_version_of_file(zFrom, zName, &v1, 0);
314 historical_version_of_file(zTo, zName, &v2, 0);
315 diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
316 blob_reset(&v1);
317 blob_reset(&v2);
318 blob_reset(&fname);
319 }
320
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -186,11 +186,11 @@
186 int ignoreEolWs /* Ignore whitespace changes at end of lines */
187 ){
188 Blob fname;
189 Blob content;
190 file_tree_name(g.argv[2], &fname, 1);
191 historical_version_of_file(zFrom, blob_str(&fname), &content, 0, 0);
192 diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
193 blob_reset(&content);
194 blob_reset(&fname);
195 }
196
@@ -308,12 +308,12 @@
308 char *zName;
309 Blob fname;
310 Blob v1, v2;
311 file_tree_name(g.argv[2], &fname, 1);
312 zName = blob_str(&fname);
313 historical_version_of_file(zFrom, zName, &v1, 0, 0);
314 historical_version_of_file(zTo, zName, &v2, 0, 0);
315 diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
316 blob_reset(&v1);
317 blob_reset(&v2);
318 blob_reset(&fname);
319 }
320
+1 -1
--- src/finfo.c
+++ src/finfo.c
@@ -100,11 +100,11 @@
100100
Blob fname;
101101
const char *zRevision = find_option("revision", "r", 1);
102102
103103
file_tree_name(g.argv[2], &fname, 1);
104104
if( zRevision ){
105
- historical_version_of_file(zRevision, blob_str(&fname), &record, 0);
105
+ historical_version_of_file(zRevision, blob_str(&fname), &record, 0, 0);
106106
}else{
107107
int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
108108
if( rid==0 ){
109109
fossil_fatal("no history for file: %b", &fname);
110110
}
111111
--- src/finfo.c
+++ src/finfo.c
@@ -100,11 +100,11 @@
100 Blob fname;
101 const char *zRevision = find_option("revision", "r", 1);
102
103 file_tree_name(g.argv[2], &fname, 1);
104 if( zRevision ){
105 historical_version_of_file(zRevision, blob_str(&fname), &record, 0);
106 }else{
107 int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
108 if( rid==0 ){
109 fossil_fatal("no history for file: %b", &fname);
110 }
111
--- src/finfo.c
+++ src/finfo.c
@@ -100,11 +100,11 @@
100 Blob fname;
101 const char *zRevision = find_option("revision", "r", 1);
102
103 file_tree_name(g.argv[2], &fname, 1);
104 if( zRevision ){
105 historical_version_of_file(zRevision, blob_str(&fname), &record, 0, 0);
106 }else{
107 int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
108 if( rid==0 ){
109 fossil_fatal("no history for file: %b", &fname);
110 }
111
+16 -22
--- src/update.c
+++ src/update.c
@@ -449,10 +449,11 @@
449449
*/
450450
int historical_version_of_file(
451451
const char *revision, /* The checkin containing the file */
452452
const char *file, /* Full treename of the file */
453453
Blob *content, /* Put the content here */
454
+ int *pIsExe, /* Set to true if file is executable */
454455
int errCode /* Error code if file not found. Panic if 0. */
455456
){
456457
Manifest *pManifest;
457458
ManifestFile *pFile;
458459
int rid=0;
@@ -467,17 +468,16 @@
467468
fossil_fatal("no such checkin: %s", revision);
468469
}
469470
pManifest = manifest_get(rid, CFTYPE_MANIFEST);
470471
471472
if( pManifest ){
472
- manifest_file_rewind(pManifest);
473
- while( (pFile = manifest_file_next(pManifest,0))!=0 ){
474
- if( fossil_strcmp(pFile->zName, file)==0 ){
475
- rid = uuid_to_rid(pFile->zUuid, 0);
476
- manifest_destroy(pManifest);
477
- return content_get(rid, content);
478
- }
473
+ pFile = manifest_file_seek(pManifest, file);
474
+ if( pFile ){
475
+ rid = uuid_to_rid(pFile->zUuid, 0);
476
+ if( pIsExe ) *pIsExe = manifest_file_mperm(pFile);
477
+ manifest_destroy(pManifest);
478
+ return content_get(rid, content);
479479
}
480480
manifest_destroy(pManifest);
481481
if( errCode<=0 ){
482482
fossil_fatal("file %s does not exist in checkin: %s", file, revision);
483483
}
@@ -509,11 +509,10 @@
509509
const char *zFile;
510510
const char *zRevision;
511511
Blob record;
512512
int i;
513513
int errCode;
514
- int rid = 0;
515514
Stmt q;
516515
517516
undo_capture_command_line();
518517
zRevision = find_option("revision", "r", 1);
519518
verify_all_options();
@@ -549,39 +548,34 @@
549548
" WHERE chnged OR deleted OR rid=0 OR pathname!=origname;"
550549
);
551550
}
552551
blob_zero(&record);
553552
db_prepare(&q, "SELECT name FROM torevert");
553
+ if( zRevision==0 ){
554
+ int vid = db_lget_int("checkout", 0);
555
+ zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
556
+ }
554557
while( db_step(&q)==SQLITE_ROW ){
558
+ int isExe = 0;
555559
zFile = db_column_text(&q, 0);
556
- if( zRevision!=0 ){
557
- errCode = historical_version_of_file(zRevision, zFile, &record, 2);
558
- }else{
559
- rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFile);
560
- if( rid==0 ){
561
- errCode = 2;
562
- }else{
563
- content_get(rid, &record);
564
- errCode = 0;
565
- }
566
- }
567
-
560
+ errCode = historical_version_of_file(zRevision, zFile, &record, &isExe,2);
568561
if( errCode==2 ){
569562
fossil_warning("file not in repository: %s", zFile);
570563
}else{
571564
char *zFull = mprintf("%/%/", g.zLocalRoot, zFile);
572565
undo_save(zFile);
573566
blob_write_to_file(&record, zFull);
567
+ file_setexe(zFull, isExe);
574568
printf("REVERTED: %s\n", zFile);
575569
if( zRevision==0 ){
576570
sqlite3_int64 mtime = file_mtime(zFull);
577571
db_multi_exec(
578572
"UPDATE vfile"
579
- " SET mtime=%lld, chnged=0, deleted=0,"
573
+ " SET mtime=%lld, chnged=0, deleted=0, isexe=%d,"
580574
" pathname=coalesce(origname,pathname), origname=NULL"
581575
" WHERE pathname=%Q",
582
- mtime, zFile
576
+ mtime, isExe, zFile
583577
);
584578
}
585579
free(zFull);
586580
}
587581
blob_reset(&record);
588582
--- src/update.c
+++ src/update.c
@@ -449,10 +449,11 @@
449 */
450 int historical_version_of_file(
451 const char *revision, /* The checkin containing the file */
452 const char *file, /* Full treename of the file */
453 Blob *content, /* Put the content here */
 
454 int errCode /* Error code if file not found. Panic if 0. */
455 ){
456 Manifest *pManifest;
457 ManifestFile *pFile;
458 int rid=0;
@@ -467,17 +468,16 @@
467 fossil_fatal("no such checkin: %s", revision);
468 }
469 pManifest = manifest_get(rid, CFTYPE_MANIFEST);
470
471 if( pManifest ){
472 manifest_file_rewind(pManifest);
473 while( (pFile = manifest_file_next(pManifest,0))!=0 ){
474 if( fossil_strcmp(pFile->zName, file)==0 ){
475 rid = uuid_to_rid(pFile->zUuid, 0);
476 manifest_destroy(pManifest);
477 return content_get(rid, content);
478 }
479 }
480 manifest_destroy(pManifest);
481 if( errCode<=0 ){
482 fossil_fatal("file %s does not exist in checkin: %s", file, revision);
483 }
@@ -509,11 +509,10 @@
509 const char *zFile;
510 const char *zRevision;
511 Blob record;
512 int i;
513 int errCode;
514 int rid = 0;
515 Stmt q;
516
517 undo_capture_command_line();
518 zRevision = find_option("revision", "r", 1);
519 verify_all_options();
@@ -549,39 +548,34 @@
549 " WHERE chnged OR deleted OR rid=0 OR pathname!=origname;"
550 );
551 }
552 blob_zero(&record);
553 db_prepare(&q, "SELECT name FROM torevert");
 
 
 
 
554 while( db_step(&q)==SQLITE_ROW ){
 
555 zFile = db_column_text(&q, 0);
556 if( zRevision!=0 ){
557 errCode = historical_version_of_file(zRevision, zFile, &record, 2);
558 }else{
559 rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFile);
560 if( rid==0 ){
561 errCode = 2;
562 }else{
563 content_get(rid, &record);
564 errCode = 0;
565 }
566 }
567
568 if( errCode==2 ){
569 fossil_warning("file not in repository: %s", zFile);
570 }else{
571 char *zFull = mprintf("%/%/", g.zLocalRoot, zFile);
572 undo_save(zFile);
573 blob_write_to_file(&record, zFull);
 
574 printf("REVERTED: %s\n", zFile);
575 if( zRevision==0 ){
576 sqlite3_int64 mtime = file_mtime(zFull);
577 db_multi_exec(
578 "UPDATE vfile"
579 " SET mtime=%lld, chnged=0, deleted=0,"
580 " pathname=coalesce(origname,pathname), origname=NULL"
581 " WHERE pathname=%Q",
582 mtime, zFile
583 );
584 }
585 free(zFull);
586 }
587 blob_reset(&record);
588
--- src/update.c
+++ src/update.c
@@ -449,10 +449,11 @@
449 */
450 int historical_version_of_file(
451 const char *revision, /* The checkin containing the file */
452 const char *file, /* Full treename of the file */
453 Blob *content, /* Put the content here */
454 int *pIsExe, /* Set to true if file is executable */
455 int errCode /* Error code if file not found. Panic if 0. */
456 ){
457 Manifest *pManifest;
458 ManifestFile *pFile;
459 int rid=0;
@@ -467,17 +468,16 @@
468 fossil_fatal("no such checkin: %s", revision);
469 }
470 pManifest = manifest_get(rid, CFTYPE_MANIFEST);
471
472 if( pManifest ){
473 pFile = manifest_file_seek(pManifest, file);
474 if( pFile ){
475 rid = uuid_to_rid(pFile->zUuid, 0);
476 if( pIsExe ) *pIsExe = manifest_file_mperm(pFile);
477 manifest_destroy(pManifest);
478 return content_get(rid, content);
 
479 }
480 manifest_destroy(pManifest);
481 if( errCode<=0 ){
482 fossil_fatal("file %s does not exist in checkin: %s", file, revision);
483 }
@@ -509,11 +509,10 @@
509 const char *zFile;
510 const char *zRevision;
511 Blob record;
512 int i;
513 int errCode;
 
514 Stmt q;
515
516 undo_capture_command_line();
517 zRevision = find_option("revision", "r", 1);
518 verify_all_options();
@@ -549,39 +548,34 @@
548 " WHERE chnged OR deleted OR rid=0 OR pathname!=origname;"
549 );
550 }
551 blob_zero(&record);
552 db_prepare(&q, "SELECT name FROM torevert");
553 if( zRevision==0 ){
554 int vid = db_lget_int("checkout", 0);
555 zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
556 }
557 while( db_step(&q)==SQLITE_ROW ){
558 int isExe = 0;
559 zFile = db_column_text(&q, 0);
560 errCode = historical_version_of_file(zRevision, zFile, &record, &isExe,2);
 
 
 
 
 
 
 
 
 
 
 
561 if( errCode==2 ){
562 fossil_warning("file not in repository: %s", zFile);
563 }else{
564 char *zFull = mprintf("%/%/", g.zLocalRoot, zFile);
565 undo_save(zFile);
566 blob_write_to_file(&record, zFull);
567 file_setexe(zFull, isExe);
568 printf("REVERTED: %s\n", zFile);
569 if( zRevision==0 ){
570 sqlite3_int64 mtime = file_mtime(zFull);
571 db_multi_exec(
572 "UPDATE vfile"
573 " SET mtime=%lld, chnged=0, deleted=0, isexe=%d,"
574 " pathname=coalesce(origname,pathname), origname=NULL"
575 " WHERE pathname=%Q",
576 mtime, isExe, zFile
577 );
578 }
579 free(zFull);
580 }
581 blob_reset(&record);
582

Keyboard Shortcuts

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