Fossil SCM

Add symlink support for Unix. New settings flag "allow-symlinks" controls this (off by default).

dmitry 2011-01-28 19:04 UTC symlinks
Commit ed2ef7e9a3b6a46da6bad49aa777e10bf675f003
+3 -3
--- src/add.c
+++ src/add.c
@@ -183,11 +183,11 @@
183183
zPath = blob_str(&path);
184184
if( shouldBeIgnored(pIgnore, zPath) ){
185185
/* Noop */
186186
}else if( file_isdir(zPath)==1 ){
187187
add_directory_content(zPath, pIgnore);
188
- }else if( file_isfile(zPath) ){
188
+ }else if( file_isfile_or_link(zPath) ){
189189
db_multi_exec("INSERT INTO sfile VALUES(%Q)", zPath);
190190
}
191191
blob_resize(&path, origSize);
192192
}
193193
}
@@ -304,11 +304,11 @@
304304
}
305305
blob_appendf(&path, "/%s", pEntry->d_name);
306306
zPath = blob_str(&path);
307307
if( file_isdir(zPath)==1 ){
308308
del_directory_content(zPath);
309
- }else if( file_isfile(zPath) ){
309
+ }else if( file_isfile_or_link(zPath) ){
310310
char *zFilePath;
311311
Blob pathname;
312312
file_tree_name(zPath, &pathname, 1);
313313
zFilePath = blob_str(&pathname);
314314
if( !db_exists(
@@ -462,11 +462,11 @@
462462
const char * zFile;
463463
const char * zPath;
464464
465465
zFile = db_column_text(&q, 0);
466466
zPath = db_column_text(&q, 1);
467
- if( !file_isfile(zPath) ){
467
+ if( !file_isfile_or_link(zPath) ){
468468
if( !isTest ){
469469
db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zFile);
470470
}
471471
printf("DELETED %s\n", zFile);
472472
nDelete++;
473473
--- src/add.c
+++ src/add.c
@@ -183,11 +183,11 @@
183 zPath = blob_str(&path);
184 if( shouldBeIgnored(pIgnore, zPath) ){
185 /* Noop */
186 }else if( file_isdir(zPath)==1 ){
187 add_directory_content(zPath, pIgnore);
188 }else if( file_isfile(zPath) ){
189 db_multi_exec("INSERT INTO sfile VALUES(%Q)", zPath);
190 }
191 blob_resize(&path, origSize);
192 }
193 }
@@ -304,11 +304,11 @@
304 }
305 blob_appendf(&path, "/%s", pEntry->d_name);
306 zPath = blob_str(&path);
307 if( file_isdir(zPath)==1 ){
308 del_directory_content(zPath);
309 }else if( file_isfile(zPath) ){
310 char *zFilePath;
311 Blob pathname;
312 file_tree_name(zPath, &pathname, 1);
313 zFilePath = blob_str(&pathname);
314 if( !db_exists(
@@ -462,11 +462,11 @@
462 const char * zFile;
463 const char * zPath;
464
465 zFile = db_column_text(&q, 0);
466 zPath = db_column_text(&q, 1);
467 if( !file_isfile(zPath) ){
468 if( !isTest ){
469 db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zFile);
470 }
471 printf("DELETED %s\n", zFile);
472 nDelete++;
473
--- src/add.c
+++ src/add.c
@@ -183,11 +183,11 @@
183 zPath = blob_str(&path);
184 if( shouldBeIgnored(pIgnore, zPath) ){
185 /* Noop */
186 }else if( file_isdir(zPath)==1 ){
187 add_directory_content(zPath, pIgnore);
188 }else if( file_isfile_or_link(zPath) ){
189 db_multi_exec("INSERT INTO sfile VALUES(%Q)", zPath);
190 }
191 blob_resize(&path, origSize);
192 }
193 }
@@ -304,11 +304,11 @@
304 }
305 blob_appendf(&path, "/%s", pEntry->d_name);
306 zPath = blob_str(&path);
307 if( file_isdir(zPath)==1 ){
308 del_directory_content(zPath);
309 }else if( file_isfile_or_link(zPath) ){
310 char *zFilePath;
311 Blob pathname;
312 file_tree_name(zPath, &pathname, 1);
313 zFilePath = blob_str(&pathname);
314 if( !db_exists(
@@ -462,11 +462,11 @@
462 const char * zFile;
463 const char * zPath;
464
465 zFile = db_column_text(&q, 0);
466 zPath = db_column_text(&q, 1);
467 if( !file_isfile_or_link(zPath) ){
468 if( !isTest ){
469 db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zFile);
470 }
471 printf("DELETED %s\n", zFile);
472 nDelete++;
473
+23
--- src/blob.c
+++ src/blob.c
@@ -645,10 +645,33 @@
645645
if( got<size ){
646646
blob_resize(pBlob, got);
647647
}
648648
return got;
649649
}
650
+
651
+/*
652
+** Reads symlink destination path and puts int into blob.
653
+** Any prior content of the blob is discarded, not freed.
654
+**
655
+** Returns length of destination path.
656
+**
657
+** On windows, zeros blob and returns 0.
658
+*/
659
+int blob_read_link(Blob *pBlob, const char *zFilename){
660
+#if !defined(_WIN32)
661
+ char zBuf[1024];
662
+ ssize_t len = readlink(zFilename, zBuf, 1023);
663
+ zBuf[len] = 0;
664
+ blob_zero(pBlob);
665
+ blob_appendf(pBlob, "%s", zBuf);
666
+ return len;
667
+#else
668
+ blob_zero(pBlob);
669
+ return 0;
670
+#endif
671
+}
672
+
650673
651674
/*
652675
** Write the content of a blob into a file.
653676
**
654677
** If the filename is blank or "-" then write to standard output.
655678
--- src/blob.c
+++ src/blob.c
@@ -645,10 +645,33 @@
645 if( got<size ){
646 blob_resize(pBlob, got);
647 }
648 return got;
649 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
650
651 /*
652 ** Write the content of a blob into a file.
653 **
654 ** If the filename is blank or "-" then write to standard output.
655
--- src/blob.c
+++ src/blob.c
@@ -645,10 +645,33 @@
645 if( got<size ){
646 blob_resize(pBlob, got);
647 }
648 return got;
649 }
650
651 /*
652 ** Reads symlink destination path and puts int into blob.
653 ** Any prior content of the blob is discarded, not freed.
654 **
655 ** Returns length of destination path.
656 **
657 ** On windows, zeros blob and returns 0.
658 */
659 int blob_read_link(Blob *pBlob, const char *zFilename){
660 #if !defined(_WIN32)
661 char zBuf[1024];
662 ssize_t len = readlink(zFilename, zBuf, 1023);
663 zBuf[len] = 0;
664 blob_zero(pBlob);
665 blob_appendf(pBlob, "%s", zBuf);
666 return len;
667 #else
668 blob_zero(pBlob);
669 return 0;
670 #endif
671 }
672
673
674 /*
675 ** Write the content of a blob into a file.
676 **
677 ** If the filename is blank or "-" then write to standard output.
678
+18 -5
--- src/checkin.c
+++ src/checkin.c
@@ -53,11 +53,11 @@
5353
int isRenamed = db_column_int(&q,4);
5454
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
5555
blob_append(report, zPrefix, nPrefix);
5656
if( isDeleted ){
5757
blob_appendf(report, "DELETED %s\n", zPathname);
58
- }else if( !file_isfile(zFullName) ){
58
+ }else if( !file_isfile_or_link(zFullName) ){
5959
if( access(zFullName, 0)==0 ){
6060
blob_appendf(report, "NOT_A_FILE %s\n", zPathname);
6161
if( missingIsFatal ){
6262
fossil_warning("not a file: %s", zPathname);
6363
nErr++;
@@ -181,11 +181,11 @@
181181
printf("%s\n", zPathname);
182182
}else if( isNew ){
183183
printf("ADDED %s\n", zPathname);
184184
}else if( isDeleted ){
185185
printf("DELETED %s\n", zPathname);
186
- }else if( !file_isfile(zFullName) ){
186
+ }else if( !file_isfile_or_link(zFullName) ){
187187
if( access(zFullName, 0)==0 ){
188188
printf("NOT_A_FILE %s\n", zPathname);
189189
}else{
190190
printf("MISSING %s\n", zPathname);
191191
}
@@ -619,11 +619,11 @@
619619
blob_appendf(pOut, "C %F\n", blob_str(pComment));
620620
zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
621621
blob_appendf(pOut, "D %s\n", zDate);
622622
zDate[10] = ' ';
623623
db_prepare(&q,
624
- "SELECT pathname, uuid, origname, blob.rid, isexe,"
624
+ "SELECT pathname, uuid, origname, blob.rid, isexe, islink,"
625625
" file_is_selected(vfile.id)"
626626
" FROM vfile JOIN blob ON vfile.mrid=blob.rid"
627627
" WHERE (NOT deleted OR NOT file_is_selected(vfile.id))"
628628
" AND vfile.vid=%d"
629629
" ORDER BY 1", vid);
@@ -634,11 +634,12 @@
634634
const char *zName = db_column_text(&q, 0);
635635
const char *zUuid = db_column_text(&q, 1);
636636
const char *zOrig = db_column_text(&q, 2);
637637
int frid = db_column_int(&q, 3);
638638
int isexe = db_column_int(&q, 4);
639
- int isSelected = db_column_int(&q, 5);
639
+ int isLink = db_column_int(&q, 5);
640
+ int isSelected = db_column_int(&q, 6);
640641
const char *zPerm;
641642
int cmp;
642643
#if !defined(_WIN32)
643644
/* For unix, extract the "executable" permission bit directly from
644645
** the filesystem. On windows, the "executable" bit is retained
@@ -645,13 +646,20 @@
645646
** unchanged from the original.
646647
*/
647648
blob_resize(&filename, nBasename);
648649
blob_append(&filename, zName, -1);
649650
isexe = file_isexe(blob_str(&filename));
651
+
652
+ /* For unix, check if the file on the filesystem is symlink.
653
+ ** On windows, the bit is retained unchanged from original.
654
+ */
655
+ isLink = file_islink(blob_str(&filename));
650656
#endif
651657
if( isexe ){
652658
zPerm = " x";
659
+ }else if( isLink ){
660
+ zPerm = " l"; /* note: symlinks don't have executable bit on unix */
653661
}else{
654662
zPerm = "";
655663
}
656664
if( !g.markPrivate ) content_make_public(frid);
657665
while( pFile && fossil_strcmp(pFile->zName,zName)<0 ){
@@ -993,11 +1001,16 @@
9931001
id = db_column_int(&q, 0);
9941002
zFullname = db_column_text(&q, 1);
9951003
rid = db_column_int(&q, 2);
9961004
9971005
blob_zero(&content);
998
- blob_read_from_file(&content, zFullname);
1006
+ if( file_islink(zFullname) ){
1007
+ /* Instead of file content, put link destination path */
1008
+ blob_read_link(&content, zFullname);
1009
+ }else{
1010
+ blob_read_from_file(&content, zFullname);
1011
+ }
9991012
nrid = content_put(&content, 0, 0, 0);
10001013
blob_reset(&content);
10011014
if( rid>0 ){
10021015
content_deltify(rid, nrid, 0);
10031016
}
10041017
--- src/checkin.c
+++ src/checkin.c
@@ -53,11 +53,11 @@
53 int isRenamed = db_column_int(&q,4);
54 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
55 blob_append(report, zPrefix, nPrefix);
56 if( isDeleted ){
57 blob_appendf(report, "DELETED %s\n", zPathname);
58 }else if( !file_isfile(zFullName) ){
59 if( access(zFullName, 0)==0 ){
60 blob_appendf(report, "NOT_A_FILE %s\n", zPathname);
61 if( missingIsFatal ){
62 fossil_warning("not a file: %s", zPathname);
63 nErr++;
@@ -181,11 +181,11 @@
181 printf("%s\n", zPathname);
182 }else if( isNew ){
183 printf("ADDED %s\n", zPathname);
184 }else if( isDeleted ){
185 printf("DELETED %s\n", zPathname);
186 }else if( !file_isfile(zFullName) ){
187 if( access(zFullName, 0)==0 ){
188 printf("NOT_A_FILE %s\n", zPathname);
189 }else{
190 printf("MISSING %s\n", zPathname);
191 }
@@ -619,11 +619,11 @@
619 blob_appendf(pOut, "C %F\n", blob_str(pComment));
620 zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
621 blob_appendf(pOut, "D %s\n", zDate);
622 zDate[10] = ' ';
623 db_prepare(&q,
624 "SELECT pathname, uuid, origname, blob.rid, isexe,"
625 " file_is_selected(vfile.id)"
626 " FROM vfile JOIN blob ON vfile.mrid=blob.rid"
627 " WHERE (NOT deleted OR NOT file_is_selected(vfile.id))"
628 " AND vfile.vid=%d"
629 " ORDER BY 1", vid);
@@ -634,11 +634,12 @@
634 const char *zName = db_column_text(&q, 0);
635 const char *zUuid = db_column_text(&q, 1);
636 const char *zOrig = db_column_text(&q, 2);
637 int frid = db_column_int(&q, 3);
638 int isexe = db_column_int(&q, 4);
639 int isSelected = db_column_int(&q, 5);
 
640 const char *zPerm;
641 int cmp;
642 #if !defined(_WIN32)
643 /* For unix, extract the "executable" permission bit directly from
644 ** the filesystem. On windows, the "executable" bit is retained
@@ -645,13 +646,20 @@
645 ** unchanged from the original.
646 */
647 blob_resize(&filename, nBasename);
648 blob_append(&filename, zName, -1);
649 isexe = file_isexe(blob_str(&filename));
 
 
 
 
 
650 #endif
651 if( isexe ){
652 zPerm = " x";
 
 
653 }else{
654 zPerm = "";
655 }
656 if( !g.markPrivate ) content_make_public(frid);
657 while( pFile && fossil_strcmp(pFile->zName,zName)<0 ){
@@ -993,11 +1001,16 @@
993 id = db_column_int(&q, 0);
994 zFullname = db_column_text(&q, 1);
995 rid = db_column_int(&q, 2);
996
997 blob_zero(&content);
998 blob_read_from_file(&content, zFullname);
 
 
 
 
 
999 nrid = content_put(&content, 0, 0, 0);
1000 blob_reset(&content);
1001 if( rid>0 ){
1002 content_deltify(rid, nrid, 0);
1003 }
1004
--- src/checkin.c
+++ src/checkin.c
@@ -53,11 +53,11 @@
53 int isRenamed = db_column_int(&q,4);
54 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
55 blob_append(report, zPrefix, nPrefix);
56 if( isDeleted ){
57 blob_appendf(report, "DELETED %s\n", zPathname);
58 }else if( !file_isfile_or_link(zFullName) ){
59 if( access(zFullName, 0)==0 ){
60 blob_appendf(report, "NOT_A_FILE %s\n", zPathname);
61 if( missingIsFatal ){
62 fossil_warning("not a file: %s", zPathname);
63 nErr++;
@@ -181,11 +181,11 @@
181 printf("%s\n", zPathname);
182 }else if( isNew ){
183 printf("ADDED %s\n", zPathname);
184 }else if( isDeleted ){
185 printf("DELETED %s\n", zPathname);
186 }else if( !file_isfile_or_link(zFullName) ){
187 if( access(zFullName, 0)==0 ){
188 printf("NOT_A_FILE %s\n", zPathname);
189 }else{
190 printf("MISSING %s\n", zPathname);
191 }
@@ -619,11 +619,11 @@
619 blob_appendf(pOut, "C %F\n", blob_str(pComment));
620 zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
621 blob_appendf(pOut, "D %s\n", zDate);
622 zDate[10] = ' ';
623 db_prepare(&q,
624 "SELECT pathname, uuid, origname, blob.rid, isexe, islink,"
625 " file_is_selected(vfile.id)"
626 " FROM vfile JOIN blob ON vfile.mrid=blob.rid"
627 " WHERE (NOT deleted OR NOT file_is_selected(vfile.id))"
628 " AND vfile.vid=%d"
629 " ORDER BY 1", vid);
@@ -634,11 +634,12 @@
634 const char *zName = db_column_text(&q, 0);
635 const char *zUuid = db_column_text(&q, 1);
636 const char *zOrig = db_column_text(&q, 2);
637 int frid = db_column_int(&q, 3);
638 int isexe = db_column_int(&q, 4);
639 int isLink = db_column_int(&q, 5);
640 int isSelected = db_column_int(&q, 6);
641 const char *zPerm;
642 int cmp;
643 #if !defined(_WIN32)
644 /* For unix, extract the "executable" permission bit directly from
645 ** the filesystem. On windows, the "executable" bit is retained
@@ -645,13 +646,20 @@
646 ** unchanged from the original.
647 */
648 blob_resize(&filename, nBasename);
649 blob_append(&filename, zName, -1);
650 isexe = file_isexe(blob_str(&filename));
651
652 /* For unix, check if the file on the filesystem is symlink.
653 ** On windows, the bit is retained unchanged from original.
654 */
655 isLink = file_islink(blob_str(&filename));
656 #endif
657 if( isexe ){
658 zPerm = " x";
659 }else if( isLink ){
660 zPerm = " l"; /* note: symlinks don't have executable bit on unix */
661 }else{
662 zPerm = "";
663 }
664 if( !g.markPrivate ) content_make_public(frid);
665 while( pFile && fossil_strcmp(pFile->zName,zName)<0 ){
@@ -993,11 +1001,16 @@
1001 id = db_column_int(&q, 0);
1002 zFullname = db_column_text(&q, 1);
1003 rid = db_column_int(&q, 2);
1004
1005 blob_zero(&content);
1006 if( file_islink(zFullname) ){
1007 /* Instead of file content, put link destination path */
1008 blob_read_link(&content, zFullname);
1009 }else{
1010 blob_read_from_file(&content, zFullname);
1011 }
1012 nrid = content_put(&content, 0, 0, 0);
1013 blob_reset(&content);
1014 if( rid>0 ){
1015 content_deltify(rid, nrid, 0);
1016 }
1017
+2 -1
--- src/checkout.c
+++ src/checkout.c
@@ -102,11 +102,12 @@
102102
db_reset(&s);
103103
}
104104
105105
/*
106106
** Set or clear the execute permission bit (as appropriate) for all
107
-** files in the current check-out.
107
+** files in the current check-out, and replace files that have
108
+** symlink bit with actual symlinks.
108109
*/
109110
void checkout_set_all_exe(int vid){
110111
Blob filename;
111112
int baseLen;
112113
Manifest *pManifest;
113114
--- src/checkout.c
+++ src/checkout.c
@@ -102,11 +102,12 @@
102 db_reset(&s);
103 }
104
105 /*
106 ** Set or clear the execute permission bit (as appropriate) for all
107 ** files in the current check-out.
 
108 */
109 void checkout_set_all_exe(int vid){
110 Blob filename;
111 int baseLen;
112 Manifest *pManifest;
113
--- src/checkout.c
+++ src/checkout.c
@@ -102,11 +102,12 @@
102 db_reset(&s);
103 }
104
105 /*
106 ** Set or clear the execute permission bit (as appropriate) for all
107 ** files in the current check-out, and replace files that have
108 ** symlink bit with actual symlinks.
109 */
110 void checkout_set_all_exe(int vid){
111 Blob filename;
112 int baseLen;
113 Manifest *pManifest;
114
+35
--- src/db.c
+++ src/db.c
@@ -740,10 +740,36 @@
740740
sqlite3_finalize(pStmt);
741741
if( rc==SQLITE_ERROR ){
742742
sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN isexe BOOLEAN", 0, 0, 0);
743743
}
744744
745
+ /* If the "islink" column is missing from the vfile table, then
746
+ ** add it now. This code added on 2011-01-17. After all users have
747
+ ** upgraded, this code can be safely deleted.
748
+ */
749
+ rc = sqlite3_prepare(g.db, "SELECT islink FROM vfile", -1, &pStmt, 0);
750
+ sqlite3_finalize(pStmt);
751
+ if( rc==SQLITE_ERROR ){
752
+ sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN islink BOOLEAN", 0, 0, 0);
753
+ }
754
+
755
+#if 0
756
+ /* If the "isLink" column is missing from the stashfile table, then
757
+ ** add it now. This code added on 2011-01-18. After all users have
758
+ ** upgraded, this code can be safely deleted.
759
+ **
760
+ ** Table stashfile may not exist at all. We don't handle this case,
761
+ ** and leave it to sqlite.
762
+ */
763
+ rc = sqlite3_prepare(g.db, "SELECT isLink FROM stashfile", -1, &pStmt, 0);
764
+ sqlite3_finalize(pStmt);
765
+ /* NOTE: this prints "SQLITE_ERROR: no such column: isLink" for some reason */
766
+ if( rc==SQLITE_ERROR ){
767
+ sqlite3_exec(g.db, "ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN", 0, 0, 0);
768
+ }
769
+#endif
770
+
745771
#if 0
746772
/* If the "mtime" column is missing from the vfile table, then
747773
** add it now. This code added on 2008-12-06. After all users have
748774
** upgraded, this code can be safely deleted.
749775
*/
@@ -847,10 +873,12 @@
847873
}
848874
}
849875
db_open_or_attach(zDbName, "repository");
850876
g.repositoryOpen = 1;
851877
g.zRepositoryName = mprintf("%s", zDbName);
878
+ /* Cache "allow-symlinks" option, because we'll need it on every stat call */
879
+ g.allowSymlinks = db_get_boolean("allow-symlinks", 0);
852880
}
853881
854882
/*
855883
** Flags for the db_find_and_open_repository() function.
856884
*/
@@ -1605,10 +1633,11 @@
16051633
int width; /* Width of display. 0 for boolean values */
16061634
char const *def; /* Default value */
16071635
};
16081636
#endif /* INTERFACE */
16091637
struct stControlSettings const ctrlSettings[] = {
1638
+ { "allow-symlinks",0, 0, "off" },
16101639
{ "access-log", 0, 0, "off" },
16111640
{ "auto-captcha", "autocaptcha", 0, "on" },
16121641
{ "auto-shun", 0, 0, "on" },
16131642
{ "autosync", 0, 0, "on" },
16141643
{ "binary-glob", 0, 32, "" },
@@ -1643,10 +1672,16 @@
16431672
** values. With just a property name it shows the value of that property.
16441673
** With a value argument it changes the property for the current repository.
16451674
**
16461675
** The "unset" command clears a property setting.
16471676
**
1677
+**
1678
+** allow-symlinks If enabled, don't follow symlinks, and instead treat
1679
+** them as symlinks on Unix. Has no effect on Windows
1680
+** (existing links in repository created on Unix become
1681
+** plain-text files with link destination path inside).
1682
+** Default: off
16481683
**
16491684
** auto-captcha If enabled, the Login page provides a button to
16501685
** fill in the captcha password. Default: on
16511686
**
16521687
** auto-shun If enabled, automatically pull the shunning list
16531688
--- src/db.c
+++ src/db.c
@@ -740,10 +740,36 @@
740 sqlite3_finalize(pStmt);
741 if( rc==SQLITE_ERROR ){
742 sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN isexe BOOLEAN", 0, 0, 0);
743 }
744
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
745 #if 0
746 /* If the "mtime" column is missing from the vfile table, then
747 ** add it now. This code added on 2008-12-06. After all users have
748 ** upgraded, this code can be safely deleted.
749 */
@@ -847,10 +873,12 @@
847 }
848 }
849 db_open_or_attach(zDbName, "repository");
850 g.repositoryOpen = 1;
851 g.zRepositoryName = mprintf("%s", zDbName);
 
 
852 }
853
854 /*
855 ** Flags for the db_find_and_open_repository() function.
856 */
@@ -1605,10 +1633,11 @@
1605 int width; /* Width of display. 0 for boolean values */
1606 char const *def; /* Default value */
1607 };
1608 #endif /* INTERFACE */
1609 struct stControlSettings const ctrlSettings[] = {
 
1610 { "access-log", 0, 0, "off" },
1611 { "auto-captcha", "autocaptcha", 0, "on" },
1612 { "auto-shun", 0, 0, "on" },
1613 { "autosync", 0, 0, "on" },
1614 { "binary-glob", 0, 32, "" },
@@ -1643,10 +1672,16 @@
1643 ** values. With just a property name it shows the value of that property.
1644 ** With a value argument it changes the property for the current repository.
1645 **
1646 ** The "unset" command clears a property setting.
1647 **
 
 
 
 
 
 
1648 **
1649 ** auto-captcha If enabled, the Login page provides a button to
1650 ** fill in the captcha password. Default: on
1651 **
1652 ** auto-shun If enabled, automatically pull the shunning list
1653
--- src/db.c
+++ src/db.c
@@ -740,10 +740,36 @@
740 sqlite3_finalize(pStmt);
741 if( rc==SQLITE_ERROR ){
742 sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN isexe BOOLEAN", 0, 0, 0);
743 }
744
745 /* If the "islink" column is missing from the vfile table, then
746 ** add it now. This code added on 2011-01-17. After all users have
747 ** upgraded, this code can be safely deleted.
748 */
749 rc = sqlite3_prepare(g.db, "SELECT islink FROM vfile", -1, &pStmt, 0);
750 sqlite3_finalize(pStmt);
751 if( rc==SQLITE_ERROR ){
752 sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN islink BOOLEAN", 0, 0, 0);
753 }
754
755 #if 0
756 /* If the "isLink" column is missing from the stashfile table, then
757 ** add it now. This code added on 2011-01-18. After all users have
758 ** upgraded, this code can be safely deleted.
759 **
760 ** Table stashfile may not exist at all. We don't handle this case,
761 ** and leave it to sqlite.
762 */
763 rc = sqlite3_prepare(g.db, "SELECT isLink FROM stashfile", -1, &pStmt, 0);
764 sqlite3_finalize(pStmt);
765 /* NOTE: this prints "SQLITE_ERROR: no such column: isLink" for some reason */
766 if( rc==SQLITE_ERROR ){
767 sqlite3_exec(g.db, "ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN", 0, 0, 0);
768 }
769 #endif
770
771 #if 0
772 /* If the "mtime" column is missing from the vfile table, then
773 ** add it now. This code added on 2008-12-06. After all users have
774 ** upgraded, this code can be safely deleted.
775 */
@@ -847,10 +873,12 @@
873 }
874 }
875 db_open_or_attach(zDbName, "repository");
876 g.repositoryOpen = 1;
877 g.zRepositoryName = mprintf("%s", zDbName);
878 /* Cache "allow-symlinks" option, because we'll need it on every stat call */
879 g.allowSymlinks = db_get_boolean("allow-symlinks", 0);
880 }
881
882 /*
883 ** Flags for the db_find_and_open_repository() function.
884 */
@@ -1605,10 +1633,11 @@
1633 int width; /* Width of display. 0 for boolean values */
1634 char const *def; /* Default value */
1635 };
1636 #endif /* INTERFACE */
1637 struct stControlSettings const ctrlSettings[] = {
1638 { "allow-symlinks",0, 0, "off" },
1639 { "access-log", 0, 0, "off" },
1640 { "auto-captcha", "autocaptcha", 0, "on" },
1641 { "auto-shun", 0, 0, "on" },
1642 { "autosync", 0, 0, "on" },
1643 { "binary-glob", 0, 32, "" },
@@ -1643,10 +1672,16 @@
1672 ** values. With just a property name it shows the value of that property.
1673 ** With a value argument it changes the property for the current repository.
1674 **
1675 ** The "unset" command clears a property setting.
1676 **
1677 **
1678 ** allow-symlinks If enabled, don't follow symlinks, and instead treat
1679 ** them as symlinks on Unix. Has no effect on Windows
1680 ** (existing links in repository created on Unix become
1681 ** plain-text files with link destination path inside).
1682 ** Default: off
1683 **
1684 ** auto-captcha If enabled, the Login page provides a button to
1685 ** fill in the captcha password. Default: on
1686 **
1687 ** auto-shun If enabled, automatically pull the shunning list
1688
+32 -10
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -59,11 +59,15 @@
5959
/* Read content of zFile2 into memory */
6060
blob_zero(&file2);
6161
if( file_size(zFile2)<0 ){
6262
zName2 = "/dev/null";
6363
}else{
64
- blob_read_from_file(&file2, zFile2);
64
+ if( file_islink(zFile2) ){
65
+ blob_read_link(&file2, zFile2);
66
+ }else{
67
+ blob_read_from_file(&file2, zFile2);
68
+ }
6569
zName2 = zName;
6670
}
6771
6872
/* Compute and output the differences */
6973
blob_zero(&out);
@@ -168,13 +172,18 @@
168172
const char *zDiffCmd, /* Use this "diff" command */
169173
int ignoreEolWs /* Ignore whitespace changes at end of lines */
170174
){
171175
Blob fname;
172176
Blob content;
177
+ int isLink;
173178
file_tree_name(g.argv[2], &fname, 1);
174
- historical_version_of_file(zFrom, blob_str(&fname), &content, 0);
175
- diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
179
+ historical_version_of_file(zFrom, blob_str(&fname), &content, &isLink, 0);
180
+ if( !isLink != !file_islink(zFrom) ){
181
+ printf("cannot compute difference between symlink and regular file\n");
182
+ }else{
183
+ diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
184
+ }
176185
blob_reset(&content);
177186
blob_reset(&fname);
178187
}
179188
180189
/*
@@ -204,32 +213,32 @@
204213
if( !is_a_version(rid) ){
205214
fossil_fatal("no such check-in: %s", zFrom);
206215
}
207216
load_vfile_from_rid(rid);
208217
blob_appendf(&sql,
209
- "SELECT v2.pathname, v2.deleted, v2.chnged, v2.rid==0, v1.rid"
218
+ "SELECT v2.pathname, v2.deleted, v2.chnged, v2.rid==0, v1.rid, v1.islink"
210219
" FROM vfile v1, vfile v2 "
211220
" WHERE v1.pathname=v2.pathname AND v1.vid=%d AND v2.vid=%d"
212221
" AND (v2.deleted OR v2.chnged OR v1.mrid!=v2.rid)"
213222
"UNION "
214
- "SELECT pathname, 1, 0, 0, 0"
223
+ "SELECT pathname, 1, 0, 0, 0, islink"
215224
" FROM vfile v1"
216225
" WHERE v1.vid=%d"
217226
" AND NOT EXISTS(SELECT 1 FROM vfile v2"
218227
" WHERE v2.vid=%d AND v2.pathname=v1.pathname)"
219228
"UNION "
220
- "SELECT pathname, 0, 0, 1, 0"
229
+ "SELECT pathname, 0, 0, 1, 0, islink"
221230
" FROM vfile v2"
222231
" WHERE v2.vid=%d"
223232
" AND NOT EXISTS(SELECT 1 FROM vfile v1"
224233
" WHERE v1.vid=%d AND v1.pathname=v2.pathname)"
225234
" ORDER BY 1",
226235
rid, vid, rid, vid, vid, rid
227236
);
228237
}else{
229238
blob_appendf(&sql,
230
- "SELECT pathname, deleted, chnged , rid==0, rid"
239
+ "SELECT pathname, deleted, chnged , rid==0, rid, islink"
231240
" FROM vfile"
232241
" WHERE vid=%d"
233242
" AND (deleted OR chnged OR rid==0)"
234243
" ORDER BY pathname",
235244
vid
@@ -240,10 +249,11 @@
240249
const char *zPathname = db_column_text(&q,0);
241250
int isDeleted = db_column_int(&q, 1);
242251
int isChnged = db_column_int(&q,2);
243252
int isNew = db_column_int(&q,3);
244253
int srcid = db_column_int(&q, 4);
254
+ int isLink = db_column_int(&q, 5);
245255
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
246256
char *zToFree = zFullName;
247257
int showDiff = 1;
248258
if( isDeleted ){
249259
printf("DELETED %s\n", zPathname);
@@ -259,10 +269,16 @@
259269
printf("ADDED_BY_MERGE %s\n", zPathname);
260270
srcid = 0;
261271
if( !asNewFile ){ showDiff = 0; }
262272
}
263273
if( showDiff ){
274
+ if( !isLink != !file_islink(zFullName) ){
275
+ diff_print_index(zPathname);
276
+ printf("--- %s\n+++ %s\n", zPathname, zPathname);
277
+ printf("cannot compute difference between symlink and regular file\n");
278
+ continue;
279
+ }
264280
Blob content;
265281
if( srcid>0 ){
266282
content_get(srcid, &content);
267283
}else{
268284
blob_zero(&content);
@@ -289,15 +305,21 @@
289305
int ignoreEolWs
290306
){
291307
char *zName;
292308
Blob fname;
293309
Blob v1, v2;
310
+ int isLink1, isLink2;
294311
file_tree_name(g.argv[2], &fname, 1);
295312
zName = blob_str(&fname);
296
- historical_version_of_file(zFrom, zName, &v1, 0);
297
- historical_version_of_file(zTo, zName, &v2, 0);
298
- diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
313
+ historical_version_of_file(zFrom, zName, &v1, &isLink1, 0);
314
+ historical_version_of_file(zTo, zName, &v2, &isLink2, 0);
315
+ if( isLink1 != isLink2 ){
316
+ printf("--- %s\n+++ %s\n", zName, zName);
317
+ printf("cannot compute difference between symlink and regular file\n");
318
+ }else{
319
+ diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
320
+ }
299321
blob_reset(&v1);
300322
blob_reset(&v2);
301323
blob_reset(&fname);
302324
}
303325
304326
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -59,11 +59,15 @@
59 /* Read content of zFile2 into memory */
60 blob_zero(&file2);
61 if( file_size(zFile2)<0 ){
62 zName2 = "/dev/null";
63 }else{
64 blob_read_from_file(&file2, zFile2);
 
 
 
 
65 zName2 = zName;
66 }
67
68 /* Compute and output the differences */
69 blob_zero(&out);
@@ -168,13 +172,18 @@
168 const char *zDiffCmd, /* Use this "diff" command */
169 int ignoreEolWs /* Ignore whitespace changes at end of lines */
170 ){
171 Blob fname;
172 Blob content;
 
173 file_tree_name(g.argv[2], &fname, 1);
174 historical_version_of_file(zFrom, blob_str(&fname), &content, 0);
175 diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
 
 
 
 
176 blob_reset(&content);
177 blob_reset(&fname);
178 }
179
180 /*
@@ -204,32 +213,32 @@
204 if( !is_a_version(rid) ){
205 fossil_fatal("no such check-in: %s", zFrom);
206 }
207 load_vfile_from_rid(rid);
208 blob_appendf(&sql,
209 "SELECT v2.pathname, v2.deleted, v2.chnged, v2.rid==0, v1.rid"
210 " FROM vfile v1, vfile v2 "
211 " WHERE v1.pathname=v2.pathname AND v1.vid=%d AND v2.vid=%d"
212 " AND (v2.deleted OR v2.chnged OR v1.mrid!=v2.rid)"
213 "UNION "
214 "SELECT pathname, 1, 0, 0, 0"
215 " FROM vfile v1"
216 " WHERE v1.vid=%d"
217 " AND NOT EXISTS(SELECT 1 FROM vfile v2"
218 " WHERE v2.vid=%d AND v2.pathname=v1.pathname)"
219 "UNION "
220 "SELECT pathname, 0, 0, 1, 0"
221 " FROM vfile v2"
222 " WHERE v2.vid=%d"
223 " AND NOT EXISTS(SELECT 1 FROM vfile v1"
224 " WHERE v1.vid=%d AND v1.pathname=v2.pathname)"
225 " ORDER BY 1",
226 rid, vid, rid, vid, vid, rid
227 );
228 }else{
229 blob_appendf(&sql,
230 "SELECT pathname, deleted, chnged , rid==0, rid"
231 " FROM vfile"
232 " WHERE vid=%d"
233 " AND (deleted OR chnged OR rid==0)"
234 " ORDER BY pathname",
235 vid
@@ -240,10 +249,11 @@
240 const char *zPathname = db_column_text(&q,0);
241 int isDeleted = db_column_int(&q, 1);
242 int isChnged = db_column_int(&q,2);
243 int isNew = db_column_int(&q,3);
244 int srcid = db_column_int(&q, 4);
 
245 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
246 char *zToFree = zFullName;
247 int showDiff = 1;
248 if( isDeleted ){
249 printf("DELETED %s\n", zPathname);
@@ -259,10 +269,16 @@
259 printf("ADDED_BY_MERGE %s\n", zPathname);
260 srcid = 0;
261 if( !asNewFile ){ showDiff = 0; }
262 }
263 if( showDiff ){
 
 
 
 
 
 
264 Blob content;
265 if( srcid>0 ){
266 content_get(srcid, &content);
267 }else{
268 blob_zero(&content);
@@ -289,15 +305,21 @@
289 int ignoreEolWs
290 ){
291 char *zName;
292 Blob fname;
293 Blob v1, v2;
 
294 file_tree_name(g.argv[2], &fname, 1);
295 zName = blob_str(&fname);
296 historical_version_of_file(zFrom, zName, &v1, 0);
297 historical_version_of_file(zTo, zName, &v2, 0);
298 diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
 
 
 
 
 
299 blob_reset(&v1);
300 blob_reset(&v2);
301 blob_reset(&fname);
302 }
303
304
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -59,11 +59,15 @@
59 /* Read content of zFile2 into memory */
60 blob_zero(&file2);
61 if( file_size(zFile2)<0 ){
62 zName2 = "/dev/null";
63 }else{
64 if( file_islink(zFile2) ){
65 blob_read_link(&file2, zFile2);
66 }else{
67 blob_read_from_file(&file2, zFile2);
68 }
69 zName2 = zName;
70 }
71
72 /* Compute and output the differences */
73 blob_zero(&out);
@@ -168,13 +172,18 @@
172 const char *zDiffCmd, /* Use this "diff" command */
173 int ignoreEolWs /* Ignore whitespace changes at end of lines */
174 ){
175 Blob fname;
176 Blob content;
177 int isLink;
178 file_tree_name(g.argv[2], &fname, 1);
179 historical_version_of_file(zFrom, blob_str(&fname), &content, &isLink, 0);
180 if( !isLink != !file_islink(zFrom) ){
181 printf("cannot compute difference between symlink and regular file\n");
182 }else{
183 diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
184 }
185 blob_reset(&content);
186 blob_reset(&fname);
187 }
188
189 /*
@@ -204,32 +213,32 @@
213 if( !is_a_version(rid) ){
214 fossil_fatal("no such check-in: %s", zFrom);
215 }
216 load_vfile_from_rid(rid);
217 blob_appendf(&sql,
218 "SELECT v2.pathname, v2.deleted, v2.chnged, v2.rid==0, v1.rid, v1.islink"
219 " FROM vfile v1, vfile v2 "
220 " WHERE v1.pathname=v2.pathname AND v1.vid=%d AND v2.vid=%d"
221 " AND (v2.deleted OR v2.chnged OR v1.mrid!=v2.rid)"
222 "UNION "
223 "SELECT pathname, 1, 0, 0, 0, islink"
224 " FROM vfile v1"
225 " WHERE v1.vid=%d"
226 " AND NOT EXISTS(SELECT 1 FROM vfile v2"
227 " WHERE v2.vid=%d AND v2.pathname=v1.pathname)"
228 "UNION "
229 "SELECT pathname, 0, 0, 1, 0, islink"
230 " FROM vfile v2"
231 " WHERE v2.vid=%d"
232 " AND NOT EXISTS(SELECT 1 FROM vfile v1"
233 " WHERE v1.vid=%d AND v1.pathname=v2.pathname)"
234 " ORDER BY 1",
235 rid, vid, rid, vid, vid, rid
236 );
237 }else{
238 blob_appendf(&sql,
239 "SELECT pathname, deleted, chnged , rid==0, rid, islink"
240 " FROM vfile"
241 " WHERE vid=%d"
242 " AND (deleted OR chnged OR rid==0)"
243 " ORDER BY pathname",
244 vid
@@ -240,10 +249,11 @@
249 const char *zPathname = db_column_text(&q,0);
250 int isDeleted = db_column_int(&q, 1);
251 int isChnged = db_column_int(&q,2);
252 int isNew = db_column_int(&q,3);
253 int srcid = db_column_int(&q, 4);
254 int isLink = db_column_int(&q, 5);
255 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
256 char *zToFree = zFullName;
257 int showDiff = 1;
258 if( isDeleted ){
259 printf("DELETED %s\n", zPathname);
@@ -259,10 +269,16 @@
269 printf("ADDED_BY_MERGE %s\n", zPathname);
270 srcid = 0;
271 if( !asNewFile ){ showDiff = 0; }
272 }
273 if( showDiff ){
274 if( !isLink != !file_islink(zFullName) ){
275 diff_print_index(zPathname);
276 printf("--- %s\n+++ %s\n", zPathname, zPathname);
277 printf("cannot compute difference between symlink and regular file\n");
278 continue;
279 }
280 Blob content;
281 if( srcid>0 ){
282 content_get(srcid, &content);
283 }else{
284 blob_zero(&content);
@@ -289,15 +305,21 @@
305 int ignoreEolWs
306 ){
307 char *zName;
308 Blob fname;
309 Blob v1, v2;
310 int isLink1, isLink2;
311 file_tree_name(g.argv[2], &fname, 1);
312 zName = blob_str(&fname);
313 historical_version_of_file(zFrom, zName, &v1, &isLink1, 0);
314 historical_version_of_file(zTo, zName, &v2, &isLink2, 0);
315 if( isLink1 != isLink2 ){
316 printf("--- %s\n+++ %s\n", zName, zName);
317 printf("cannot compute difference between symlink and regular file\n");
318 }else{
319 diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
320 }
321 blob_reset(&v1);
322 blob_reset(&v2);
323 blob_reset(&fname);
324 }
325
326
+110 -4
--- src/file.c
+++ src/file.c
@@ -34,10 +34,22 @@
3434
# define stat _stati64
3535
#else
3636
static struct stat fileStat;
3737
#endif
3838
static int fileStatValid = 0;
39
+
40
+int fossil_stat(const char *zFilename, struct stat *buf){
41
+#if !defined(_WIN32)
42
+ if( g.allowSymlinks ){
43
+ return lstat(zFilename, buf);
44
+ }else{
45
+ return stat(zFilename, buf);
46
+ }
47
+#else
48
+ return stat(zFilename, buf);
49
+#endif
50
+}
3951
4052
/*
4153
** Fill in the fileStat variable for the file named zFilename.
4254
** If zFilename==0, then use the previous value of fileStat if
4355
** there is a previous value.
@@ -47,11 +59,11 @@
4759
static int getStat(const char *zFilename){
4860
int rc = 0;
4961
if( zFilename==0 ){
5062
if( fileStatValid==0 ) rc = 1;
5163
}else{
52
- if( stat(zFilename, &fileStat)!=0 ){
64
+ if( fossil_stat(zFilename, &fileStat)!=0 ){
5365
fileStatValid = 0;
5466
rc = 1;
5567
}else{
5668
fileStatValid = 1;
5769
rc = 0;
@@ -76,18 +88,98 @@
7688
** recently stat-ed file.
7789
*/
7890
i64 file_mtime(const char *zFilename){
7991
return getStat(zFilename) ? -1 : fileStat.st_mtime;
8092
}
93
+
94
+/*
95
+** Return TRUE if the named file is an ordinary file or symlink
96
+** (if symlinks are allowed).
97
+** Return false for directories, devices, fifos, etc.
98
+*/
99
+int file_isfile_or_link(const char *zFilename){
100
+#if !defined(_WIN32)
101
+ if ( g.allowSymlinks ){
102
+ return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode) || S_ISLNK(fileStat.st_mode);
103
+ }else{
104
+ return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
105
+ }
106
+#else
107
+ return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
108
+#endif
109
+}
81110
82111
/*
83112
** Return TRUE if the named file is an ordinary file. Return false
84
-** for directories, devices, fifos, symlinks, etc.
113
+** for directories, devices, fifos, etc.
114
+**
85115
*/
86116
int file_isfile(const char *zFilename){
87117
return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
88118
}
119
+
120
+/*
121
+** Return TRUE if the named file is a symlink. Return false
122
+** for all other cases.
123
+** On Windows, always return False.
124
+*/
125
+int file_islink(const char *zFilename){
126
+#if !defined(_WIN32)
127
+ if( g.allowSymlinks ){
128
+ return getStat(zFilename) ? 0 : S_ISLNK(fileStat.st_mode);
129
+ }else{
130
+ return 0;
131
+ }
132
+#else
133
+ return 0;
134
+#endif
135
+}
136
+
137
+/*
138
+** Create symlink to file on Unix, or plain-text file with
139
+** symlink target if "allow-symlinks" is off or we're on Windows.
140
+**
141
+** Arguments: target file (symlink will point to it), link file
142
+**/
143
+void create_symlink(const char *zTargetFile, const char *zLinkFile){
144
+#if !defined(_WIN32)
145
+ if( g.allowSymlinks ){
146
+ int i, nName;
147
+ char *zName, zBuf[1000];
148
+
149
+ nName = strlen(zLinkFile);
150
+ if( nName>=sizeof(zBuf) ){
151
+ zName = mprintf("%s", zLinkFile);
152
+ }else{
153
+ zName = zBuf;
154
+ memcpy(zName, zLinkFile, nName+1);
155
+ }
156
+ nName = file_simplify_name(zName, nName);
157
+ for(i=1; i<nName; i++){
158
+ if( zName[i]=='/' ){
159
+ zName[i] = 0;
160
+ if( file_mkdir(zName, 1) ){
161
+ fossil_fatal_recursive("unable to create directory %s", zName);
162
+ return;
163
+ }
164
+ zName[i] = '/';
165
+ }
166
+ }
167
+ if( zName!=zBuf ) free(zName);
168
+
169
+ if( symlink(zTargetFile, zName)!=0 ){
170
+ fossil_fatal_recursive("unable to create symlink \"%s\"", zName);
171
+ }
172
+ }else
173
+#endif
174
+ {
175
+ Blob content;
176
+ blob_set(&content, zTargetFile);
177
+ blob_write_to_file(&content, zLinkFile);
178
+ blob_reset(&content);
179
+ }
180
+}
89181
90182
/*
91183
** Return TRUE if the named file is an executable. Return false
92184
** for directories, devices, fifos, symlinks, etc.
93185
*/
@@ -118,11 +210,19 @@
118210
rc = getStat(zFN);
119211
free(zFN);
120212
}else{
121213
rc = getStat(0);
122214
}
215
+#if !defined(_WIN32)
216
+ if( g.allowSymlinks ){
217
+ return rc ? 0 : (S_ISDIR(fileStat.st_mode) && !S_ISLNK(fileStat.st_mode) ? 1 : 2);
218
+ }else{
219
+ return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
220
+ }
221
+#else
123222
return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
223
+#endif
124224
}
125225
126226
/*
127227
** Return the tail of a file pathname. The tail is the last component
128228
** of the path. For example, the tail of "/a/b/c.d" is "c.d".
@@ -158,11 +258,11 @@
158258
** Set or clear the execute bit on a file.
159259
*/
160260
void file_setexe(const char *zFilename, int onoff){
161261
#if !defined(_WIN32)
162262
struct stat buf;
163
- if( stat(zFilename, &buf)!=0 ) return;
263
+ if( fossil_stat(zFilename, &buf)!=0 || S_ISLNK(buf.st_mode) ) return;
164264
if( onoff ){
165265
if( (buf.st_mode & 0111)!=0111 ){
166266
chmod(zFilename, buf.st_mode | 0111);
167267
}
168268
}else{
@@ -377,12 +477,14 @@
377477
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_size(zName));
378478
printf(" file_size = %s\n", zBuf);
379479
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_mtime(zName));
380480
printf(" file_mtime = %s\n", zBuf);
381481
printf(" file_isfile = %d\n", file_isfile(zName));
482
+ printf(" file_islink = %d\n", file_islink(zName));
382483
printf(" file_isexe = %d\n", file_isexe(zName));
383484
printf(" file_isdir = %d\n", file_isdir(zName));
485
+ printf(" file_isfile_or_link = %d\n", file_isfile_or_link(zName));
384486
}
385487
}
386488
387489
/*
388490
** Return TRUE if the given filename is canonical.
@@ -632,10 +734,14 @@
632734
Blob onDisk;
633735
634736
iSize = file_size(zName);
635737
if( iSize<0 ) return 0;
636738
if( iSize!=blob_size(pContent) ) return 0;
637
- blob_read_from_file(&onDisk, zName);
739
+ if( file_islink(zName) ){
740
+ blob_read_link(&onDisk, zName);
741
+ }else{
742
+ blob_read_from_file(&onDisk, zName);
743
+ }
638744
rc = blob_compare(&onDisk, pContent);
639745
blob_reset(&onDisk);
640746
return rc==0;
641747
}
642748
--- src/file.c
+++ src/file.c
@@ -34,10 +34,22 @@
34 # define stat _stati64
35 #else
36 static struct stat fileStat;
37 #endif
38 static int fileStatValid = 0;
 
 
 
 
 
 
 
 
 
 
 
 
39
40 /*
41 ** Fill in the fileStat variable for the file named zFilename.
42 ** If zFilename==0, then use the previous value of fileStat if
43 ** there is a previous value.
@@ -47,11 +59,11 @@
47 static int getStat(const char *zFilename){
48 int rc = 0;
49 if( zFilename==0 ){
50 if( fileStatValid==0 ) rc = 1;
51 }else{
52 if( stat(zFilename, &fileStat)!=0 ){
53 fileStatValid = 0;
54 rc = 1;
55 }else{
56 fileStatValid = 1;
57 rc = 0;
@@ -76,18 +88,98 @@
76 ** recently stat-ed file.
77 */
78 i64 file_mtime(const char *zFilename){
79 return getStat(zFilename) ? -1 : fileStat.st_mtime;
80 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
82 /*
83 ** Return TRUE if the named file is an ordinary file. Return false
84 ** for directories, devices, fifos, symlinks, etc.
 
85 */
86 int file_isfile(const char *zFilename){
87 return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
88 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90 /*
91 ** Return TRUE if the named file is an executable. Return false
92 ** for directories, devices, fifos, symlinks, etc.
93 */
@@ -118,11 +210,19 @@
118 rc = getStat(zFN);
119 free(zFN);
120 }else{
121 rc = getStat(0);
122 }
 
 
 
 
 
 
 
123 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
 
124 }
125
126 /*
127 ** Return the tail of a file pathname. The tail is the last component
128 ** of the path. For example, the tail of "/a/b/c.d" is "c.d".
@@ -158,11 +258,11 @@
158 ** Set or clear the execute bit on a file.
159 */
160 void file_setexe(const char *zFilename, int onoff){
161 #if !defined(_WIN32)
162 struct stat buf;
163 if( stat(zFilename, &buf)!=0 ) return;
164 if( onoff ){
165 if( (buf.st_mode & 0111)!=0111 ){
166 chmod(zFilename, buf.st_mode | 0111);
167 }
168 }else{
@@ -377,12 +477,14 @@
377 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_size(zName));
378 printf(" file_size = %s\n", zBuf);
379 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_mtime(zName));
380 printf(" file_mtime = %s\n", zBuf);
381 printf(" file_isfile = %d\n", file_isfile(zName));
 
