| ︙ | | |
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
-
-
+
+
-
-
|
}else if( fossil_strcmp(g.argv[2], "latest")==0 ){
/* If VERSION is "latest", then use the same algorithm to find the
** target as if VERSION were omitted and the --latest flag is present.
*/
latestFlag = 1;
}else{
tid = name_to_typed_rid(g.argv[2],"ci");
if( tid==0 ){
fossil_fatal("no such version: %s", g.argv[2]);
if( tid==0 || !is_a_version(tid) ){
fossil_fatal("no such check-in: %s", g.argv[2]);
}else if( !is_a_version(tid) ){
fossil_fatal("no such version: %s", g.argv[2]);
}
}
}
/* If no VERSION is specified on the command-line, then look for a
** descendent of the current version. If there are multiple descendants,
** look for one from the same branch as the current version. If there
|
| ︙ | | |
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
-
+
|
int i; /* Loop counter */
const char *zSep; /* Term separator */
blob_zero(&sql);
blob_append(&sql, "DELETE FROM fv WHERE ", -1);
zSep = "";
for(i=3; i<g.argc; i++){
file_tree_name(g.argv[i], &treename, 1);
file_tree_name(g.argv[i], &treename, 0, 1);
if( file_wd_isdir(g.argv[i])==1 ){
if( blob_size(&treename) != 1 || blob_str(&treename)[0] != '.' ){
blob_append_sql(&sql, "%sfn NOT GLOB '%q/*' ",
zSep /*safe-for-%s*/, blob_str(&treename));
}else{
blob_reset(&sql);
break;
|
| ︙ | | |
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
|
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
|
-
+
-
+
-
+
-
+
-
+
|
/* File added in the target. */
if( file_wd_isfile_or_link(zFullPath) ){
fossil_print("ADD %s - overwrites an unmanaged file\n", zName);
nOverwrite++;
}else{
fossil_print("ADD %s\n", zName);
}
undo_save(zName);
if( !dryRunFlag && !internalUpdate ) undo_save(zName);
if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
}else if( idt>0 && idv>0 && ridt!=ridv && (chnged==0 || deleted) ){
/* The file is unedited. Change it to the target version */
undo_save(zName);
if( deleted ){
fossil_print("UPDATE %s - change to unmanaged file\n", zName);
}else{
fossil_print("UPDATE %s\n", zName);
}
if( !dryRunFlag && !internalUpdate ) undo_save(zName);
if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
}else if( idt>0 && idv>0 && !deleted && file_wd_size(zFullPath)<0 ){
/* The file missing from the local check-out. Restore it to the
** version that appears in the target. */
fossil_print("UPDATE %s\n", zName);
undo_save(zName);
if( !dryRunFlag && !internalUpdate ) undo_save(zName);
if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0);
}else if( idt==0 && idv>0 ){
if( ridv==0 ){
/* Added in current checkout. Continue to hold the file as
** as an addition */
db_multi_exec("UPDATE vfile SET vid=%d WHERE id=%d", tid, idv);
}else if( chnged ){
/* Edited locally but deleted from the target. Do not track the
** file but keep the edited version around. */
fossil_print("CONFLICT %s - edited locally but deleted by update\n",
zName);
nConflict++;
}else{
fossil_print("REMOVE %s\n", zName);
undo_save(zName);
if( !dryRunFlag && !internalUpdate ) undo_save(zName);
if( !dryRunFlag ) file_delete(zFullPath);
}
}else if( idt>0 && idv>0 && ridt!=ridv && chnged ){
/* Merge the changes in the current tree into the target version */
Blob r, t, v;
int rc;
if( nameChng ){
fossil_print("MERGE %s -> %s\n", zName, zNewName);
}else{
fossil_print("MERGE %s\n", zName);
}
if( islinkv || islinkt /* || file_wd_islink(zFullPath) */ ){
fossil_print("***** Cannot merge symlink %s\n", zNewName);
nConflict++;
}else{
unsigned mergeFlags = dryRunFlag ? MERGE_DRYRUN : 0;
undo_save(zName);
if( !dryRunFlag && !internalUpdate ) undo_save(zName);
content_get(ridt, &t);
content_get(ridv, &v);
rc = merge_3way(&v, zFullPath, &t, &r, mergeFlags);
if( rc>=0 ){
if( !dryRunFlag ){
blob_write_to_file(&r, zFullNewPath);
file_wd_setexe(zFullNewPath, isexe);
|
| ︙ | | |
542
543
544
545
546
547
548
549
550
551
552
553
554
555
|
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
|
+
|
case -2: zLabel = "backout merge"; break;
}
fossil_warning("uncommitted %s against %S.",
zLabel, db_column_text(&q, 0));
nMerge++;
}
db_finalize(&q);
leaf_ambiguity_warning(tid, tid);
if( nConflict ){
if( internalUpdate ){
internalConflictCnt = nConflict;
nConflict = 0;
}else{
fossil_warning("WARNING: %d merge conflicts", nConflict);
|
| ︙ | | |
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
|
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
|
-
+
-
-
+
-
-
+
+
-
-
-
-
+
-
-
-
+
-
+
-
-
-
-
-
-
+
-
-
+
+
-
+
+
-
+
+
+
-
+
|
if( !internalUpdate ) undo_finish();
if( setmtimeFlag ) vfile_check_signature(tid, CKSIG_SETMTIME);
db_end_transaction(0);
}
}
/*
** Make sure empty directories are created
** Create empty directories specified by the empty-dirs setting.
*/
void ensure_empty_dirs_created(void){
/* Make empty directories? */
char *zEmptyDirs = db_get("empty-dirs", 0);
if( zEmptyDirs!=0 ){
char *bc;
int i;
Blob dirName;
Blob dirsList;
blob_zero(&dirsList);
blob_init(&dirsList, zEmptyDirs, strlen(zEmptyDirs));
zEmptyDirs = fossil_strdup(zEmptyDirs);
for(i=0; zEmptyDirs[i]; i++){
/* Replace commas by spaces */
bc = blob_str(&dirsList);
while( (*bc)!='\0' ){
if( (*bc)==',' ) { *bc = ' '; }
if( zEmptyDirs[i]==',' ) zEmptyDirs[i] = ' ';
++bc;
}
/* Make directories */
blob_zero(&dirName);
blob_init(&dirsList, zEmptyDirs, -1);
while( blob_token(&dirsList, &dirName) ){
const char *zDir = blob_str(&dirName);
char *zDir = blob_str(&dirName);
/* Make full pathname of the directory */
Blob path;
const char *zPath;
blob_zero(&path);
blob_appendf(&path, "%s/%s", g.zLocalRoot, zDir);
char *zPath = mprintf("%s/%s", g.zLocalRoot, zDir);
zPath = blob_str(&path);
/* Handle various cases of existence of the directory */
switch( file_wd_isdir(zPath) ){
case 0: { /* doesn't exist */
fossil_free(zPath);
zPath = mprintf("%s/%s/x", g.zLocalRoot, zDir);
if( file_mkdir(zPath, 0)!=0 ) {
if( file_mkfolder(zPath, 0, 1)!=0 ) {
fossil_warning("couldn't create directory %s as "
"required by empty-dirs setting", zDir);
}
break;
}
case 1: { /* exists, and is a directory */
/* do nothing - required directory exists already */
break;
}
case 2: { /* exists, but isn't a directory */
fossil_warning("file %s found, but a directory is required "
"by empty-dirs setting", zDir);
}
}
fossil_free(zPath);
blob_reset(&path);
blob_reset(&dirName);
}
blob_reset(&dirsList);
fossil_free(zEmptyDirs);
}
}
/*
** Get the contents of a file within the check-in "revision". If
** revision==NULL then get the file content for the current checkout.
*/
int historical_version_of_file(
const char *revision, /* The check-in containing the file */
const char *file, /* Full treename of the file */
Blob *content, /* Put the content here */
int *pIsLink, /* Set to true if file is link. */
int *pIsExe, /* Set to true if file is executable */
int *pIsBin, /* Set to true if file is binary */
int errCode /* Error code if file not found. Panic if 0. */
int errCode /* Error code if file not found. Panic if <= 0. */
){
Manifest *pManifest;
ManifestFile *pFile;
int rid=0;
if( revision ){
rid = name_to_typed_rid(revision,"ci");
|
| ︙ | | |
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
|
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
|
+
-
+
|
undo_begin();
db_multi_exec("CREATE TEMP TABLE torevert(name UNIQUE);");
if( g.argc>2 ){
for(i=2; i<g.argc; i++){
Blob fname;
zFile = mprintf("%/", g.argv[i]);
blob_zero(&fname);
file_tree_name(zFile, &fname, 1);
file_tree_name(zFile, &fname, 0, 1);
db_multi_exec(
"REPLACE INTO torevert VALUES(%B);"
"INSERT OR IGNORE INTO torevert"
" SELECT pathname"
" FROM vfile"
" WHERE origname=%B;",
&fname, &fname
|
| ︙ | | |
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
|
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
|
-
+
-
+
-
+
|
zFile = db_column_text(&q, 0);
zFull = mprintf("%/%/", g.zLocalRoot, zFile);
errCode = historical_version_of_file(zRevision, zFile, &record,
&isLink, &isExe, 0, 2);
if( errCode==2 ){
if( db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q OR origname=%Q",
zFile, zFile)==0 ){
fossil_print("UNMANAGE: %s\n", zFile);
fossil_print("UNMANAGE %s\n", zFile);
}else{
undo_save(zFile);
file_delete(zFull);
fossil_print("DELETE: %s\n", zFile);
fossil_print("DELETE %s\n", zFile);
}
db_multi_exec(
"UPDATE OR REPLACE vfile"
" SET pathname=origname, origname=NULL"
" WHERE pathname=%Q AND origname!=pathname;"
"DELETE FROM vfile WHERE pathname=%Q",
zFile, zFile
);
}else{
sqlite3_int64 mtime;
undo_save(zFile);
mayNeedDelete = file_wd_size(zFull)>=0;
mayBeLink = file_wd_islink(0);
create_symlink_or_file(mayNeedDelete, isLink, mayBeLink, &record, zFull);
file_wd_setexe(zFull, isExe);
fossil_print("REVERTED: %s\n", zFile);
fossil_print("REVERT %s\n", zFile);
mtime = file_wd_mtime(zFull);
db_multi_exec(
"UPDATE vfile"
" SET mtime=%lld, chnged=0, deleted=0, isexe=%d, islink=%d,mrid=rid"
" WHERE pathname=%Q OR origname=%Q",
mtime, isExe, isLink, zFile, zFile
);
|
| ︙ | | |