382 printf(" file_isexe = %d\n", file_isexe(zName));
383 printf(" file_isdir = %d\n", file_isdir(zName));
 
384 }
385 }
386
387 /*
388 ** Return TRUE if the given filename is canonical.
@@ -632,10 +734,14 @@
632 Blob onDisk;
633
634 iSize = file_size(zName);
635 if( iSize<0 ) return 0;
636 if( iSize!=blob_size(pContent) ) return 0;
637 blob_read_from_file(&onDisk, zName);
 
 
 
 
638 rc = blob_compare(&onDisk, pContent);
639 blob_reset(&onDisk);
640 return rc==0;
641 }
642
--- src/file.c
+++ src/file.c
@@ -34,10 +34,22 @@
34 # define stat _stati64
35 #else
36 static struct stat fileStat;
37 #endif
38 static int fileStatValid = 0;
39
40 int fossil_stat(const char *zFilename, struct stat *buf){
41 #if !defined(_WIN32)
42 if( g.allowSymlinks ){
43 return lstat(zFilename, buf);
44 }else{
45 return stat(zFilename, buf);
46 }
47 #else
48 return stat(zFilename, buf);
49 #endif
50 }
51
52 /*
53 ** Fill in the fileStat variable for the file named zFilename.
54 ** If zFilename==0, then use the previous value of fileStat if
55 ** there is a previous value.
@@ -47,11 +59,11 @@
59 static int getStat(const char *zFilename){
60 int rc = 0;
61 if( zFilename==0 ){
62 if( fileStatValid==0 ) rc = 1;
63 }else{
64 if( fossil_stat(zFilename, &fileStat)!=0 ){
65 fileStatValid = 0;
66 rc = 1;
67 }else{
68 fileStatValid = 1;
69 rc = 0;
@@ -76,18 +88,98 @@
88 ** recently stat-ed file.
89 */
90 i64 file_mtime(const char *zFilename){
91 return getStat(zFilename) ? -1 : fileStat.st_mtime;
92 }
93
94 /*
95 ** Return TRUE if the named file is an ordinary file or symlink
96 ** (if symlinks are allowed).
97 ** Return false for directories, devices, fifos, etc.
98 */
99 int file_isfile_or_link(const char *zFilename){
100 #if !defined(_WIN32)
101 if ( g.allowSymlinks ){
102 return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode) || S_ISLNK(fileStat.st_mode);
103 }else{
104 return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
105 }
106 #else
107 return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
108 #endif
109 }
110
111 /*
112 ** Return TRUE if the named file is an ordinary file. Return false
113 ** for directories, devices, fifos, etc.
114 **
115 */
116 int file_isfile(const char *zFilename){
117 return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
118 }
119
120 /*
121 ** Return TRUE if the named file is a symlink. Return false
122 ** for all other cases.
123 ** On Windows, always return False.
124 */
125 int file_islink(const char *zFilename){
126 #if !defined(_WIN32)
127 if( g.allowSymlinks ){
128 return getStat(zFilename) ? 0 : S_ISLNK(fileStat.st_mode);
129 }else{
130 return 0;
131 }
132 #else
133 return 0;
134 #endif
135 }
136
137 /*
138 ** Create symlink to file on Unix, or plain-text file with
139 ** symlink target if "allow-symlinks" is off or we're on Windows.
140 **
141 ** Arguments: target file (symlink will point to it), link file
142 **/
143 void create_symlink(const char *zTargetFile, const char *zLinkFile){
144 #if !defined(_WIN32)
145 if( g.allowSymlinks ){
146 int i, nName;
147 char *zName, zBuf[1000];
148
149 nName = strlen(zLinkFile);
150 if( nName>=sizeof(zBuf) ){
151 zName = mprintf("%s", zLinkFile);
152 }else{
153 zName = zBuf;
154 memcpy(zName, zLinkFile, nName+1);
155 }
156 nName = file_simplify_name(zName, nName);
157 for(i=1; i<nName; i++){
158 if( zName[i]=='/' ){
159 zName[i] = 0;
160 if( file_mkdir(zName, 1) ){
161 fossil_fatal_recursive("unable to create directory %s", zName);
162 return;
163 }
164 zName[i] = '/';
165 }
166 }
167 if( zName!=zBuf ) free(zName);
168
169 if( symlink(zTargetFile, zName)!=0 ){
170 fossil_fatal_recursive("unable to create symlink \"%s\"", zName);
171 }
172 }else
173 #endif
174 {
175 Blob content;
176 blob_set(&content, zTargetFile);
177 blob_write_to_file(&content, zLinkFile);
178 blob_reset(&content);
179 }
180 }
181
182 /*
183 ** Return TRUE if the named file is an executable. Return false
184 ** for directories, devices, fifos, symlinks, etc.
185 */
@@ -118,11 +210,19 @@
210 rc = getStat(zFN);
211 free(zFN);
212 }else{
213 rc = getStat(0);
214 }
215 #if !defined(_WIN32)
216 if( g.allowSymlinks ){
217 return rc ? 0 : (S_ISDIR(fileStat.st_mode) && !S_ISLNK(fileStat.st_mode) ? 1 : 2);
218 }else{
219 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
220 }
221 #else
222 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
223 #endif
224 }
225
226 /*
227 ** Return the tail of a file pathname. The tail is the last component
228 ** of the path. For example, the tail of "/a/b/c.d" is "c.d".
@@ -158,11 +258,11 @@
258 ** Set or clear the execute bit on a file.
259 */
260 void file_setexe(const char *zFilename, int onoff){
261 #if !defined(_WIN32)
262 struct stat buf;
263 if( fossil_stat(zFilename, &buf)!=0 || S_ISLNK(buf.st_mode) ) return;
264 if( onoff ){
265 if( (buf.st_mode & 0111)!=0111 ){
266 chmod(zFilename, buf.st_mode | 0111);
267 }
268 }else{
@@ -377,12 +477,14 @@
477 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_size(zName));
478 printf(" file_size = %s\n", zBuf);
479 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_mtime(zName));
480 printf(" file_mtime = %s\n", zBuf);
481 printf(" file_isfile = %d\n", file_isfile(zName));
482 printf(" file_islink = %d\n", file_islink(zName));
483 printf(" file_isexe = %d\n", file_isexe(zName));
484 printf(" file_isdir = %d\n", file_isdir(zName));
485 printf(" file_isfile_or_link = %d\n", file_isfile_or_link(zName));
486 }
487 }
488
489 /*
490 ** Return TRUE if the given filename is canonical.
@@ -632,10 +734,14 @@
734 Blob onDisk;
735
736 iSize = file_size(zName);
737 if( iSize<0 ) return 0;
738 if( iSize!=blob_size(pContent) ) return 0;
739 if( file_islink(zName) ){
740 blob_read_link(&onDisk, zName);
741 }else{
742 blob_read_from_file(&onDisk, zName);
743 }
744 rc = blob_compare(&onDisk, pContent);
745 blob_reset(&onDisk);
746 return rc==0;
747 }
748
+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, NULL, 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, NULL, 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
+12
--- src/import.c
+++ src/import.c
@@ -30,10 +30,11 @@
3030
char *zName; /* Name of a file */
3131
char *zUuid; /* UUID of the file */
3232
char *zPrior; /* Prior name if the name was changed */
3333
char isFrom; /* True if obtained from the parent */
3434
char isExe; /* True if executable */
35
+ char isLink; /* True if symlink */
3536
};
3637
#endif
3738
3839
3940
/*
@@ -58,10 +59,11 @@
5859
char **azMerge; /* Merge values */
5960
int nFile; /* Number of aFile values */
6061
int nFileAlloc; /* Number of slots in aFile[] */
6162
ImportFile *aFile; /* Information about files in a commit */
6263
int fromLoaded; /* True zFrom content loaded into aFile[] */
64
+ int hasLinks; /* True if git repository contains symlinks */
6365
} gg;
6466
6567
/*
6668
** Duplicate a string.
6769
*/
@@ -229,10 +231,13 @@
229231
const char *zUuid = gg.aFile[i].zUuid;
230232
if( zUuid==0 ) continue;
231233
blob_appendf(&record, "F %F %s", gg.aFile[i].zName, zUuid);
232234
if( gg.aFile[i].isExe ){
233235
blob_append(&record, " x\n", 3);
236
+ }else if( gg.aFile[i].isLink ){
237
+ blob_append(&record, " l\n", 3);
238
+ gg.hasLinks = 1;
234239
}else{
235240
blob_append(&record, "\n", 1);
236241
}
237242
}
238243
if( gg.zFrom ){
@@ -371,10 +376,11 @@
371376
manifest_file_rewind(p);
372377
while( (pOld = manifest_file_next(p, 0))!=0 ){
373378
pNew = import_add_file();
374379
pNew->zName = fossil_strdup(pOld->zName);
375380
pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0;
381
+ pNew->isLink = pOld->zPerm && strstr(pOld->zPerm, "l")!=0;
376382
pNew->zUuid = fossil_strdup(pOld->zUuid);
377383
pNew->isFrom = 1;
378384
}
379385
manifest_destroy(p);
380386
}
@@ -526,10 +532,11 @@
526532
if( pFile==0 ){
527533
pFile = import_add_file();
528534
pFile->zName = fossil_strdup(zName);
529535
}
530536
pFile->isExe = (fossil_strcmp(zPerm, "100755")==0);
537
+ pFile->isLink = (fossil_strcmp(zPerm, "120000")==0);
531538
fossil_free(pFile->zUuid);
532539
pFile->zUuid = resolve_committish(zUuid);
533540
pFile->isFrom = 0;
534541
}else
535542
if( memcmp(zLine, "D ", 2)==0 ){
@@ -563,10 +570,11 @@
563570
pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
564571
}else{
565572
pNew->zName = fossil_strdup(pFile->zName);
566573
}
567574
pNew->isExe = pFile->isExe;
575
+ pNew->isLink = pFile->isLink;
568576
pNew->zUuid = fossil_strdup(pFile->zUuid);
569577
pNew->isFrom = 0;
570578
}
571579
}else
572580
if( memcmp(zLine, "R ", 2)==0 ){
@@ -586,10 +594,11 @@
586594
}else{
587595
pNew->zName = fossil_strdup(pFile->zName);
588596
}
589597
pNew->zPrior = pFile->zName;
590598
pNew->isExe = pFile->isExe;
599
+ pNew->isLink = pFile->isLink;
591600
pNew->zUuid = pFile->zUuid;
592601
pNew->isFrom = 0;
593602
gg.nFile--;
594603
*pFile = *pNew;
595604
memset(pNew, 0, sizeof(*pNew));
@@ -606,10 +615,13 @@
606615
{
607616
goto malformed_line;
608617
}
609618
}
610619
gg.xFinish();
620
+ if( gg.hasLinks ){
621
+ db_set_int("allow-symlinks", 1, 0);
622
+ }
611623
import_reset(1);
612624
return;
613625
614626
malformed_line:
615627
trim_newline(zLine);
616628
--- src/import.c
+++ src/import.c
@@ -30,10 +30,11 @@
30 char *zName; /* Name of a file */
31 char *zUuid; /* UUID of the file */
32 char *zPrior; /* Prior name if the name was changed */
33 char isFrom; /* True if obtained from the parent */
34 char isExe; /* True if executable */
 
35 };
36 #endif
37
38
39 /*
@@ -58,10 +59,11 @@
58 char **azMerge; /* Merge values */
59 int nFile; /* Number of aFile values */
60 int nFileAlloc; /* Number of slots in aFile[] */
61 ImportFile *aFile; /* Information about files in a commit */
62 int fromLoaded; /* True zFrom content loaded into aFile[] */
 
63 } gg;
64
65 /*
66 ** Duplicate a string.
67 */
@@ -229,10 +231,13 @@
229 const char *zUuid = gg.aFile[i].zUuid;
230 if( zUuid==0 ) continue;
231 blob_appendf(&record, "F %F %s", gg.aFile[i].zName, zUuid);
232 if( gg.aFile[i].isExe ){
233 blob_append(&record, " x\n", 3);
 
 
 
234 }else{
235 blob_append(&record, "\n", 1);
236 }
237 }
238 if( gg.zFrom ){
@@ -371,10 +376,11 @@
371 manifest_file_rewind(p);
372 while( (pOld = manifest_file_next(p, 0))!=0 ){
373 pNew = import_add_file();
374 pNew->zName = fossil_strdup(pOld->zName);
375 pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0;
 
376 pNew->zUuid = fossil_strdup(pOld->zUuid);
377 pNew->isFrom = 1;
378 }
379 manifest_destroy(p);
380 }
@@ -526,10 +532,11 @@
526 if( pFile==0 ){
527 pFile = import_add_file();
528 pFile->zName = fossil_strdup(zName);
529 }
530 pFile->isExe = (fossil_strcmp(zPerm, "100755")==0);
 
531 fossil_free(pFile->zUuid);
532 pFile->zUuid = resolve_committish(zUuid);
533 pFile->isFrom = 0;
534 }else
535 if( memcmp(zLine, "D ", 2)==0 ){
@@ -563,10 +570,11 @@
563 pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
564 }else{
565 pNew->zName = fossil_strdup(pFile->zName);
566 }
567 pNew->isExe = pFile->isExe;
 
568 pNew->zUuid = fossil_strdup(pFile->zUuid);
569 pNew->isFrom = 0;
570 }
571 }else
572 if( memcmp(zLine, "R ", 2)==0 ){
@@ -586,10 +594,11 @@
586 }else{
587 pNew->zName = fossil_strdup(pFile->zName);
588 }
589 pNew->zPrior = pFile->zName;
590 pNew->isExe = pFile->isExe;
 
591 pNew->zUuid = pFile->zUuid;
592 pNew->isFrom = 0;
593 gg.nFile--;
594 *pFile = *pNew;
595 memset(pNew, 0, sizeof(*pNew));
@@ -606,10 +615,13 @@
606 {
607 goto malformed_line;
608 }
609 }
610 gg.xFinish();
 
 
 
611 import_reset(1);
612 return;
613
614 malformed_line:
615 trim_newline(zLine);
616
--- src/import.c
+++ src/import.c
@@ -30,10 +30,11 @@
30 char *zName; /* Name of a file */
31 char *zUuid; /* UUID of the file */
32 char *zPrior; /* Prior name if the name was changed */
33 char isFrom; /* True if obtained from the parent */
34 char isExe; /* True if executable */
35 char isLink; /* True if symlink */
36 };
37 #endif
38
39
40 /*
@@ -58,10 +59,11 @@
59 char **azMerge; /* Merge values */
60 int nFile; /* Number of aFile values */
61 int nFileAlloc; /* Number of slots in aFile[] */
62 ImportFile *aFile; /* Information about files in a commit */
63 int fromLoaded; /* True zFrom content loaded into aFile[] */
64 int hasLinks; /* True if git repository contains symlinks */
65 } gg;
66
67 /*
68 ** Duplicate a string.
69 */
@@ -229,10 +231,13 @@
231 const char *zUuid = gg.aFile[i].zUuid;
232 if( zUuid==0 ) continue;
233 blob_appendf(&record, "F %F %s", gg.aFile[i].zName, zUuid);
234 if( gg.aFile[i].isExe ){
235 blob_append(&record, " x\n", 3);
236 }else if( gg.aFile[i].isLink ){
237 blob_append(&record, " l\n", 3);
238 gg.hasLinks = 1;
239 }else{
240 blob_append(&record, "\n", 1);
241 }
242 }
243 if( gg.zFrom ){
@@ -371,10 +376,11 @@
376 manifest_file_rewind(p);
377 while( (pOld = manifest_file_next(p, 0))!=0 ){
378 pNew = import_add_file();
379 pNew->zName = fossil_strdup(pOld->zName);
380 pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0;
381 pNew->isLink = pOld->zPerm && strstr(pOld->zPerm, "l")!=0;
382 pNew->zUuid = fossil_strdup(pOld->zUuid);
383 pNew->isFrom = 1;
384 }
385 manifest_destroy(p);
386 }
@@ -526,10 +532,11 @@
532 if( pFile==0 ){
533 pFile = import_add_file();
534 pFile->zName = fossil_strdup(zName);
535 }
536 pFile->isExe = (fossil_strcmp(zPerm, "100755")==0);
537 pFile->isLink = (fossil_strcmp(zPerm, "120000")==0);
538 fossil_free(pFile->zUuid);
539 pFile->zUuid = resolve_committish(zUuid);
540 pFile->isFrom = 0;
541 }else
542 if( memcmp(zLine, "D ", 2)==0 ){
@@ -563,10 +570,11 @@
570 pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
571 }else{
572 pNew->zName = fossil_strdup(pFile->zName);
573 }
574 pNew->isExe = pFile->isExe;
575 pNew->isLink = pFile->isLink;
576 pNew->zUuid = fossil_strdup(pFile->zUuid);
577 pNew->isFrom = 0;
578 }
579 }else
580 if( memcmp(zLine, "R ", 2)==0 ){
@@ -586,10 +594,11 @@
594 }else{
595 pNew->zName = fossil_strdup(pFile->zName);
596 }
597 pNew->zPrior = pFile->zName;
598 pNew->isExe = pFile->isExe;
599 pNew->isLink = pFile->isLink;
600 pNew->zUuid = pFile->zUuid;
601 pNew->isFrom = 0;
602 gg.nFile--;
603 *pFile = *pNew;
604 memset(pNew, 0, sizeof(*pNew));
@@ -606,10 +615,13 @@
615 {
616 goto malformed_line;
617 }
618 }
619 gg.xFinish();
620 if( gg.hasLinks ){
621 db_set_int("allow-symlinks", 1, 0);
622 }
623 import_reset(1);
624 return;
625
626 malformed_line:
627 trim_newline(zLine);
628
+2
--- src/main.c
+++ src/main.c
@@ -150,10 +150,12 @@
150150
const char *azAuxName[MX_AUX]; /* Name of each aux() or option() value */
151151
char *azAuxParam[MX_AUX]; /* Param of each aux() or option() value */
152152
const char *azAuxVal[MX_AUX]; /* Value of each aux() or option() value */
153153
const char **azAuxOpt[MX_AUX]; /* Options of each option() value */
154154
int anAuxCols[MX_AUX]; /* Number of columns for option() values */
155
+
156
+ int allowSymlinks; /* Cached "allow-symlinks" option */
155157
};
156158
157159
/*
158160
** Macro for debugging:
159161
*/
160162
--- src/main.c
+++ src/main.c
@@ -150,10 +150,12 @@
150 const char *azAuxName[MX_AUX]; /* Name of each aux() or option() value */
151 char *azAuxParam[MX_AUX]; /* Param of each aux() or option() value */
152 const char *azAuxVal[MX_AUX]; /* Value of each aux() or option() value */
153 const char **azAuxOpt[MX_AUX]; /* Options of each option() value */
154 int anAuxCols[MX_AUX]; /* Number of columns for option() values */
 
 
155 };
156
157 /*
158 ** Macro for debugging:
159 */
160
--- src/main.c
+++ src/main.c
@@ -150,10 +150,12 @@
150 const char *azAuxName[MX_AUX]; /* Name of each aux() or option() value */
151 char *azAuxParam[MX_AUX]; /* Param of each aux() or option() value */
152 const char *azAuxVal[MX_AUX]; /* Value of each aux() or option() value */
153 const char **azAuxOpt[MX_AUX]; /* Options of each option() value */
154 int anAuxCols[MX_AUX]; /* Number of columns for option() values */
155
156 int allowSymlinks; /* Cached "allow-symlinks" option */
157 };
158
159 /*
160 ** Macro for debugging:
161 */
162
+51 -31
--- src/merge.c
+++ src/merge.c
@@ -159,11 +159,13 @@
159159
" chnged BOOLEAN," /* True if current version has been edited */
160160
" ridv INTEGER," /* Record ID for current version */
161161
" ridp INTEGER," /* Record ID for pivot */
162162
" ridm INTEGER," /* Record ID for merge */
163163
" fnp TEXT," /* The filename in the pivot */
164
- " fnm TEXT" /* the filename in the merged version */
164
+ " fnm TEXT," /* the filename in the merged version */
165
+ " islinkv BOOLEAN," /* True if current version is a symlink */
166
+ " islinkm BOOLEAN" /* True if merged version in is a symlink */
165167
");"
166168
);
167169
168170
/* Add files found in V
169171
*/
@@ -303,10 +305,21 @@
303305
vfile_to_disk(0, idm, 0, 0);
304306
}
305307
}
306308
db_finalize(&q);
307309
310
+ /*
311
+ ** Add islink information for files in V and M
312
+ **
313
+ */
314
+ db_multi_exec(
315
+ "UPDATE fv SET"
316
+ " islinkv=coalesce((SELECT islink FROM vfile WHERE vid=%d AND pathname=fnm),0),"
317
+ " islinkm=coalesce((SELECT islink FROM vfile WHERE vid=%d AND pathname=fnm),0)",
318
+ vid, mid
319
+ );
320
+
308321
/*
309322
** Find files that have changed from P->M but not P->V.
310323
** Copy the M content over into V.
311324
*/
312325
db_prepare(&q,
@@ -332,11 +345,11 @@
332345
333346
/*
334347
** Do a three-way merge on files that have changes on both P->M and P->V.
335348
*/
336349
db_prepare(&q,
337
- "SELECT ridm, idv, ridp, ridv, %s, fn FROM fv"
350
+ "SELECT ridm, idv, ridp, ridv, %s, fn, islinkv, islinkm FROM fv"
338351
" WHERE idp>0 AND idv>0 AND idm>0"
339352
" AND ridm!=ridp AND (ridv!=ridp OR chnged)",
340353
glob_expr("fv.fn", zBinGlob)
341354
);
342355
while( db_step(&q)==SQLITE_ROW ){
@@ -344,48 +357,55 @@
344357
int idv = db_column_int(&q, 1);
345358
int ridp = db_column_int(&q, 2);
346359
int ridv = db_column_int(&q, 3);
347360
int isBinary = db_column_int(&q, 4);
348361
const char *zName = db_column_text(&q, 5);
362
+ int islinkv = db_column_int(&q, 6);
363
+ int islinkm = db_column_int(&q, 7);
349364
int rc;
350365
char *zFullPath;
351366
Blob m, p, v, r;
352367
/* Do a 3-way merge of idp->idm into idp->idv. The results go into idv. */
353368
if( detailFlag ){
354369
printf("MERGE %s (pivot=%d v1=%d v2=%d)\n", zName, ridp, ridm, ridv);
355370
}else{
356371
printf("MERGE %s\n", zName);
357372
}
358
- undo_save(zName);
359
- zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
360
- content_get(ridp, &p);
361
- content_get(ridm, &m);
362
- blob_zero(&v);
363
- blob_read_from_file(&v, zFullPath);
364
- if( isBinary ){
365
- rc = -1;
366
- blob_zero(&r);
367
- }else{
368
- rc = blob_merge(&p, &v, &m, &r);
369
- }
370
- if( rc>=0 ){
371
- if( !nochangeFlag ){
372
- blob_write_to_file(&r, zFullPath);
373
- }
374
- db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", idv);
375
- if( rc>0 ){
376
- printf("***** %d merge conflicts in %s\n", rc, zName);
377
- nConflict++;
378
- }
379
- }else{
380
- printf("***** Cannot merge binary file %s\n", zName);
381
- nConflict++;
382
- }
383
- blob_reset(&p);
384
- blob_reset(&m);
385
- blob_reset(&v);
386
- blob_reset(&r);
373
+ if( islinkv || islinkm /* || file_islink(zFullPath) */ ){
374
+ printf("***** Cannot merge symlink %s\n", zName);
375
+ nConflict++;
376
+ }else{
377
+ undo_save(zName);
378
+ zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
379
+ content_get(ridp, &p);
380
+ content_get(ridm, &m);
381
+ blob_zero(&v);
382
+ blob_read_from_file(&v, zFullPath);
383
+ if( isBinary ){
384
+ rc = -1;
385
+ blob_zero(&r);
386
+ }else{
387
+ rc = blob_merge(&p, &v, &m, &r);
388
+ }
389
+ if( rc>=0 ){
390
+ if( !nochangeFlag ){
391
+ blob_write_to_file(&r, zFullPath);
392
+ }
393
+ db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", idv);
394
+ if( rc>0 ){
395
+ printf("***** %d merge conflicts in %s\n", rc, zName);
396
+ nConflict++;
397
+ }
398
+ }else{
399
+ printf("***** Cannot merge binary file %s\n", zName);
400
+ nConflict++;
401
+ }
402
+ blob_reset(&p);
403
+ blob_reset(&m);
404
+ blob_reset(&v);
405
+ blob_reset(&r);
406
+ }
387407
db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
388408
idv,ridm);
389409
}
390410
db_finalize(&q);
391411
392412
--- src/merge.c
+++ src/merge.c
@@ -159,11 +159,13 @@
159 " chnged BOOLEAN," /* True if current version has been edited */
160 " ridv INTEGER," /* Record ID for current version */
161 " ridp INTEGER," /* Record ID for pivot */
162 " ridm INTEGER," /* Record ID for merge */
163 " fnp TEXT," /* The filename in the pivot */
164 " fnm TEXT" /* the filename in the merged version */
 
 
165 ");"
166 );
167
168 /* Add files found in V
169 */
@@ -303,10 +305,21 @@
303 vfile_to_disk(0, idm, 0, 0);
304 }
305 }
306 db_finalize(&q);
307
 
 
 
 
 
 
 
 
 
 
 
308 /*
309 ** Find files that have changed from P->M but not P->V.
310 ** Copy the M content over into V.
311 */
312 db_prepare(&q,
@@ -332,11 +345,11 @@
332
333 /*
334 ** Do a three-way merge on files that have changes on both P->M and P->V.
335 */
336 db_prepare(&q,
337 "SELECT ridm, idv, ridp, ridv, %s, fn FROM fv"
338 " WHERE idp>0 AND idv>0 AND idm>0"
339 " AND ridm!=ridp AND (ridv!=ridp OR chnged)",
340 glob_expr("fv.fn", zBinGlob)
341 );
342 while( db_step(&q)==SQLITE_ROW ){
@@ -344,48 +357,55 @@
344 int idv = db_column_int(&q, 1);
345 int ridp = db_column_int(&q, 2);
346 int ridv = db_column_int(&q, 3);
347 int isBinary = db_column_int(&q, 4);
348 const char *zName = db_column_text(&q, 5);
 
 
349 int rc;
350 char *zFullPath;
351 Blob m, p, v, r;
352 /* Do a 3-way merge of idp->idm into idp->idv. The results go into idv. */
353 if( detailFlag ){
354 printf("MERGE %s (pivot=%d v1=%d v2=%d)\n", zName, ridp, ridm, ridv);
355 }else{
356 printf("MERGE %s\n", zName);
357 }
358 undo_save(zName);
359 zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
360 content_get(ridp, &p);
361 content_get(ridm, &m);
362 blob_zero(&v);
363 blob_read_from_file(&v, zFullPath);
364 if( isBinary ){
365 rc = -1;
366 blob_zero(&r);
367 }else{
368 rc = blob_merge(&p, &v, &m, &r);
369 }
370 if( rc>=0 ){
371 if( !nochangeFlag ){
372 blob_write_to_file(&r, zFullPath);
373 }
374 db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", idv);
375 if( rc>0 ){
376 printf("***** %d merge conflicts in %s\n", rc, zName);
377 nConflict++;
378 }
379 }else{
380 printf("***** Cannot merge binary file %s\n", zName);
381 nConflict++;
382 }
383 blob_reset(&p);
384 blob_reset(&m);
385 blob_reset(&v);
386 blob_reset(&r);
 
 
 
 
 
387 db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
388 idv,ridm);
389 }
390 db_finalize(&q);
391
392
--- src/merge.c
+++ src/merge.c
@@ -159,11 +159,13 @@
159 " chnged BOOLEAN," /* True if current version has been edited */
160 " ridv INTEGER," /* Record ID for current version */
161 " ridp INTEGER," /* Record ID for pivot */
162 " ridm INTEGER," /* Record ID for merge */
163 " fnp TEXT," /* The filename in the pivot */
164 " fnm TEXT," /* the filename in the merged version */
165 " islinkv BOOLEAN," /* True if current version is a symlink */
166 " islinkm BOOLEAN" /* True if merged version in is a symlink */
167 ");"
168 );
169
170 /* Add files found in V
171 */
@@ -303,10 +305,21 @@
305 vfile_to_disk(0, idm, 0, 0);
306 }
307 }
308 db_finalize(&q);
309
310 /*
311 ** Add islink information for files in V and M
312 **
313 */
314 db_multi_exec(
315 "UPDATE fv SET"
316 " islinkv=coalesce((SELECT islink FROM vfile WHERE vid=%d AND pathname=fnm),0),"
317 " islinkm=coalesce((SELECT islink FROM vfile WHERE vid=%d AND pathname=fnm),0)",
318 vid, mid
319 );
320
321 /*
322 ** Find files that have changed from P->M but not P->V.
323 ** Copy the M content over into V.
324 */
325 db_prepare(&q,
@@ -332,11 +345,11 @@
345
346 /*
347 ** Do a three-way merge on files that have changes on both P->M and P->V.
348 */
349 db_prepare(&q,
350 "SELECT ridm, idv, ridp, ridv, %s, fn, islinkv, islinkm FROM fv"
351 " WHERE idp>0 AND idv>0 AND idm>0"
352 " AND ridm!=ridp AND (ridv!=ridp OR chnged)",
353 glob_expr("fv.fn", zBinGlob)
354 );
355 while( db_step(&q)==SQLITE_ROW ){
@@ -344,48 +357,55 @@
357 int idv = db_column_int(&q, 1);
358 int ridp = db_column_int(&q, 2);
359 int ridv = db_column_int(&q, 3);
360 int isBinary = db_column_int(&q, 4);
361 const char *zName = db_column_text(&q, 5);
362 int islinkv = db_column_int(&q, 6);
363 int islinkm = db_column_int(&q, 7);
364 int rc;
365 char *zFullPath;
366 Blob m, p, v, r;
367 /* Do a 3-way merge of idp->idm into idp->idv. The results go into idv. */
368 if( detailFlag ){
369 printf("MERGE %s (pivot=%d v1=%d v2=%d)\n", zName, ridp, ridm, ridv);
370 }else{
371 printf("MERGE %s\n", zName);
372 }
373 if( islinkv || islinkm /* || file_islink(zFullPath) */ ){
374 printf("***** Cannot merge symlink %s\n", zName);
375 nConflict++;
376 }else{
377 undo_save(zName);
378 zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
379 content_get(ridp, &p);
380 content_get(ridm, &m);
381 blob_zero(&v);
382 blob_read_from_file(&v, zFullPath);
383 if( isBinary ){
384 rc = -1;
385 blob_zero(&r);
386 }else{
387 rc = blob_merge(&p, &v, &m, &r);
388 }
389 if( rc>=0 ){
390 if( !nochangeFlag ){
391 blob_write_to_file(&r, zFullPath);
392 }
393 db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", idv);
394 if( rc>0 ){
395 printf("***** %d merge conflicts in %s\n", rc, zName);
396 nConflict++;
397 }
398 }else{
399 printf("***** Cannot merge binary file %s\n", zName);
400 nConflict++;
401 }
402 blob_reset(&p);
403 blob_reset(&m);
404 blob_reset(&v);
405 blob_reset(&r);
406 }
407 db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
408 idv,ridm);
409 }
410 db_finalize(&q);
411
412
--- src/schema.c
+++ src/schema.c
@@ -429,10 +429,11 @@
429429
@ id INTEGER PRIMARY KEY, -- ID of the checked out file
430430
@ vid INTEGER REFERENCES blob, -- The baseline this file is part of.
431431
@ chnged INT DEFAULT 0, -- 0:unchnged 1:edited 2:m-chng 3:m-add
432432
@ deleted BOOLEAN DEFAULT 0, -- True if deleted
433433
@ isexe BOOLEAN, -- True if file should be executable
434
+@ islink BOOLEAN, -- True if file should be symlink
434435
@ rid INTEGER, -- Originally from this repository record
435436
@ mrid INTEGER, -- Based on this record due to a merge
436437
@ mtime INTEGER, -- Modification time of file on disk
437438
@ pathname TEXT, -- Full pathname relative to root
438439
@ origname TEXT, -- Original pathname. NULL if unchanged
439440
--- src/schema.c
+++ src/schema.c
@@ -429,10 +429,11 @@
429 @ id INTEGER PRIMARY KEY, -- ID of the checked out file
430 @ vid INTEGER REFERENCES blob, -- The baseline this file is part of.
431 @ chnged INT DEFAULT 0, -- 0:unchnged 1:edited 2:m-chng 3:m-add
432 @ deleted BOOLEAN DEFAULT 0, -- True if deleted
433 @ isexe BOOLEAN, -- True if file should be executable
 
434 @ rid INTEGER, -- Originally from this repository record
435 @ mrid INTEGER, -- Based on this record due to a merge
436 @ mtime INTEGER, -- Modification time of file on disk
437 @ pathname TEXT, -- Full pathname relative to root
438 @ origname TEXT, -- Original pathname. NULL if unchanged
439
--- src/schema.c
+++ src/schema.c
@@ -429,10 +429,11 @@
429 @ id INTEGER PRIMARY KEY, -- ID of the checked out file
430 @ vid INTEGER REFERENCES blob, -- The baseline this file is part of.
431 @ chnged INT DEFAULT 0, -- 0:unchnged 1:edited 2:m-chng 3:m-add
432 @ deleted BOOLEAN DEFAULT 0, -- True if deleted
433 @ isexe BOOLEAN, -- True if file should be executable
434 @ islink BOOLEAN, -- True if file should be symlink
435 @ rid INTEGER, -- Originally from this repository record
436 @ mrid INTEGER, -- Based on this record due to a merge
437 @ mtime INTEGER, -- Modification time of file on disk
438 @ pathname TEXT, -- Full pathname relative to root
439 @ origname TEXT, -- Original pathname. NULL if unchanged
440
+11
--- src/sha1.c
+++ src/sha1.c
@@ -265,10 +265,21 @@
265265
int sha1sum_file(const char *zFilename, Blob *pCksum){
266266
FILE *in;
267267
SHA1Context ctx;
268268
unsigned char zResult[20];
269269
char zBuf[10240];
270
+
271
+ if( file_islink(zFilename) ){
272
+ /* Instead of file content, return sha1 of link destination path */
273
+ Blob destinationPath;
274
+ int rc;
275
+
276
+ blob_read_link(&destinationPath, zFilename);
277
+ rc = sha1sum_blob(&destinationPath, pCksum);
278
+ blob_reset(&destinationPath);
279
+ return rc;
280
+ }
270281
271282
in = fopen(zFilename,"rb");
272283
if( in==0 ){
273284
return 1;
274285
}
275286
--- src/sha1.c
+++ src/sha1.c
@@ -265,10 +265,21 @@
265 int sha1sum_file(const char *zFilename, Blob *pCksum){
266 FILE *in;
267 SHA1Context ctx;
268 unsigned char zResult[20];
269 char zBuf[10240];
 
 
 
 
 
 
 
 
 
 
 
270
271 in = fopen(zFilename,"rb");
272 if( in==0 ){
273 return 1;
274 }
275
--- src/sha1.c
+++ src/sha1.c
@@ -265,10 +265,21 @@
265 int sha1sum_file(const char *zFilename, Blob *pCksum){
266 FILE *in;
267 SHA1Context ctx;
268 unsigned char zResult[20];
269 char zBuf[10240];
270
271 if( file_islink(zFilename) ){
272 /* Instead of file content, return sha1 of link destination path */
273 Blob destinationPath;
274 int rc;
275
276 blob_read_link(&destinationPath, zFilename);
277 rc = sha1sum_blob(&destinationPath, pCksum);
278 blob_reset(&destinationPath);
279 return rc;
280 }
281
282 in = fopen(zFilename,"rb");
283 if( in==0 ){
284 return 1;
285 }
286
+81 -29
--- src/stash.c
+++ src/stash.c
@@ -35,10 +35,11 @@
3535
@ stashid INTEGER REFERENCES stash, -- Stash that contains this file
3636
@ rid INTEGER, -- Baseline content in BLOB table or 0.
3737
@ isAdded BOOLEAN, -- True if this is an added file
3838
@ isRemoved BOOLEAN, -- True if this file is deleted
3939
@ isExec BOOLEAN, -- True if file is executable
40
+@ isLink BOOLEAN, -- True if file is a symlink
4041
@ origname TEXT, -- Original filename
4142
@ newname TEXT, -- New name for file at next check-in
4243
@ delta BLOB, -- Delta from baseline. Content if rid=0
4344
@ PRIMARY KEY(origname, stashid)
4445
@ );
@@ -61,11 +62,11 @@
6162
zFile = mprintf("%/", zFName);
6263
file_tree_name(zFile, &fname, 1);
6364
zTreename = blob_str(&fname);
6465
blob_zero(&sql);
6566
blob_appendf(&sql,
66
- "SELECT deleted, isexe, mrid, pathname, coalesce(origname,pathname)"
67
+ "SELECT deleted, isexe, islink, mrid, pathname, coalesce(origname,pathname)"
6768
" FROM vfile"
6869
" WHERE vid=%d AND (chnged OR deleted OR origname NOT NULL OR mrid==0)",
6970
vid
7071
);
7172
if( fossil_strcmp(zTreename,".")!=0 ){
@@ -76,48 +77,62 @@
7677
);
7778
}
7879
db_prepare(&q, blob_str(&sql));
7980
blob_reset(&sql);
8081
db_prepare(&ins,
81
- "INSERT INTO stashfile(stashid, rid, isAdded, isRemoved, isExec,"
82
+ "INSERT INTO stashfile(stashid, rid, isAdded, isRemoved, isExec, isLink,"
8283
"origname, newname, delta)"
83
- "VALUES(%d,:rid,:isadd,:isrm,:isexe,:orig,:new,:content)",
84
+ "VALUES(%d,:rid,:isadd,:isrm,:isexe,:islink,:orig,:new,:content)",
8485
stashid
8586
);
8687
while( db_step(&q)==SQLITE_ROW ){
8788
int deleted = db_column_int(&q, 0);
88
- int rid = db_column_int(&q, 2);
89
- const char *zName = db_column_text(&q, 3);
90
- const char *zOrig = db_column_text(&q, 4);
89
+ //int isLink = db_column_int(&q, 2);
90
+ int rid = db_column_int(&q, 3);
91
+ const char *zName = db_column_text(&q, 4);
92
+ const char *zOrig = db_column_text(&q, 5);
9193
char *zPath = mprintf("%s%s", g.zLocalRoot, zName);
9294
Blob content;
95
+ int isNewLink = file_islink(zPath);
9396
9497
db_bind_int(&ins, ":rid", rid);
9598
db_bind_int(&ins, ":isadd", rid==0);
9699
db_bind_int(&ins, ":isrm", deleted);
97100
#ifdef _WIN32
98101
db_bind_int(&ins, ":isexe", db_column_int(&q, 1));
102
+ //db_bind_int(&ins, ":islink", isLink);
99103
#endif
100104
db_bind_text(&ins, ":orig", zOrig);
101105
db_bind_text(&ins, ":new", zName);
106
+
102107
if( rid==0 ){
103108
/* A new file */
104
- blob_read_from_file(&content, zPath);
109
+ if( isNewLink ){
110
+ blob_read_link(&content, zPath);
111
+ }else{
112
+ blob_read_from_file(&content, zPath);
113
+ }
105114
db_bind_blob(&ins, ":content", &content);
106115
}else if( deleted ){
107116
db_bind_null(&ins, ":content");
108117
}else{
109118
/* A modified file */
110119
Blob orig;
111120
Blob disk;
112
- blob_read_from_file(&disk, zPath);
121
+
122
+ if( isNewLink ){
123
+ blob_read_link(&disk, zPath);
124
+ }else{
125
+ blob_read_from_file(&disk, zPath);
126
+ }
113127
content_get(rid, &orig);
114128
blob_delta_create(&orig, &disk, &content);
115129
blob_reset(&orig);
116130
blob_reset(&disk);
117131
db_bind_blob(&ins, ":content", &content);
118132
}
133
+ db_bind_int(&ins, ":islink", isNewLink);
119134
db_step(&ins);
120135
db_reset(&ins);
121136
fossil_free(zPath);
122137
blob_reset(&content);
123138
}
@@ -168,19 +183,20 @@
168183
** Apply a stash to the current check-out.
169184
*/
170185
static void stash_apply(int stashid, int nConflict){
171186
Stmt q;
172187
db_prepare(&q,
173
- "SELECT rid, isRemoved, isExec, origname, newname, delta"
188
+ "SELECT rid, isRemoved, isExec, isLink, origname, newname, delta"
174189
" FROM stashfile WHERE stashid=%d",
175190
stashid
176191
);
177192
while( db_step(&q)==SQLITE_ROW ){
178193
int rid = db_column_int(&q, 0);
179194
int isRemoved = db_column_int(&q, 1);
180
- const char *zOrig = db_column_text(&q, 3);
181
- const char *zNew = db_column_text(&q, 4);
195
+ int isLink = db_column_int(&q, 3);
196
+ const char *zOrig = db_column_text(&q, 4);
197
+ const char *zNew = db_column_text(&q, 5);
182198
char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
183199
char *zNPath = mprintf("%s%s", g.zLocalRoot, zNew);
184200
Blob delta;
185201
undo_save(zNew);
186202
blob_zero(&delta);
@@ -191,27 +207,46 @@
191207
}else if( isRemoved ){
192208
printf("DELETE %s\n", zOrig);
193209
unlink(zOPath);
194210
}else{
195211
Blob a, b, out, disk;
212
+ int isNewLink = file_islink(zOPath);
196213
db_ephemeral_blob(&q, 5, &delta);
197
- blob_read_from_file(&disk, zOPath);
214
+ if( isNewLink ){
215
+ blob_read_link(&disk, zOPath);
216
+ }else{
217
+ blob_read_from_file(&disk, zOPath);
218
+ }
198219
content_get(rid, &a);
199220
blob_delta_apply(&a, &delta, &b);
200
- if( blob_compare(&disk, &a)==0 ){
201
- blob_write_to_file(&b, zNPath);
221
+ if( blob_compare(&disk, &a)==0 && isLink == isNewLink ){
222
+ if( isLink || isNewLink ){
223
+ unlink(zNPath);
224
+ }
225
+ if( isLink ){
226
+ create_symlink(blob_str(&b), zNPath);
227
+ }else{
228
+ blob_write_to_file(&b, zNPath);
229
+ }
202230
printf("UPDATE %s\n", zNew);
203231
}else{
204
- int rc = blob_merge(&a, &disk, &b, &out);
205
- blob_write_to_file(&out, zNPath);
232
+ int rc;
233
+ if( isLink || isNewLink ){
234
+ rc = -1;
235
+ blob_zero(&b); /* because we reset it later */
236
+ //TODO write something to disk?
237
+ }else{
238
+ rc = blob_merge(&a, &disk, &b, &out);
239
+ blob_write_to_file(&out, zNPath);
240
+ blob_reset(&out);
241
+ }
206242
if( rc ){
207243
printf("CONFLICT %s\n", zNew);
208244
nConflict++;
209245
}else{
210246
printf("MERGE %s\n", zNew);
211247
}
212
- blob_reset(&out);
213248
}
214249
blob_reset(&a);
215250
blob_reset(&b);
216251
blob_reset(&disk);
217252
}
@@ -221,11 +256,12 @@
221256
unlink(zOPath);
222257
}
223258
}
224259
db_finalize(&q);
225260
if( nConflict ){
226
- printf("WARNING: merge conflicts - see messages above for details.\n");
261
+ printf("WARNING: %d merge conflicts - see messages above for details.\n",
262
+ nConflict);
227263
}
228264
}
229265
230266
/*
231267
** Show the diffs associate with a single stash.
@@ -233,41 +269,57 @@
233269
static void stash_diff(int stashid, const char *zDiffCmd){
234270
Stmt q;
235271
Blob empty;
236272
blob_zero(&empty);
237273
db_prepare(&q,
238
- "SELECT rid, isRemoved, isExec, origname, newname, delta"
274
+ "SELECT rid, isRemoved, isExec, isLink, origname, newname, delta"
239275
" FROM stashfile WHERE stashid=%d",
240276
stashid
241277
);
242278
while( db_step(&q)==SQLITE_ROW ){
243279
int rid = db_column_int(&q, 0);
244280
int isRemoved = db_column_int(&q, 1);
245
- const char *zOrig = db_column_text(&q, 3);
246
- const char *zNew = db_column_text(&q, 4);
281
+ int isLink = db_column_int(&q, 3);
282
+ const char *zOrig = db_column_text(&q, 4);
283
+ const char *zNew = db_column_text(&q, 5);
247284
char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
248285
Blob delta;
249286
if( rid==0 ){
250287
db_ephemeral_blob(&q, 5, &delta);
251288
printf("ADDED %s\n", zNew);
252289
diff_print_index(zNew);
253290
diff_file_mem(&empty, &delta, zNew, zDiffCmd, 0);
254291
}else if( isRemoved ){
255292
printf("DELETE %s\n", zOrig);
256
- blob_read_from_file(&delta, zOPath);
293
+ if( file_islink(zOPath) ){
294
+ blob_read_link(&delta, zOPath);
295
+ }else{
296
+ blob_read_from_file(&delta, zOPath);
297
+ }
257298
diff_print_index(zNew);
258299
diff_file_mem(&delta, &empty, zOrig, zDiffCmd, 0);
259300
}else{
260301
Blob a, b, disk;
302
+ int isOrigLink = file_islink(zOPath);
261303
db_ephemeral_blob(&q, 5, &delta);
262
- blob_read_from_file(&disk, zOPath);
263
- content_get(rid, &a);
264
- blob_delta_apply(&a, &delta, &b);
304
+ if( isOrigLink ){
305
+ blob_read_link(&disk, zOPath);
306
+ }else{
307
+ blob_read_from_file(&disk, zOPath);
308
+ }
265309
printf("CHANGED %s\n", zNew);
266
- diff_file_mem(&disk, &b, zNew, zDiffCmd, 0);
267
- blob_reset(&a);
268
- blob_reset(&b);
310
+ if( !isOrigLink != !isLink ){
311
+ diff_print_index(zNew);
312
+ printf("--- %s\n+++ %s\n", zOrig, zNew);
313
+ printf("cannot compute difference between symlink and regular file\n");
314
+ }else{
315
+ content_get(rid, &a);
316
+ blob_delta_apply(&a, &delta, &b);
317
+ diff_file_mem(&disk, &b, zNew, zDiffCmd, 0);
318
+ blob_reset(&a);
319
+ blob_reset(&b);
320
+ }
269321
blob_reset(&disk);
270322
}
271323
blob_reset(&delta);
272324
}
273325
db_finalize(&q);
@@ -347,11 +399,11 @@
347399
** Forget everything about STASHID. Forget the whole stash if the
348400
** --all flag is used. Individual drops are undoable but --all is not.
349401
**
350402
** fossil stash snapshot ?-m COMMENT? ?FILES...?
351403
**
352
-** Save the current changes in the working tress as a new stash
404
+** Save the current changes in the working tree as a new stash
353405
** but, unlike "save", do not revert those changes.
354406
**
355407
** fossil stash diff ?STASHID?
356408
** fossil stash gdiff ?STASHID?
357409
**
358410
--- src/stash.c
+++ src/stash.c
@@ -35,10 +35,11 @@
35 @ stashid INTEGER REFERENCES stash, -- Stash that contains this file
36 @ rid INTEGER, -- Baseline content in BLOB table or 0.
37 @ isAdded BOOLEAN, -- True if this is an added file
38 @ isRemoved BOOLEAN, -- True if this file is deleted
39 @ isExec BOOLEAN, -- True if file is executable
 
40 @ origname TEXT, -- Original filename
41 @ newname TEXT, -- New name for file at next check-in
42 @ delta BLOB, -- Delta from baseline. Content if rid=0
43 @ PRIMARY KEY(origname, stashid)
44 @ );
@@ -61,11 +62,11 @@
61 zFile = mprintf("%/", zFName);
62 file_tree_name(zFile, &fname, 1);
63 zTreename = blob_str(&fname);
64 blob_zero(&sql);
65 blob_appendf(&sql,
66 "SELECT deleted, isexe, mrid, pathname, coalesce(origname,pathname)"
67 " FROM vfile"
68 " WHERE vid=%d AND (chnged OR deleted OR origname NOT NULL OR mrid==0)",
69 vid
70 );
71 if( fossil_strcmp(zTreename,".")!=0 ){
@@ -76,48 +77,62 @@
76 );
77 }
78 db_prepare(&q, blob_str(&sql));
79 blob_reset(&sql);
80 db_prepare(&ins,
81 "INSERT INTO stashfile(stashid, rid, isAdded, isRemoved, isExec,"
82 "origname, newname, delta)"
83 "VALUES(%d,:rid,:isadd,:isrm,:isexe,:orig,:new,:content)",
84 stashid
85 );
86 while( db_step(&q)==SQLITE_ROW ){
87 int deleted = db_column_int(&q, 0);
88 int rid = db_column_int(&q, 2);
89 const char *zName = db_column_text(&q, 3);
90 const char *zOrig = db_column_text(&q, 4);
 
91 char *zPath = mprintf("%s%s", g.zLocalRoot, zName);
92 Blob content;
 
93
94 db_bind_int(&ins, ":rid", rid);
95 db_bind_int(&ins, ":isadd", rid==0);
96 db_bind_int(&ins, ":isrm", deleted);
97 #ifdef _WIN32
98 db_bind_int(&ins, ":isexe", db_column_int(&q, 1));
 
99 #endif
100 db_bind_text(&ins, ":orig", zOrig);
101 db_bind_text(&ins, ":new", zName);
 
102 if( rid==0 ){
103 /* A new file */
104 blob_read_from_file(&content, zPath);
 
 
 
 
105 db_bind_blob(&ins, ":content", &content);
106 }else if( deleted ){
107 db_bind_null(&ins, ":content");
108 }else{
109 /* A modified file */
110 Blob orig;
111 Blob disk;
112 blob_read_from_file(&disk, zPath);
 
 
 
 
 
113 content_get(rid, &orig);
114 blob_delta_create(&orig, &disk, &content);
115 blob_reset(&orig);
116 blob_reset(&disk);
117 db_bind_blob(&ins, ":content", &content);
118 }
 
119 db_step(&ins);
120 db_reset(&ins);
121 fossil_free(zPath);
122 blob_reset(&content);
123 }
@@ -168,19 +183,20 @@
168 ** Apply a stash to the current check-out.
169 */
170 static void stash_apply(int stashid, int nConflict){
171 Stmt q;
172 db_prepare(&q,
173 "SELECT rid, isRemoved, isExec, origname, newname, delta"
174 " FROM stashfile WHERE stashid=%d",
175 stashid
176 );
177 while( db_step(&q)==SQLITE_ROW ){
178 int rid = db_column_int(&q, 0);
179 int isRemoved = db_column_int(&q, 1);
180 const char *zOrig = db_column_text(&q, 3);
181 const char *zNew = db_column_text(&q, 4);
 
182 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
183 char *zNPath = mprintf("%s%s", g.zLocalRoot, zNew);
184 Blob delta;
185 undo_save(zNew);
186 blob_zero(&delta);
@@ -191,27 +207,46 @@
191 }else if( isRemoved ){
192 printf("DELETE %s\n", zOrig);
193 unlink(zOPath);
194 }else{
195 Blob a, b, out, disk;
 
196 db_ephemeral_blob(&q, 5, &delta);
197 blob_read_from_file(&disk, zOPath);
 
 
 
 
198 content_get(rid, &a);
199 blob_delta_apply(&a, &delta, &b);
200 if( blob_compare(&disk, &a)==0 ){
201 blob_write_to_file(&b, zNPath);
 
 
 
 
 
 
 
202 printf("UPDATE %s\n", zNew);
203 }else{
204 int rc = blob_merge(&a, &disk, &b, &out);
205 blob_write_to_file(&out, zNPath);
 
 
 
 
 
 
 
 
206 if( rc ){
207 printf("CONFLICT %s\n", zNew);
208 nConflict++;
209 }else{
210 printf("MERGE %s\n", zNew);
211 }
212 blob_reset(&out);
213 }
214 blob_reset(&a);
215 blob_reset(&b);
216 blob_reset(&disk);
217 }
@@ -221,11 +256,12 @@
221 unlink(zOPath);
222 }
223 }
224 db_finalize(&q);
225 if( nConflict ){
226 printf("WARNING: merge conflicts - see messages above for details.\n");
 
227 }
228 }
229
230 /*
231 ** Show the diffs associate with a single stash.
@@ -233,41 +269,57 @@
233 static void stash_diff(int stashid, const char *zDiffCmd){
234 Stmt q;
235 Blob empty;
236 blob_zero(&empty);
237 db_prepare(&q,
238 "SELECT rid, isRemoved, isExec, origname, newname, delta"
239 " FROM stashfile WHERE stashid=%d",
240 stashid
241 );
242 while( db_step(&q)==SQLITE_ROW ){
243 int rid = db_column_int(&q, 0);
244 int isRemoved = db_column_int(&q, 1);
245 const char *zOrig = db_column_text(&q, 3);
246 const char *zNew = db_column_text(&q, 4);
 
247 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
248 Blob delta;
249 if( rid==0 ){
250 db_ephemeral_blob(&q, 5, &delta);
251 printf("ADDED %s\n", zNew);
252 diff_print_index(zNew);
253 diff_file_mem(&empty, &delta, zNew, zDiffCmd, 0);
254 }else if( isRemoved ){
255 printf("DELETE %s\n", zOrig);
256 blob_read_from_file(&delta, zOPath);
 
 
 
 
257 diff_print_index(zNew);
258 diff_file_mem(&delta, &empty, zOrig, zDiffCmd, 0);
259 }else{
260 Blob a, b, disk;
 
261 db_ephemeral_blob(&q, 5, &delta);
262 blob_read_from_file(&disk, zOPath);
263 content_get(rid, &a);
264 blob_delta_apply(&a, &delta, &b);
 
 
265 printf("CHANGED %s\n", zNew);
266 diff_file_mem(&disk, &b, zNew, zDiffCmd, 0);
267 blob_reset(&a);
268 blob_reset(&b);
 
 
 
 
 
 
 
 
269 blob_reset(&disk);
270 }
271 blob_reset(&delta);
272 }
273 db_finalize(&q);
@@ -347,11 +399,11 @@
347 ** Forget everything about STASHID. Forget the whole stash if the
348 ** --all flag is used. Individual drops are undoable but --all is not.
349 **
350 ** fossil stash snapshot ?-m COMMENT? ?FILES...?
351 **
352 ** Save the current changes in the working tress as a new stash
353 ** but, unlike "save", do not revert those changes.
354 **
355 ** fossil stash diff ?STASHID?
356 ** fossil stash gdiff ?STASHID?
357 **
358
--- src/stash.c
+++ src/stash.c
@@ -35,10 +35,11 @@
35 @ stashid INTEGER REFERENCES stash, -- Stash that contains this file
36 @ rid INTEGER, -- Baseline content in BLOB table or 0.
37 @ isAdded BOOLEAN, -- True if this is an added file
38 @ isRemoved BOOLEAN, -- True if this file is deleted
39 @ isExec BOOLEAN, -- True if file is executable
40 @ isLink BOOLEAN, -- True if file is a symlink
41 @ origname TEXT, -- Original filename
42 @ newname TEXT, -- New name for file at next check-in
43 @ delta BLOB, -- Delta from baseline. Content if rid=0
44 @ PRIMARY KEY(origname, stashid)
45 @ );
@@ -61,11 +62,11 @@
62 zFile = mprintf("%/", zFName);
63 file_tree_name(zFile, &fname, 1);
64 zTreename = blob_str(&fname);
65 blob_zero(&sql);
66 blob_appendf(&sql,
67 "SELECT deleted, isexe, islink, mrid, pathname, coalesce(origname,pathname)"
68 " FROM vfile"
69 " WHERE vid=%d AND (chnged OR deleted OR origname NOT NULL OR mrid==0)",
70 vid
71 );
72 if( fossil_strcmp(zTreename,".")!=0 ){
@@ -76,48 +77,62 @@
77 );
78 }
79 db_prepare(&q, blob_str(&sql));
80 blob_reset(&sql);
81 db_prepare(&ins,
82 "INSERT INTO stashfile(stashid, rid, isAdded, isRemoved, isExec, isLink,"
83 "origname, newname, delta)"
84 "VALUES(%d,:rid,:isadd,:isrm,:isexe,:islink,:orig,:new,:content)",
85 stashid
86 );
87 while( db_step(&q)==SQLITE_ROW ){
88 int deleted = db_column_int(&q, 0);
89 //int isLink = db_column_int(&q, 2);
90 int rid = db_column_int(&q, 3);
91 const char *zName = db_column_text(&q, 4);
92 const char *zOrig = db_column_text(&q, 5);
93 char *zPath = mprintf("%s%s", g.zLocalRoot, zName);
94 Blob content;
95 int isNewLink = file_islink(zPath);
96
97 db_bind_int(&ins, ":rid", rid);
98 db_bind_int(&ins, ":isadd", rid==0);
99 db_bind_int(&ins, ":isrm", deleted);
100 #ifdef _WIN32
101 db_bind_int(&ins, ":isexe", db_column_int(&q, 1));
102 //db_bind_int(&ins, ":islink", isLink);
103 #endif
104 db_bind_text(&ins, ":orig", zOrig);
105 db_bind_text(&ins, ":new", zName);
106
107 if( rid==0 ){
108 /* A new file */
109 if( isNewLink ){
110 blob_read_link(&content, zPath);
111 }else{
112 blob_read_from_file(&content, zPath);
113 }
114 db_bind_blob(&ins, ":content", &content);
115 }else if( deleted ){
116 db_bind_null(&ins, ":content");
117 }else{
118 /* A modified file */
119 Blob orig;
120 Blob disk;
121
122 if( isNewLink ){
123 blob_read_link(&disk, zPath);
124 }else{
125 blob_read_from_file(&disk, zPath);
126 }
127 content_get(rid, &orig);
128 blob_delta_create(&orig, &disk, &content);
129 blob_reset(&orig);
130 blob_reset(&disk);
131 db_bind_blob(&ins, ":content", &content);
132 }
133 db_bind_int(&ins, ":islink", isNewLink);
134 db_step(&ins);
135 db_reset(&ins);
136 fossil_free(zPath);
137 blob_reset(&content);
138 }
@@ -168,19 +183,20 @@
183 ** Apply a stash to the current check-out.
184 */
185 static void stash_apply(int stashid, int nConflict){
186 Stmt q;
187 db_prepare(&q,
188 "SELECT rid, isRemoved, isExec, isLink, origname, newname, delta"
189 " FROM stashfile WHERE stashid=%d",
190 stashid
191 );
192 while( db_step(&q)==SQLITE_ROW ){
193 int rid = db_column_int(&q, 0);
194 int isRemoved = db_column_int(&q, 1);
195 int isLink = db_column_int(&q, 3);
196 const char *zOrig = db_column_text(&q, 4);
197 const char *zNew = db_column_text(&q, 5);
198 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
199 char *zNPath = mprintf("%s%s", g.zLocalRoot, zNew);
200 Blob delta;
201 undo_save(zNew);
202 blob_zero(&delta);
@@ -191,27 +207,46 @@
207 }else if( isRemoved ){
208 printf("DELETE %s\n", zOrig);
209 unlink(zOPath);
210 }else{
211 Blob a, b, out, disk;
212 int isNewLink = file_islink(zOPath);
213 db_ephemeral_blob(&q, 5, &delta);
214 if( isNewLink ){
215 blob_read_link(&disk, zOPath);
216 }else{
217 blob_read_from_file(&disk, zOPath);
218 }
219 content_get(rid, &a);
220 blob_delta_apply(&a, &delta, &b);
221 if( blob_compare(&disk, &a)==0 && isLink == isNewLink ){
222 if( isLink || isNewLink ){
223 unlink(zNPath);
224 }
225 if( isLink ){
226 create_symlink(blob_str(&b), zNPath);
227 }else{
228 blob_write_to_file(&b, zNPath);
229 }
230 printf("UPDATE %s\n", zNew);
231 }else{
232 int rc;
233 if( isLink || isNewLink ){
234 rc = -1;
235 blob_zero(&b); /* because we reset it later */
236 //TODO write something to disk?
237 }else{
238 rc = blob_merge(&a, &disk, &b, &out);
239 blob_write_to_file(&out, zNPath);
240 blob_reset(&out);
241 }
242 if( rc ){
243 printf("CONFLICT %s\n", zNew);
244 nConflict++;
245 }else{
246 printf("MERGE %s\n", zNew);
247 }
 
248 }
249 blob_reset(&a);
250 blob_reset(&b);
251 blob_reset(&disk);
252 }
@@ -221,11 +256,12 @@
256 unlink(zOPath);
257 }
258 }
259 db_finalize(&q);
260 if( nConflict ){
261 printf("WARNING: %d merge conflicts - see messages above for details.\n",
262 nConflict);
263 }
264 }
265
266 /*
267 ** Show the diffs associate with a single stash.
@@ -233,41 +269,57 @@
269 static void stash_diff(int stashid, const char *zDiffCmd){
270 Stmt q;
271 Blob empty;
272 blob_zero(&empty);
273 db_prepare(&q,
274 "SELECT rid, isRemoved, isExec, isLink, origname, newname, delta"
275 " FROM stashfile WHERE stashid=%d",
276 stashid
277 );
278 while( db_step(&q)==SQLITE_ROW ){
279 int rid = db_column_int(&q, 0);
280 int isRemoved = db_column_int(&q, 1);
281 int isLink = db_column_int(&q, 3);
282 const char *zOrig = db_column_text(&q, 4);
283 const char *zNew = db_column_text(&q, 5);
284 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
285 Blob delta;
286 if( rid==0 ){
287 db_ephemeral_blob(&q, 5, &delta);
288 printf("ADDED %s\n", zNew);
289 diff_print_index(zNew);
290 diff_file_mem(&empty, &delta, zNew, zDiffCmd, 0);
291 }else if( isRemoved ){
292 printf("DELETE %s\n", zOrig);
293 if( file_islink(zOPath) ){
294 blob_read_link(&delta, zOPath);
295 }else{
296 blob_read_from_file(&delta, zOPath);
297 }
298 diff_print_index(zNew);
299 diff_file_mem(&delta, &empty, zOrig, zDiffCmd, 0);
300 }else{
301 Blob a, b, disk;
302 int isOrigLink = file_islink(zOPath);
303 db_ephemeral_blob(&q, 5, &delta);
304 if( isOrigLink ){
305 blob_read_link(&disk, zOPath);
306 }else{
307 blob_read_from_file(&disk, zOPath);
308 }
309 printf("CHANGED %s\n", zNew);
310 if( !isOrigLink != !isLink ){
311 diff_print_index(zNew);
312 printf("--- %s\n+++ %s\n", zOrig, zNew);
313 printf("cannot compute difference between symlink and regular file\n");
314 }else{
315 content_get(rid, &a);
316 blob_delta_apply(&a, &delta, &b);
317 diff_file_mem(&disk, &b, zNew, zDiffCmd, 0);
318 blob_reset(&a);
319 blob_reset(&b);
320 }
321 blob_reset(&disk);
322 }
323 blob_reset(&delta);
324 }
325 db_finalize(&q);
@@ -347,11 +399,11 @@
399 ** Forget everything about STASHID. Forget the whole stash if the
400 ** --all flag is used. Individual drops are undoable but --all is not.
401 **
402 ** fossil stash snapshot ?-m COMMENT? ?FILES...?
403 **
404 ** Save the current changes in the working tree as a new stash
405 ** but, unlike "save", do not revert those changes.
406 **
407 ** fossil stash diff ?STASHID?
408 ** fossil stash gdiff ?STASHID?
409 **
410
+29 -9
--- src/undo.c
+++ src/undo.c
@@ -30,22 +30,28 @@
3030
*/
3131
static void undo_one(const char *zPathname, int redoFlag){
3232
Stmt q;
3333
char *zFullname;
3434
db_prepare(&q,
35
- "SELECT content, existsflag FROM undo WHERE pathname=%Q AND redoflag=%d",
35
+ "SELECT content, existsflag, islink FROM undo WHERE pathname=%Q AND redoflag=%d",
3636
zPathname, redoFlag
3737
);
3838
if( db_step(&q)==SQLITE_ROW ){
3939
int old_exists;
4040
int new_exists;
4141
Blob current;
4242
Blob new;
43
+ int isLink = db_column_int(&q, 2);
4344
zFullname = mprintf("%s/%s", g.zLocalRoot, zPathname);
4445
new_exists = file_size(zFullname)>=0;
46
+ int isNewLink = file_islink(zFullname);
4547
if( new_exists ){
46
- blob_read_from_file(&current, zFullname);
48
+ if( isNewLink ){
49
+ blob_read_link(&current, zFullname);
50
+ }else{
51
+ blob_read_from_file(&current, zFullname);
52
+ }
4753
}else{
4854
blob_zero(&current);
4955
}
5056
blob_zero(&new);
5157
old_exists = db_column_int(&q, 1);
@@ -56,22 +62,29 @@
5662
if( new_exists ){
5763
printf("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
5864
}else{
5965
printf("NEW %s\n", zPathname);
6066
}
61
- blob_write_to_file(&new, zFullname);
67
+ if( new_exists && (isNewLink || isLink) ){
68
+ unlink(zFullname);
69
+ }
70
+ if( isLink ){
71
+ create_symlink(blob_str(&new), zFullname);
72
+ }else{
73
+ blob_write_to_file(&new, zFullname);
74
+ }
6275
}else{
6376
printf("DELETE %s\n", zPathname);
6477
unlink(zFullname);
6578
}
6679
blob_reset(&new);
6780
free(zFullname);
6881
db_finalize(&q);
6982
db_prepare(&q,
70
- "UPDATE undo SET content=:c, existsflag=%d, redoflag=NOT redoflag"
83
+ "UPDATE undo SET content=:c, existsflag=%d, redoflag=NOT redoflag, islink=%d"
7184
" WHERE pathname=%Q",
72
- new_exists, zPathname
85
+ new_exists, isNewLink, zPathname
7386
);
7487
if( new_exists ){
7588
db_bind_blob(&q, ":c", &current);
7689
}
7790
db_step(&q);
@@ -200,10 +213,11 @@
200213
static const char zSql[] =
201214
@ CREATE TABLE %s.undo(
202215
@ pathname TEXT UNIQUE, -- Name of the file
203216
@ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
204217
@ existsflag BOOLEAN, -- True if the file exists
218
+ @ islink BOOLEAN, -- True if the file is symlink
205219
@ content BLOB -- Saved content
206220
@ );
207221
@ CREATE TABLE %s.undo_vfile AS SELECT * FROM vfile;
208222
@ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge;
209223
;
@@ -240,22 +254,28 @@
240254
*/
241255
void undo_save(const char *zPathname){
242256
char *zFullname;
243257
Blob content;
244258
int existsFlag;
259
+ int isLink;
245260
Stmt q;
246261
247262
if( !undoActive ) return;
248263
zFullname = mprintf("%s%s", g.zLocalRoot, zPathname);
249264
existsFlag = file_size(zFullname)>=0;
265
+ isLink = file_islink(zFullname);
250266
db_prepare(&q,
251
- "INSERT OR IGNORE INTO undo(pathname,redoflag,existsflag,content)"
252
- " VALUES(%Q,0,%d,:c)",
253
- zPathname, existsFlag
267
+ "INSERT OR IGNORE INTO undo(pathname,redoflag,existsflag,islink,content)"
268
+ " VALUES(%Q,0,%d,%d,:c)",
269
+ zPathname, existsFlag, isLink
254270
);
255271
if( existsFlag ){
256
- blob_read_from_file(&content, zFullname);
272
+ if( isLink ){
273
+ blob_read_link(&content, zFullname);
274
+ }else{
275
+ blob_read_from_file(&content, zFullname);
276
+ }
257277
db_bind_blob(&q, ":c", &content);
258278
}
259279
free(zFullname);
260280
db_step(&q);
261281
db_finalize(&q);
262282
--- src/undo.c
+++ src/undo.c
@@ -30,22 +30,28 @@
30 */
31 static void undo_one(const char *zPathname, int redoFlag){
32 Stmt q;
33 char *zFullname;
34 db_prepare(&q,
35 "SELECT content, existsflag FROM undo WHERE pathname=%Q AND redoflag=%d",
36 zPathname, redoFlag
37 );
38 if( db_step(&q)==SQLITE_ROW ){
39 int old_exists;
40 int new_exists;
41 Blob current;
42 Blob new;
 
43 zFullname = mprintf("%s/%s", g.zLocalRoot, zPathname);
44 new_exists = file_size(zFullname)>=0;
 
45 if( new_exists ){
46 blob_read_from_file(&current, zFullname);
 
 
 
 
47 }else{
48 blob_zero(&current);
49 }
50 blob_zero(&new);
51 old_exists = db_column_int(&q, 1);
@@ -56,22 +62,29 @@
56 if( new_exists ){
57 printf("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
58 }else{
59 printf("NEW %s\n", zPathname);
60 }
61 blob_write_to_file(&new, zFullname);
 
 
 
 
 
 
 
62 }else{
63 printf("DELETE %s\n", zPathname);
64 unlink(zFullname);
65 }
66 blob_reset(&new);
67 free(zFullname);
68 db_finalize(&q);
69 db_prepare(&q,
70 "UPDATE undo SET content=:c, existsflag=%d, redoflag=NOT redoflag"
71 " WHERE pathname=%Q",
72 new_exists, zPathname
73 );
74 if( new_exists ){
75 db_bind_blob(&q, ":c", &current);
76 }
77 db_step(&q);
@@ -200,10 +213,11 @@
200 static const char zSql[] =
201 @ CREATE TABLE %s.undo(
202 @ pathname TEXT UNIQUE, -- Name of the file
203 @ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
204 @ existsflag BOOLEAN, -- True if the file exists
 
205 @ content BLOB -- Saved content
206 @ );
207 @ CREATE TABLE %s.undo_vfile AS SELECT * FROM vfile;
208 @ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge;
209 ;
@@ -240,22 +254,28 @@
240 */
241 void undo_save(const char *zPathname){
242 char *zFullname;
243 Blob content;
244 int existsFlag;
 
245 Stmt q;
246
247 if( !undoActive ) return;
248 zFullname = mprintf("%s%s", g.zLocalRoot, zPathname);
249 existsFlag = file_size(zFullname)>=0;
 
250 db_prepare(&q,
251 "INSERT OR IGNORE INTO undo(pathname,redoflag,existsflag,content)"
252 " VALUES(%Q,0,%d,:c)",
253 zPathname, existsFlag
254 );
255 if( existsFlag ){
256 blob_read_from_file(&content, zFullname);
 
 
 
 
257 db_bind_blob(&q, ":c", &content);
258 }
259 free(zFullname);
260 db_step(&q);
261 db_finalize(&q);
262
--- src/undo.c
+++ src/undo.c
@@ -30,22 +30,28 @@
30 */
31 static void undo_one(const char *zPathname, int redoFlag){
32 Stmt q;
33 char *zFullname;
34 db_prepare(&q,
35 "SELECT content, existsflag, islink FROM undo WHERE pathname=%Q AND redoflag=%d",
36 zPathname, redoFlag
37 );
38 if( db_step(&q)==SQLITE_ROW ){
39 int old_exists;
40 int new_exists;
41 Blob current;
42 Blob new;
43 int isLink = db_column_int(&q, 2);
44 zFullname = mprintf("%s/%s", g.zLocalRoot, zPathname);
45 new_exists = file_size(zFullname)>=0;
46 int isNewLink = file_islink(zFullname);
47 if( new_exists ){
48 if( isNewLink ){
49 blob_read_link(&current, zFullname);
50 }else{
51 blob_read_from_file(&current, zFullname);
52 }
53 }else{
54 blob_zero(&current);
55 }
56 blob_zero(&new);
57 old_exists = db_column_int(&q, 1);
@@ -56,22 +62,29 @@
62 if( new_exists ){
63 printf("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
64 }else{
65 printf("NEW %s\n", zPathname);
66 }
67 if( new_exists && (isNewLink || isLink) ){
68 unlink(zFullname);
69 }
70 if( isLink ){
71 create_symlink(blob_str(&new), zFullname);
72 }else{
73 blob_write_to_file(&new, zFullname);
74 }
75 }else{
76 printf("DELETE %s\n", zPathname);
77 unlink(zFullname);
78 }
79 blob_reset(&new);
80 free(zFullname);
81 db_finalize(&q);
82 db_prepare(&q,
83 "UPDATE undo SET content=:c, existsflag=%d, redoflag=NOT redoflag, islink=%d"
84 " WHERE pathname=%Q",
85 new_exists, isNewLink, zPathname
86 );
87 if( new_exists ){
88 db_bind_blob(&q, ":c", &current);
89 }
90 db_step(&q);
@@ -200,10 +213,11 @@
213 static const char zSql[] =
214 @ CREATE TABLE %s.undo(
215 @ pathname TEXT UNIQUE, -- Name of the file
216 @ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
217 @ existsflag BOOLEAN, -- True if the file exists
218 @ islink BOOLEAN, -- True if the file is symlink
219 @ content BLOB -- Saved content
220 @ );
221 @ CREATE TABLE %s.undo_vfile AS SELECT * FROM vfile;
222 @ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge;
223 ;
@@ -240,22 +254,28 @@
254 */
255 void undo_save(const char *zPathname){
256 char *zFullname;
257 Blob content;
258 int existsFlag;
259 int isLink;
260 Stmt q;
261
262 if( !undoActive ) return;
263 zFullname = mprintf("%s%s", g.zLocalRoot, zPathname);
264 existsFlag = file_size(zFullname)>=0;
265 isLink = file_islink(zFullname);
266 db_prepare(&q,
267 "INSERT OR IGNORE INTO undo(pathname,redoflag,existsflag,islink,content)"
268 " VALUES(%Q,0,%d,%d,:c)",
269 zPathname, existsFlag, isLink
270 );
271 if( existsFlag ){
272 if( isLink ){
273 blob_read_link(&content, zFullname);
274 }else{
275 blob_read_from_file(&content, zFullname);
276 }
277 db_bind_blob(&q, ":c", &content);
278 }
279 free(zFullname);
280 db_step(&q);
281 db_finalize(&q);
282
+65 -30
--- src/update.c
+++ src/update.c
@@ -195,10 +195,12 @@
195195
"CREATE TEMP TABLE fv("
196196
" fn TEXT PRIMARY KEY," /* The filename relative to root */
197197
" idv INTEGER," /* VFILE entry for current version */
198198
" idt INTEGER," /* VFILE entry for target version */
199199
" chnged BOOLEAN," /* True if current version has been edited */
200
+ " islinkv BOOLEAN," /* True if current file is a link */
201
+ " islinkt BOOLEAN," /* True if target file is a link */
200202
" ridv INTEGER," /* Record ID for current version */
201203
" ridt INTEGER," /* Record ID for target */
202204
" fnt TEXT" /* Filename of same file on target version */
203205
");"
204206
);
@@ -245,21 +247,34 @@
245247
"UPDATE fv SET"
246248
" idt=coalesce((SELECT id FROM vfile WHERE vid=%d AND pathname=fnt),0),"
247249
" ridt=coalesce((SELECT rid FROM vfile WHERE vid=%d AND pathname=fnt),0)",
248250
tid, tid
249251
);
252
+
253
+ /*
254
+ ** Add islink information
255
+ */
256
+ db_multi_exec(
257
+ "UPDATE fv SET"
258
+ " islinkv=coalesce((SELECT islink FROM vfile WHERE vid=%d AND pathname=fnt),0),"
259
+ " islinkt=coalesce((SELECT islink FROM vfile WHERE vid=%d AND pathname=fnt),0)",
260
+ vid, tid
261
+ );
262
+
250263
251264
if( debugFlag ){
252265
db_prepare(&q,
253
- "SELECT rowid, fn, fnt, chnged, ridv, ridt FROM fv"
266
+ "SELECT rowid, fn, fnt, chnged, ridv, ridt, islinkv, islinkt FROM fv"
254267
);
255268
while( db_step(&q)==SQLITE_ROW ){
256
- printf("%3d: ridv=%-4d ridt=%-4d chnged=%d\n",
269
+ printf("%3d: ridv=%-4d ridt=%-4d chnged=%d islinkv=%d islinkt=%d\n",
257270
db_column_int(&q, 0),
258271
db_column_int(&q, 4),
259272
db_column_int(&q, 5),
260
- db_column_int(&q, 3));
273
+ db_column_int(&q, 3),
274
+ db_column_int(&q, 6),
275
+ db_column_int(&q, 7));
261276
printf(" fnv = [%s]\n", db_column_text(&q, 1));
262277
printf(" fnt = [%s]\n", db_column_text(&q, 2));
263278
}
264279
db_finalize(&q);
265280
}
@@ -299,11 +314,11 @@
299314
/*
300315
** Alter the content of the checkout so that it conforms with the
301316
** target
302317
*/
303318
db_prepare(&q,
304
- "SELECT fn, idv, ridv, idt, ridt, chnged, fnt FROM fv ORDER BY 1"
319
+ "SELECT fn, idv, ridv, idt, ridt, chnged, fnt, islinkv, islinkt FROM fv ORDER BY 1"
305320
);
306321
db_prepare(&mtimeXfer,
307322
"UPDATE vfile SET mtime=(SELECT mtime FROM vfile WHERE id=:idv)"
308323
" WHERE id=:idt"
309324
);
@@ -316,10 +331,12 @@
316331
int ridv = db_column_int(&q, 2); /* RecordID for current */
317332
int idt = db_column_int(&q, 3); /* VFILE entry for target */
318333
int ridt = db_column_int(&q, 4); /* RecordID for target */
319334
int chnged = db_column_int(&q, 5); /* Current is edited */
320335
const char *zNewName = db_column_text(&q,6);/* New filename */
336
+ int islinkv = db_column_int(&q, 7); /* Is current file is a link */
337
+ int islinkt = db_column_int(&q, 8); /* Is target file is a link */
321338
char *zFullPath; /* Full pathname of the file */
322339
char *zFullNewPath; /* Full pathname of dest */
323340
char nameChng; /* True if the name changed */
324341
325342
zFullPath = mprintf("%s%s", g.zLocalRoot, zName);
@@ -369,32 +386,38 @@
369386
if( nameChng ){
370387
printf("MERGE %s -> %s\n", zName, zNewName);
371388
}else{
372389
printf("MERGE %s\n", zName);
373390
}
374
- undo_save(zName);
375
- content_get(ridt, &t);
376
- content_get(ridv, &v);
377
- blob_zero(&e);
378
- blob_read_from_file(&e, zFullPath);
379
- rc = blob_merge(&v, &e, &t, &r);
380
- if( rc>=0 ){
381
- if( !nochangeFlag ) blob_write_to_file(&r, zFullNewPath);
382
- if( rc>0 ){
383
- printf("***** %d merge conflicts in %s\n", rc, zNewName);
384
- nConflict++;
385
- }
386
- }else{
387
- if( !nochangeFlag ) blob_write_to_file(&t, zFullNewPath);
388
- printf("***** Cannot merge binary file %s\n", zNewName);
389
- nConflict++;
390
- }
391
- if( nameChng && !nochangeFlag ) unlink(zFullPath);
392
- blob_reset(&v);
393
- blob_reset(&e);
394
- blob_reset(&t);
395
- blob_reset(&r);
391
+ if( islinkv || islinkt /* || file_islink(zFullPath) */ ){
392
+ //if( !nochangeFlag ) blob_write_to_file(&t, zFullNewPath);
393
+ printf("***** Cannot merge symlink %s\n", zNewName);
394
+ nConflict++;
395
+ }else{
396
+ undo_save(zName);
397
+ content_get(ridt, &t);
398
+ content_get(ridv, &v);
399
+ blob_zero(&e);
400
+ blob_read_from_file(&e, zFullPath);
401
+ rc = blob_merge(&v, &e, &t, &r);
402
+ if( rc>=0 ){
403
+ if( !nochangeFlag ) blob_write_to_file(&r, zFullNewPath);
404
+ if( rc>0 ){
405
+ printf("***** %d merge conflicts in %s\n", rc, zNewName);
406
+ nConflict++;
407
+ }
408
+ }else{
409
+ if( !nochangeFlag ) blob_write_to_file(&t, zFullNewPath);
410
+ printf("***** Cannot merge binary file %s\n", zNewName);
411
+ nConflict++;
412
+ }
413
+ if( nameChng && !nochangeFlag ) unlink(zFullPath);
414
+ blob_reset(&v);
415
+ blob_reset(&e);
416
+ blob_reset(&t);
417
+ blob_reset(&r);
418
+ }
396419
}else{
397420
if( chnged ){
398421
if( verboseFlag ) printf("EDITED %s\n", zName);
399422
}else{
400423
db_bind_int(&mtimeXfer, ":idv", idv);
@@ -452,10 +475,11 @@
452475
*/
453476
int historical_version_of_file(
454477
const char *revision, /* The checkin containing the file */
455478
const char *file, /* Full treename of the file */
456479
Blob *content, /* Put the content here */
480
+ int *isLink, /* Put islink here. Pass NULL if you don't need it */
457481
int errCode /* Error code if file not found. Panic if 0. */
458482
){
459483
Manifest *pManifest;
460484
ManifestFile *pFile;
461485
int rid=0;
@@ -475,10 +499,13 @@
475499
manifest_file_rewind(pManifest);
476500
while( (pFile = manifest_file_next(pManifest,0))!=0 ){
477501
if( fossil_strcmp(pFile->zName, file)==0 ){
478502
rid = uuid_to_rid(pFile->zUuid, 0);
479503
manifest_destroy(pManifest);
504
+ if( isLink!=NULL ){
505
+ *isLink = strstr(pFile->zPerm, "l") ? 1 : 0;
506
+ }
480507
return content_get(rid, content);
481508
}
482509
}
483510
manifest_destroy(pManifest);
484511
if( errCode<=0 ){
@@ -550,13 +577,14 @@
550577
);
551578
}
552579
blob_zero(&record);
553580
db_prepare(&q, "SELECT name FROM torevert");
554581
while( db_step(&q)==SQLITE_ROW ){
582
+ int isLink = 0;
555583
zFile = db_column_text(&q, 0);
556584
if( zRevision!=0 ){
557
- errCode = historical_version_of_file(zRevision, zFile, &record, 2);
585
+ errCode = historical_version_of_file(zRevision, zFile, &record, &isLink, 2);
558586
}else{
559587
rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFile);
560588
if( rid==0 ){
561589
errCode = 2;
562590
}else{
@@ -568,20 +596,27 @@
568596
if( errCode==2 ){
569597
fossil_warning("file not in repository: %s", zFile);
570598
}else{
571599
char *zFull = mprintf("%/%/", g.zLocalRoot, zFile);
572600
undo_save(zFile);
573
- blob_write_to_file(&record, zFull);
601
+ if( file_size(zFull)>=0 && (isLink || file_islink(zFull)) ){
602
+ unlink(zFull);
603
+ }
604
+ if( isLink ){
605
+ create_symlink(blob_str(&record), zFull);
606
+ }else{
607
+ blob_write_to_file(&record, zFull);
608
+ }
574609
printf("REVERTED: %s\n", zFile);
575610
if( zRevision==0 ){
576611
sqlite3_int64 mtime = file_mtime(zFull);
577612
db_multi_exec(
578613
"UPDATE vfile"
579
- " SET mtime=%lld, chnged=0, deleted=0,"
614
+ " SET mtime=%lld, chnged=0, deleted=0, islink=%d,"
580615
" pathname=coalesce(origname,pathname), origname=NULL"
581616
" WHERE pathname=%Q",
582
- mtime, zFile
617
+ mtime, isLink, zFile
583618
);
584619
}
585620
free(zFull);
586621
}
587622
blob_reset(&record);
588623
--- src/update.c
+++ src/update.c
@@ -195,10 +195,12 @@
195 "CREATE TEMP TABLE fv("
196 " fn TEXT PRIMARY KEY," /* The filename relative to root */
197 " idv INTEGER," /* VFILE entry for current version */
198 " idt INTEGER," /* VFILE entry for target version */
199 " chnged BOOLEAN," /* True if current version has been edited */
 
 
200 " ridv INTEGER," /* Record ID for current version */
201 " ridt INTEGER," /* Record ID for target */
202 " fnt TEXT" /* Filename of same file on target version */
203 ");"
204 );
@@ -245,21 +247,34 @@
245 "UPDATE fv SET"
246 " idt=coalesce((SELECT id FROM vfile WHERE vid=%d AND pathname=fnt),0),"
247 " ridt=coalesce((SELECT rid FROM vfile WHERE vid=%d AND pathname=fnt),0)",
248 tid, tid
249 );
 
 
 
 
 
 
 
 
 
 
 
250
251 if( debugFlag ){
252 db_prepare(&q,
253 "SELECT rowid, fn, fnt, chnged, ridv, ridt FROM fv"
254 );
255 while( db_step(&q)==SQLITE_ROW ){
256 printf("%3d: ridv=%-4d ridt=%-4d chnged=%d\n",
257 db_column_int(&q, 0),
258 db_column_int(&q, 4),
259 db_column_int(&q, 5),
260 db_column_int(&q, 3));
 
 
261 printf(" fnv = [%s]\n", db_column_text(&q, 1));
262 printf(" fnt = [%s]\n", db_column_text(&q, 2));
263 }
264 db_finalize(&q);
265 }
@@ -299,11 +314,11 @@
299 /*
300 ** Alter the content of the checkout so that it conforms with the
301 ** target
302 */
303 db_prepare(&q,
304 "SELECT fn, idv, ridv, idt, ridt, chnged, fnt FROM fv ORDER BY 1"
305 );
306 db_prepare(&mtimeXfer,
307 "UPDATE vfile SET mtime=(SELECT mtime FROM vfile WHERE id=:idv)"
308 " WHERE id=:idt"
309 );
@@ -316,10 +331,12 @@
316 int ridv = db_column_int(&q, 2); /* RecordID for current */
317 int idt = db_column_int(&q, 3); /* VFILE entry for target */
318 int ridt = db_column_int(&q, 4); /* RecordID for target */
319 int chnged = db_column_int(&q, 5); /* Current is edited */
320 const char *zNewName = db_column_text(&q,6);/* New filename */
 
 
321 char *zFullPath; /* Full pathname of the file */
322 char *zFullNewPath; /* Full pathname of dest */
323 char nameChng; /* True if the name changed */
324
325 zFullPath = mprintf("%s%s", g.zLocalRoot, zName);
@@ -369,32 +386,38 @@
369 if( nameChng ){
370 printf("MERGE %s -> %s\n", zName, zNewName);
371 }else{
372 printf("MERGE %s\n", zName);
373 }
374 undo_save(zName);
375 content_get(ridt, &t);
376 content_get(ridv, &v);
377 blob_zero(&e);
378 blob_read_from_file(&e, zFullPath);
379 rc = blob_merge(&v, &e, &t, &r);
380 if( rc>=0 ){
381 if( !nochangeFlag ) blob_write_to_file(&r, zFullNewPath);
382 if( rc>0 ){
383 printf("***** %d merge conflicts in %s\n", rc, zNewName);
384 nConflict++;
385 }
386 }else{
387 if( !nochangeFlag ) blob_write_to_file(&t, zFullNewPath);
388 printf("***** Cannot merge binary file %s\n", zNewName);
389 nConflict++;
390 }
391 if( nameChng && !nochangeFlag ) unlink(zFullPath);
392 blob_reset(&v);
393 blob_reset(&e);
394 blob_reset(&t);
395 blob_reset(&r);
 
 
 
 
 
 
396 }else{
397 if( chnged ){
398 if( verboseFlag ) printf("EDITED %s\n", zName);
399 }else{
400 db_bind_int(&mtimeXfer, ":idv", idv);
@@ -452,10 +475,11 @@
452 */
453 int historical_version_of_file(
454 const char *revision, /* The checkin containing the file */
455 const char *file, /* Full treename of the file */
456 Blob *content, /* Put the content here */
 
457 int errCode /* Error code if file not found. Panic if 0. */
458 ){
459 Manifest *pManifest;
460 ManifestFile *pFile;
461 int rid=0;
@@ -475,10 +499,13 @@
475 manifest_file_rewind(pManifest);
476 while( (pFile = manifest_file_next(pManifest,0))!=0 ){
477 if( fossil_strcmp(pFile->zName, file)==0 ){
478 rid = uuid_to_rid(pFile->zUuid, 0);
479 manifest_destroy(pManifest);
 
 
 
480 return content_get(rid, content);
481 }
482 }
483 manifest_destroy(pManifest);
484 if( errCode<=0 ){
@@ -550,13 +577,14 @@
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{
@@ -568,20 +596,27 @@
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
@@ -195,10 +195,12 @@
195 "CREATE TEMP TABLE fv("
196 " fn TEXT PRIMARY KEY," /* The filename relative to root */
197 " idv INTEGER," /* VFILE entry for current version */
198 " idt INTEGER," /* VFILE entry for target version */
199 " chnged BOOLEAN," /* True if current version has been edited */
200 " islinkv BOOLEAN," /* True if current file is a link */
201 " islinkt BOOLEAN," /* True if target file is a link */
202 " ridv INTEGER," /* Record ID for current version */
203 " ridt INTEGER," /* Record ID for target */
204 " fnt TEXT" /* Filename of same file on target version */
205 ");"
206 );
@@ -245,21 +247,34 @@
247 "UPDATE fv SET"
248 " idt=coalesce((SELECT id FROM vfile WHERE vid=%d AND pathname=fnt),0),"
249 " ridt=coalesce((SELECT rid FROM vfile WHERE vid=%d AND pathname=fnt),0)",
250 tid, tid
251 );
252
253 /*
254 ** Add islink information
255 */
256 db_multi_exec(
257 "UPDATE fv SET"
258 " islinkv=coalesce((SELECT islink FROM vfile WHERE vid=%d AND pathname=fnt),0),"
259 " islinkt=coalesce((SELECT islink FROM vfile WHERE vid=%d AND pathname=fnt),0)",
260 vid, tid
261 );
262
263
264 if( debugFlag ){
265 db_prepare(&q,
266 "SELECT rowid, fn, fnt, chnged, ridv, ridt, islinkv, islinkt FROM fv"
267 );
268 while( db_step(&q)==SQLITE_ROW ){
269 printf("%3d: ridv=%-4d ridt=%-4d chnged=%d islinkv=%d islinkt=%d\n",
270 db_column_int(&q, 0),
271 db_column_int(&q, 4),
272 db_column_int(&q, 5),
273 db_column_int(&q, 3),
274 db_column_int(&q, 6),
275 db_column_int(&q, 7));
276 printf(" fnv = [%s]\n", db_column_text(&q, 1));
277 printf(" fnt = [%s]\n", db_column_text(&q, 2));
278 }
279 db_finalize(&q);
280 }
@@ -299,11 +314,11 @@
314 /*
315 ** Alter the content of the checkout so that it conforms with the
316 ** target
317 */
318 db_prepare(&q,
319 "SELECT fn, idv, ridv, idt, ridt, chnged, fnt, islinkv, islinkt FROM fv ORDER BY 1"
320 );
321 db_prepare(&mtimeXfer,
322 "UPDATE vfile SET mtime=(SELECT mtime FROM vfile WHERE id=:idv)"
323 " WHERE id=:idt"
324 );
@@ -316,10 +331,12 @@
331 int ridv = db_column_int(&q, 2); /* RecordID for current */
332 int idt = db_column_int(&q, 3); /* VFILE entry for target */
333 int ridt = db_column_int(&q, 4); /* RecordID for target */
334 int chnged = db_column_int(&q, 5); /* Current is edited */
335 const char *zNewName = db_column_text(&q,6);/* New filename */
336 int islinkv = db_column_int(&q, 7); /* Is current file is a link */
337 int islinkt = db_column_int(&q, 8); /* Is target file is a link */
338 char *zFullPath; /* Full pathname of the file */
339 char *zFullNewPath; /* Full pathname of dest */
340 char nameChng; /* True if the name changed */
341
342 zFullPath = mprintf("%s%s", g.zLocalRoot, zName);
@@ -369,32 +386,38 @@
386 if( nameChng ){
387 printf("MERGE %s -> %s\n", zName, zNewName);
388 }else{
389 printf("MERGE %s\n", zName);
390 }
391 if( islinkv || islinkt /* || file_islink(zFullPath) */ ){
392 //if( !nochangeFlag ) blob_write_to_file(&t, zFullNewPath);
393 printf("***** Cannot merge symlink %s\n", zNewName);
394 nConflict++;
395 }else{
396 undo_save(zName);
397 content_get(ridt, &t);
398 content_get(ridv, &v);
399 blob_zero(&e);
400 blob_read_from_file(&e, zFullPath);
401 rc = blob_merge(&v, &e, &t, &r);
402 if( rc>=0 ){
403 if( !nochangeFlag ) blob_write_to_file(&r, zFullNewPath);
404 if( rc>0 ){
405 printf("***** %d merge conflicts in %s\n", rc, zNewName);
406 nConflict++;
407 }
408 }else{
409 if( !nochangeFlag ) blob_write_to_file(&t, zFullNewPath);
410 printf("***** Cannot merge binary file %s\n", zNewName);
411 nConflict++;
412 }
413 if( nameChng && !nochangeFlag ) unlink(zFullPath);
414 blob_reset(&v);
415 blob_reset(&e);
416 blob_reset(&t);
417 blob_reset(&r);
418 }
419 }else{
420 if( chnged ){
421 if( verboseFlag ) printf("EDITED %s\n", zName);
422 }else{
423 db_bind_int(&mtimeXfer, ":idv", idv);
@@ -452,10 +475,11 @@
475 */
476 int historical_version_of_file(
477 const char *revision, /* The checkin containing the file */
478 const char *file, /* Full treename of the file */
479 Blob *content, /* Put the content here */
480 int *isLink, /* Put islink here. Pass NULL if you don't need it */
481 int errCode /* Error code if file not found. Panic if 0. */
482 ){
483 Manifest *pManifest;
484 ManifestFile *pFile;
485 int rid=0;
@@ -475,10 +499,13 @@
499 manifest_file_rewind(pManifest);
500 while( (pFile = manifest_file_next(pManifest,0))!=0 ){
501 if( fossil_strcmp(pFile->zName, file)==0 ){
502 rid = uuid_to_rid(pFile->zUuid, 0);
503 manifest_destroy(pManifest);
504 if( isLink!=NULL ){
505 *isLink = strstr(pFile->zPerm, "l") ? 1 : 0;
506 }
507 return content_get(rid, content);
508 }
509 }
510 manifest_destroy(pManifest);
511 if( errCode<=0 ){
@@ -550,13 +577,14 @@
577 );
578 }
579 blob_zero(&record);
580 db_prepare(&q, "SELECT name FROM torevert");
581 while( db_step(&q)==SQLITE_ROW ){
582 int isLink = 0;
583 zFile = db_column_text(&q, 0);
584 if( zRevision!=0 ){
585 errCode = historical_version_of_file(zRevision, zFile, &record, &isLink, 2);
586 }else{
587 rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFile);
588 if( rid==0 ){
589 errCode = 2;
590 }else{
@@ -568,20 +596,27 @@
596 if( errCode==2 ){
597 fossil_warning("file not in repository: %s", zFile);
598 }else{
599 char *zFull = mprintf("%/%/", g.zLocalRoot, zFile);
600 undo_save(zFile);
601 if( file_size(zFull)>=0 && (isLink || file_islink(zFull)) ){
602 unlink(zFull);
603 }
604 if( isLink ){
605 create_symlink(blob_str(&record), zFull);
606 }else{
607 blob_write_to_file(&record, zFull);
608 }
609 printf("REVERTED: %s\n", zFile);
610 if( zRevision==0 ){
611 sqlite3_int64 mtime = file_mtime(zFull);
612 db_multi_exec(
613 "UPDATE vfile"
614 " SET mtime=%lld, chnged=0, deleted=0, islink=%d,"
615 " pathname=coalesce(origname,pathname), origname=NULL"
616 " WHERE pathname=%Q",
617 mtime, isLink, zFile
618 );
619 }
620 free(zFull);
621 }
622 blob_reset(&record);
623
+58 -30
--- src/vfile.c
+++ src/vfile.c
@@ -84,12 +84,12 @@
8484
db_begin_transaction();
8585
p = manifest_get(vid, CFTYPE_MANIFEST);
8686
if( p==0 ) return;
8787
db_multi_exec("DELETE FROM vfile WHERE vid=%d", vid);
8888
db_prepare(&ins,
89
- "INSERT INTO vfile(vid,rid,mrid,pathname) "
90
- " VALUES(:vid,:id,:id,:name)");
89
+ "INSERT INTO vfile(vid,rid,mrid,pathname,islink) "
90
+ " VALUES(:vid,:id,:id,:name,:islink)");
9191
db_bind_int(&ins, ":vid", vid);
9292
manifest_file_rewind(p);
9393
while( (pFile = manifest_file_next(p,0))!=0 ){
9494
if( pFile->zUuid==0 || uuid_is_shunned(pFile->zUuid) ) continue;
9595
rid = uuid_to_rid(pFile->zUuid, 0);
@@ -97,10 +97,11 @@
9797
fossil_warning("content missing for %s", pFile->zName);
9898
continue;
9999
}
100100
db_bind_int(&ins, ":id", rid);
101101
db_bind_text(&ins, ":name", pFile->zName);
102
+ db_bind_int(&ins, ":islink", pFile->zPerm && strstr(pFile->zPerm, "l"));
102103
db_step(&ins);
103104
db_reset(&ins);
104105
}
105106
db_finalize(&ins);
106107
manifest_destroy(p);
@@ -148,11 +149,11 @@
148149
isDeleted = db_column_int(&q, 3);
149150
oldChnged = db_column_int(&q, 4);
150151
oldMtime = db_column_int64(&q, 7);
151152
if( isDeleted ){
152153
chnged = 1;
153
- }else if( !file_isfile(zName) && file_size(0)>=0 ){
154
+ }else if( !file_isfile_or_link(zName) && file_size(0)>=0 ){
154155
if( notFileIsFatal ){
155156
fossil_warning("not an ordinary file: %s", zName);
156157
nErr++;
157158
}
158159
chnged = 1;
@@ -206,28 +207,29 @@
206207
Stmt q;
207208
Blob content;
208209
int nRepos = strlen(g.zLocalRoot);
209210
210211
if( vid>0 && id==0 ){
211
- db_prepare(&q, "SELECT id, %Q || pathname, mrid"
212
+ db_prepare(&q, "SELECT id, %Q || pathname, mrid, islink"
212213
" FROM vfile"
213214
" WHERE vid=%d AND mrid>0",
214215
g.zLocalRoot, vid);
215216
}else{
216217
assert( vid==0 && id>0 );
217
- db_prepare(&q, "SELECT id, %Q || pathname, mrid"
218
+ db_prepare(&q, "SELECT id, %Q || pathname, mrid, islink"
218219
" FROM vfile"
219220
" WHERE id=%d AND mrid>0",
220221
g.zLocalRoot, id);
221222
}
222223
while( db_step(&q)==SQLITE_ROW ){
223
- int id, rid;
224
+ int id, rid, isLink;
224225
const char *zName;
225226
226227
id = db_column_int(&q, 0);
227228
zName = db_column_text(&q, 1);
228229
rid = db_column_int(&q, 2);
230
+ isLink = db_column_int(&q, 3);
229231
content_get(rid, &content);
230232
if( file_is_the_same(&content, zName) ){
231233
blob_reset(&content);
232234
continue;
233235
}
@@ -248,11 +250,22 @@
248250
blob_reset(&content);
249251
continue;
250252
}
251253
}
252254
if( verbose ) printf("%s\n", &zName[nRepos]);
253
- blob_write_to_file(&content, zName);
255
+ if( file_isdir(zName) == 1 ){
256
+ //TODO remove directories?
257
+ fossil_fatal("%s is directory, cannot overwrite\n", zName);
258
+ }
259
+ if( file_size(zName)>=0 && (isLink || file_islink(zName)) ){
260
+ unlink(zName);
261
+ }
262
+ if( isLink ){
263
+ create_symlink(blob_str(&content), zName);
264
+ }else{
265
+ blob_write_to_file(&content, zName);
266
+ }
254267
blob_reset(&content);
255268
db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
256269
file_mtime(zName), id);
257270
}
258271
db_finalize(&q);
@@ -305,11 +318,11 @@
305318
}
306319
blob_appendf(pPath, "/%s", pEntry->d_name);
307320
zPath = blob_str(pPath);
308321
if( file_isdir(zPath)==1 ){
309322
vfile_scan(vid, pPath, nPrefix, allFlag);
310
- }else if( file_isfile(zPath) && !db_exists(zSql, &zPath[nPrefix+1]) ){
323
+ }else if( file_isfile_or_link(zPath) && !db_exists(zSql, &zPath[nPrefix+1]) ){
311324
db_multi_exec("INSERT INTO sfile VALUES(%Q)", &zPath[nPrefix+1]);
312325
}
313326
blob_resize(pPath, origSize);
314327
}
315328
}
@@ -356,27 +369,38 @@
356369
const char *zName = db_column_text(&q, 1);
357370
int isSelected = db_column_int(&q, 3);
358371
359372
if( isSelected ){
360373
md5sum_step_text(zName, -1);
361
- in = fopen(zFullpath,"rb");
362
- if( in==0 ){
363
- md5sum_step_text(" 0\n", -1);
364
- continue;
365
- }
366
- fseek(in, 0L, SEEK_END);
367
- sqlite3_snprintf(sizeof(zBuf), zBuf, " %ld\n", ftell(in));
368
- fseek(in, 0L, SEEK_SET);
369
- md5sum_step_text(zBuf, -1);
370
- /*printf("%s %s %s",md5sum_current_state(),zName,zBuf); fflush(stdout);*/
371
- for(;;){
372
- int n;
373
- n = fread(zBuf, 1, sizeof(zBuf), in);
374
- if( n<=0 ) break;
375
- md5sum_step_text(zBuf, n);
376
- }
377
- fclose(in);
374
+ if( file_islink(zFullpath) ){
375
+ /* Instead of file content, use link destination path */
376
+ Blob pathBuf;
377
+
378
+ sqlite3_snprintf(sizeof(zBuf), zBuf, " %ld\n",
379
+ blob_read_link(&pathBuf, zFullpath));
380
+ md5sum_step_text(zBuf, -1);
381
+ md5sum_step_text(blob_str(&pathBuf), -1);
382
+ blob_reset(&pathBuf);
383
+ }else{
384
+ in = fopen(zFullpath,"rb");
385
+ if( in==0 ){
386
+ md5sum_step_text(" 0\n", -1);
387
+ continue;
388
+ }
389
+ fseek(in, 0L, SEEK_END);
390
+ sqlite3_snprintf(sizeof(zBuf), zBuf, " %ld\n", ftell(in));
391
+ fseek(in, 0L, SEEK_SET);
392
+ md5sum_step_text(zBuf, -1);
393
+ /*printf("%s %s %s",md5sum_current_state(),zName,zBuf); fflush(stdout);*/
394
+ for(;;){
395
+ int n;
396
+ n = fread(zBuf, 1, sizeof(zBuf), in);
397
+ if( n<=0 ) break;
398
+ md5sum_step_text(zBuf, n);
399
+ }
400
+ fclose(in);
401
+ }
378402
}else{
379403
int rid = db_column_int(&q, 4);
380404
const char *zOrigName = db_column_text(&q, 2);
381405
char zBuf[100];
382406
Blob file;
@@ -417,15 +441,19 @@
417441
const char *zFullpath = db_column_text(&q, 0);
418442
const char *zName = db_column_text(&q, 1);
419443
int rid = db_column_int(&q, 2);
420444
421445
blob_zero(&disk);
422
- rc = blob_read_from_file(&disk, zFullpath);
423
- if( rc<0 ){
424
- printf("ERROR: cannot read file [%s]\n", zFullpath);
425
- blob_reset(&disk);
426
- continue;
446
+ if( file_islink(zFullpath) ){
447
+ blob_read_link(&disk, zFullpath);
448
+ }else{
449
+ rc = blob_read_from_file(&disk, zFullpath);
450
+ if( rc<0 ){
451
+ printf("ERROR: cannot read file [%s]\n", zFullpath);
452
+ blob_reset(&disk);
453
+ continue;
454
+ }
427455
}
428456
blob_zero(&repo);
429457
content_get(rid, &repo);
430458
if( blob_size(&repo)!=blob_size(&disk) ){
431459
printf("ERROR: [%s] is %d bytes on disk but %d in the repository\n",
432460
--- src/vfile.c
+++ src/vfile.c
@@ -84,12 +84,12 @@
84 db_begin_transaction();
85 p = manifest_get(vid, CFTYPE_MANIFEST);
86 if( p==0 ) return;
87 db_multi_exec("DELETE FROM vfile WHERE vid=%d", vid);
88 db_prepare(&ins,
89 "INSERT INTO vfile(vid,rid,mrid,pathname) "
90 " VALUES(:vid,:id,:id,:name)");
91 db_bind_int(&ins, ":vid", vid);
92 manifest_file_rewind(p);
93 while( (pFile = manifest_file_next(p,0))!=0 ){
94 if( pFile->zUuid==0 || uuid_is_shunned(pFile->zUuid) ) continue;
95 rid = uuid_to_rid(pFile->zUuid, 0);
@@ -97,10 +97,11 @@
97 fossil_warning("content missing for %s", pFile->zName);
98 continue;
99 }
100 db_bind_int(&ins, ":id", rid);
101 db_bind_text(&ins, ":name", pFile->zName);
 
102 db_step(&ins);
103 db_reset(&ins);
104 }
105 db_finalize(&ins);
106 manifest_destroy(p);
@@ -148,11 +149,11 @@
148 isDeleted = db_column_int(&q, 3);
149 oldChnged = db_column_int(&q, 4);
150 oldMtime = db_column_int64(&q, 7);
151 if( isDeleted ){
152 chnged = 1;
153 }else if( !file_isfile(zName) && file_size(0)>=0 ){
154 if( notFileIsFatal ){
155 fossil_warning("not an ordinary file: %s", zName);
156 nErr++;
157 }
158 chnged = 1;
@@ -206,28 +207,29 @@
206 Stmt q;
207 Blob content;
208 int nRepos = strlen(g.zLocalRoot);
209
210 if( vid>0 && id==0 ){
211 db_prepare(&q, "SELECT id, %Q || pathname, mrid"
212 " FROM vfile"
213 " WHERE vid=%d AND mrid>0",
214 g.zLocalRoot, vid);
215 }else{
216 assert( vid==0 && id>0 );
217 db_prepare(&q, "SELECT id, %Q || pathname, mrid"
218 " FROM vfile"
219 " WHERE id=%d AND mrid>0",
220 g.zLocalRoot, id);
221 }
222 while( db_step(&q)==SQLITE_ROW ){
223 int id, rid;
224 const char *zName;
225
226 id = db_column_int(&q, 0);
227 zName = db_column_text(&q, 1);
228 rid = db_column_int(&q, 2);
 
229 content_get(rid, &content);
230 if( file_is_the_same(&content, zName) ){
231 blob_reset(&content);
232 continue;
233 }
@@ -248,11 +250,22 @@
248 blob_reset(&content);
249 continue;
250 }
251 }
252 if( verbose ) printf("%s\n", &zName[nRepos]);
253 blob_write_to_file(&content, zName);
 
 
 
 
 
 
 
 
 
 
 
254 blob_reset(&content);
255 db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
256 file_mtime(zName), id);
257 }
258 db_finalize(&q);
@@ -305,11 +318,11 @@
305 }
306 blob_appendf(pPath, "/%s", pEntry->d_name);
307 zPath = blob_str(pPath);
308 if( file_isdir(zPath)==1 ){
309 vfile_scan(vid, pPath, nPrefix, allFlag);
310 }else if( file_isfile(zPath) && !db_exists(zSql, &zPath[nPrefix+1]) ){
311 db_multi_exec("INSERT INTO sfile VALUES(%Q)", &zPath[nPrefix+1]);
312 }
313 blob_resize(pPath, origSize);
314 }
315 }
@@ -356,27 +369,38 @@
356 const char *zName = db_column_text(&q, 1);
357 int isSelected = db_column_int(&q, 3);
358
359 if( isSelected ){
360 md5sum_step_text(zName, -1);
361 in = fopen(zFullpath,"rb");
362 if( in==0 ){
363 md5sum_step_text(" 0\n", -1);
364 continue;
365 }
366 fseek(in, 0L, SEEK_END);
367 sqlite3_snprintf(sizeof(zBuf), zBuf, " %ld\n", ftell(in));
368 fseek(in, 0L, SEEK_SET);
369 md5sum_step_text(zBuf, -1);
370 /*printf("%s %s %s",md5sum_current_state(),zName,zBuf); fflush(stdout);*/
371 for(;;){
372 int n;
373 n = fread(zBuf, 1, sizeof(zBuf), in);
374 if( n<=0 ) break;
375 md5sum_step_text(zBuf, n);
376 }
377 fclose(in);
 
 
 
 
 
 
 
 
 
 
 
378 }else{
379 int rid = db_column_int(&q, 4);
380 const char *zOrigName = db_column_text(&q, 2);
381 char zBuf[100];
382 Blob file;
@@ -417,15 +441,19 @@
417 const char *zFullpath = db_column_text(&q, 0);
418 const char *zName = db_column_text(&q, 1);
419 int rid = db_column_int(&q, 2);
420
421 blob_zero(&disk);
422 rc = blob_read_from_file(&disk, zFullpath);
423 if( rc<0 ){
424 printf("ERROR: cannot read file [%s]\n", zFullpath);
425 blob_reset(&disk);
426 continue;
 
 
 
 
427 }
428 blob_zero(&repo);
429 content_get(rid, &repo);
430 if( blob_size(&repo)!=blob_size(&disk) ){
431 printf("ERROR: [%s] is %d bytes on disk but %d in the repository\n",
432
--- src/vfile.c
+++ src/vfile.c
@@ -84,12 +84,12 @@
84 db_begin_transaction();
85 p = manifest_get(vid, CFTYPE_MANIFEST);
86 if( p==0 ) return;
87 db_multi_exec("DELETE FROM vfile WHERE vid=%d", vid);
88 db_prepare(&ins,
89 "INSERT INTO vfile(vid,rid,mrid,pathname,islink) "
90 " VALUES(:vid,:id,:id,:name,:islink)");
91 db_bind_int(&ins, ":vid", vid);
92 manifest_file_rewind(p);
93 while( (pFile = manifest_file_next(p,0))!=0 ){
94 if( pFile->zUuid==0 || uuid_is_shunned(pFile->zUuid) ) continue;
95 rid = uuid_to_rid(pFile->zUuid, 0);
@@ -97,10 +97,11 @@
97 fossil_warning("content missing for %s", pFile->zName);
98 continue;
99 }
100 db_bind_int(&ins, ":id", rid);
101 db_bind_text(&ins, ":name", pFile->zName);
102 db_bind_int(&ins, ":islink", pFile->zPerm && strstr(pFile->zPerm, "l"));
103 db_step(&ins);
104 db_reset(&ins);
105 }
106 db_finalize(&ins);
107 manifest_destroy(p);
@@ -148,11 +149,11 @@
149 isDeleted = db_column_int(&q, 3);
150 oldChnged = db_column_int(&q, 4);
151 oldMtime = db_column_int64(&q, 7);
152 if( isDeleted ){
153 chnged = 1;
154 }else if( !file_isfile_or_link(zName) && file_size(0)>=0 ){
155 if( notFileIsFatal ){
156 fossil_warning("not an ordinary file: %s", zName);
157 nErr++;
158 }
159 chnged = 1;
@@ -206,28 +207,29 @@
207 Stmt q;
208 Blob content;
209 int nRepos = strlen(g.zLocalRoot);
210
211 if( vid>0 && id==0 ){
212 db_prepare(&q, "SELECT id, %Q || pathname, mrid, islink"
213 " FROM vfile"
214 " WHERE vid=%d AND mrid>0",
215 g.zLocalRoot, vid);
216 }else{
217 assert( vid==0 && id>0 );
218 db_prepare(&q, "SELECT id, %Q || pathname, mrid, islink"
219 " FROM vfile"
220 " WHERE id=%d AND mrid>0",
221 g.zLocalRoot, id);
222 }
223 while( db_step(&q)==SQLITE_ROW ){
224 int id, rid, isLink;
225 const char *zName;
226
227 id = db_column_int(&q, 0);
228 zName = db_column_text(&q, 1);
229 rid = db_column_int(&q, 2);
230 isLink = db_column_int(&q, 3);
231 content_get(rid, &content);
232 if( file_is_the_same(&content, zName) ){
233 blob_reset(&content);
234 continue;
235 }
@@ -248,11 +250,22 @@
250 blob_reset(&content);
251 continue;
252 }
253 }
254 if( verbose ) printf("%s\n", &zName[nRepos]);
255 if( file_isdir(zName) == 1 ){
256 //TODO remove directories?
257 fossil_fatal("%s is directory, cannot overwrite\n", zName);
258 }
259 if( file_size(zName)>=0 && (isLink || file_islink(zName)) ){
260 unlink(zName);
261 }
262 if( isLink ){
263 create_symlink(blob_str(&content), zName);
264 }else{
265 blob_write_to_file(&content, zName);
266 }
267 blob_reset(&content);
268 db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
269 file_mtime(zName), id);
270 }
271 db_finalize(&q);
@@ -305,11 +318,11 @@
318 }
319 blob_appendf(pPath, "/%s", pEntry->d_name);
320 zPath = blob_str(pPath);
321 if( file_isdir(zPath)==1 ){
322 vfile_scan(vid, pPath, nPrefix, allFlag);
323 }else if( file_isfile_or_link(zPath) && !db_exists(zSql, &zPath[nPrefix+1]) ){
324 db_multi_exec("INSERT INTO sfile VALUES(%Q)", &zPath[nPrefix+1]);
325 }
326 blob_resize(pPath, origSize);
327 }
328 }
@@ -356,27 +369,38 @@
369 const char *zName = db_column_text(&q, 1);
370 int isSelected = db_column_int(&q, 3);
371
372 if( isSelected ){
373 md5sum_step_text(zName, -1);
374 if( file_islink(zFullpath) ){
375 /* Instead of file content, use link destination path */
376 Blob pathBuf;
377
378 sqlite3_snprintf(sizeof(zBuf), zBuf, " %ld\n",
379 blob_read_link(&pathBuf, zFullpath));
380 md5sum_step_text(zBuf, -1);
381 md5sum_step_text(blob_str(&pathBuf), -1);
382 blob_reset(&pathBuf);
383 }else{
384 in = fopen(zFullpath,"rb");
385 if( in==0 ){
386 md5sum_step_text(" 0\n", -1);
387 continue;
388 }
389 fseek(in, 0L, SEEK_END);
390 sqlite3_snprintf(sizeof(zBuf), zBuf, " %ld\n", ftell(in));
391 fseek(in, 0L, SEEK_SET);
392 md5sum_step_text(zBuf, -1);
393 /*printf("%s %s %s",md5sum_current_state(),zName,zBuf); fflush(stdout);*/
394 for(;;){
395 int n;
396 n = fread(zBuf, 1, sizeof(zBuf), in);
397 if( n<=0 ) break;
398 md5sum_step_text(zBuf, n);
399 }
400 fclose(in);
401 }
402 }else{
403 int rid = db_column_int(&q, 4);
404 const char *zOrigName = db_column_text(&q, 2);
405 char zBuf[100];
406 Blob file;
@@ -417,15 +441,19 @@
441 const char *zFullpath = db_column_text(&q, 0);
442 const char *zName = db_column_text(&q, 1);
443 int rid = db_column_int(&q, 2);
444
445 blob_zero(&disk);
446 if( file_islink(zFullpath) ){
447 blob_read_link(&disk, zFullpath);
448 }else{
449 rc = blob_read_from_file(&disk, zFullpath);
450 if( rc<0 ){
451 printf("ERROR: cannot read file [%s]\n", zFullpath);
452 blob_reset(&disk);
453 continue;
454 }
455 }
456 blob_zero(&repo);
457 content_get(rid, &repo);
458 if( blob_size(&repo)!=blob_size(&disk) ){
459 printf("ERROR: [%s] is %d bytes on disk but %d in the repository\n",
460

Keyboard Shortcuts

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