Fossil SCM

Store the repository filename in the _FOSSIL_ database exactly as it is typed on the "open" command-line. That means that the repository filename will be stored relative to the root of the check-out if a relative pathname is given on open.

drh 2012-01-28 21:51 trunk
Commit a7248d8fb9f013795c3276837fda9f2170f4b5ca
4 files changed +1 -1 +35 -13 +19 -7 +1 -1
+1 -1
--- src/checkin.c
+++ src/checkin.c
@@ -180,11 +180,11 @@
180180
*/
181181
void status_cmd(void){
182182
int vid;
183183
db_must_be_within_tree();
184184
/* 012345678901234 */
185
- fossil_print("repository: %s\n", db_lget("repository",""));
185
+ fossil_print("repository: %s\n", db_repository_filename());
186186
fossil_print("local-root: %s\n", g.zLocalRoot);
187187
vid = db_lget_int("checkout", 0);
188188
if( vid ){
189189
show_common_info(vid, "checkout:", 1, 1);
190190
}
191191
--- src/checkin.c
+++ src/checkin.c
@@ -180,11 +180,11 @@
180 */
181 void status_cmd(void){
182 int vid;
183 db_must_be_within_tree();
184 /* 012345678901234 */
185 fossil_print("repository: %s\n", db_lget("repository",""));
186 fossil_print("local-root: %s\n", g.zLocalRoot);
187 vid = db_lget_int("checkout", 0);
188 if( vid ){
189 show_common_info(vid, "checkout:", 1, 1);
190 }
191
--- src/checkin.c
+++ src/checkin.c
@@ -180,11 +180,11 @@
180 */
181 void status_cmd(void){
182 int vid;
183 db_must_be_within_tree();
184 /* 012345678901234 */
185 fossil_print("repository: %s\n", db_repository_filename());
186 fossil_print("local-root: %s\n", g.zLocalRoot);
187 vid = db_lget_int("checkout", 0);
188 if( vid ){
189 show_common_info(vid, "checkout:", 1, 1);
190 }
191
+35 -13
--- src/db.c
+++ src/db.c
@@ -785,40 +785,41 @@
785785
786786
if( file_access(zDbName, F_OK) ) return 0;
787787
lsize = file_size(zDbName);
788788
if( lsize%1024!=0 || lsize<4096 ) return 0;
789789
db_open_or_attach(zDbName, "localdb");
790
- g.localOpen = 1;
791
- db_open_config(0);
792
- db_open_repository(0);
793790
794791
/* If the "isexe" column is missing from the vfile table, then
795792
** add it now. This code added on 2010-03-06. After all users have
796793
** upgraded, this code can be safely deleted.
797794
*/
798
- if( !db_local_column_exists("vfile", "isexe") )
795
+ if( !db_local_column_exists("vfile", "isexe") ){
799796
db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
797
+ }
800798
801799
/* If "islink"/"isLink" columns are missing from tables, then
802800
** add them now. This code added on 2011-01-17 and 2011-08-27.
803801
** After all users have upgraded, this code can be safely deleted.
804802
*/
805
- if( !db_local_column_exists("vfile", "islink") )
803
+ if( !db_local_column_exists("vfile", "islink") ){
806804
db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
805
+ }
807806
808807
if( !db_local_column_exists("stashfile", "isLink") &&
809
- db_local_table_exists("stashfile") )
808
+ db_local_table_exists("stashfile") ){
810809
db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN DEFAULT 0");
810
+ }
811811
812812
if( !db_local_column_exists("undo", "isLink") &&
813
- db_local_table_exists("undo") )
813
+ db_local_table_exists("undo") ){
814814
db_multi_exec("ALTER TABLE undo ADD COLUMN isLink BOOLEAN DEFAULT 0");
815
+ }
815816
816817
if( !db_local_column_exists("undo_vfile", "islink") &&
817
- db_local_table_exists("undo_vfile") )
818
+ db_local_table_exists("undo_vfile") ){
818819
db_multi_exec("ALTER TABLE undo_vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
819
-
820
+ }
820821
return 1;
821822
}
822823
823824
/*
824825
** Locate the root directory of the local repository tree. The root
@@ -853,10 +854,13 @@
853854
while( n>1 && zPwd[n-1]=='/' ){
854855
n--;
855856
zPwd[n] = 0;
856857
}
857858
g.zLocalRoot = mprintf("%s/", zPwd);
859
+ g.localOpen = 1;
860
+ db_open_config(0);
861
+ db_open_repository(0);
858862
return 1;
859863
}
860864
}
861865
n--;
862866
while( n>0 && zPwd[n]!='/' ){ n--; }
@@ -865,20 +869,38 @@
865869
}
866870
867871
/* A checkout database file could not be found */
868872
return 0;
869873
}
874
+
875
+/*
876
+** Get the full pathname to the repository database file. The
877
+** local database (the _FOSSIL_ or .fos database) must have already
878
+** been opened before this routine is called.
879
+*/
880
+const char *db_repository_filename(void){
881
+ static char *zRepo = 0;
882
+ assert( g.localOpen );
883
+ assert( g.zLocalRoot );
884
+ if( zRepo==0 ){
885
+ zRepo = db_lget("repository", 0);
886
+ if( zRepo && !file_is_absolute_path(zRepo) ){
887
+ zRepo = mprintf("%s%s", g.zLocalRoot, zRepo);
888
+ }
889
+ }
890
+ return zRepo;
891
+}
870892
871893
/*
872894
** Open the repository database given by zDbName. If zDbName==NULL then
873895
** get the name from the already open local database.
874896
*/
875897
void db_open_repository(const char *zDbName){
876898
if( g.repositoryOpen ) return;
877899
if( zDbName==0 ){
878900
if( g.localOpen ){
879
- zDbName = db_lget("repository", 0);
901
+ zDbName = db_repository_filename();
880902
}
881903
if( zDbName==0 ){
882904
db_err("unable to find the name of a repository database");
883905
}
884906
}
@@ -930,11 +952,11 @@
930952
}
931953
if( zRep==0 ){
932954
if( db_open_local()==0 ){
933955
goto rep_not_found;
934956
}
935
- zRep = db_lget("repository", 0)/*leak here*/;
957
+ zRep = db_repository_filename();
936958
if( zRep==0 ){
937959
goto rep_not_found;
938960
}
939961
}
940962
db_open_repository(zRep);
@@ -1667,11 +1689,11 @@
16671689
*/
16681690
void db_record_repository_filename(const char *zName){
16691691
Blob full;
16701692
if( zName==0 ){
16711693
if( !g.localOpen ) return;
1672
- zName = db_lget("repository", 0);
1694
+ zName = db_repository_filename();
16731695
}
16741696
file_canonical_name(zName, &full);
16751697
db_swap_connections();
16761698
db_multi_exec(
16771699
"INSERT OR IGNORE INTO global_config(name,value)"
@@ -1725,11 +1747,11 @@
17251747
file_canonical_name(g.argv[2], &path);
17261748
db_open_repository(blob_str(&path));
17271749
db_init_database("./_FOSSIL_", zLocalSchema, (char*)0);
17281750
db_delete_on_failure("./_FOSSIL_");
17291751
db_open_local();
1730
- db_lset("repository", blob_str(&path));
1752
+ db_lset("repository", g.argv[2]);
17311753
db_record_repository_filename(blob_str(&path));
17321754
vid = db_int(0, "SELECT pid FROM plink y"
17331755
" WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)");
17341756
if( vid==0 ){
17351757
db_lset_int("checkout", 1);
17361758
--- src/db.c
+++ src/db.c
@@ -785,40 +785,41 @@
785
786 if( file_access(zDbName, F_OK) ) return 0;
787 lsize = file_size(zDbName);
788 if( lsize%1024!=0 || lsize<4096 ) return 0;
789 db_open_or_attach(zDbName, "localdb");
790 g.localOpen = 1;
791 db_open_config(0);
792 db_open_repository(0);
793
794 /* If the "isexe" column is missing from the vfile table, then
795 ** add it now. This code added on 2010-03-06. After all users have
796 ** upgraded, this code can be safely deleted.
797 */
798 if( !db_local_column_exists("vfile", "isexe") )
799 db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
 
800
801 /* If "islink"/"isLink" columns are missing from tables, then
802 ** add them now. This code added on 2011-01-17 and 2011-08-27.
803 ** After all users have upgraded, this code can be safely deleted.
804 */
805 if( !db_local_column_exists("vfile", "islink") )
806 db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
 
807
808 if( !db_local_column_exists("stashfile", "isLink") &&
809 db_local_table_exists("stashfile") )
810 db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN DEFAULT 0");
 
811
812 if( !db_local_column_exists("undo", "isLink") &&
813 db_local_table_exists("undo") )
814 db_multi_exec("ALTER TABLE undo ADD COLUMN isLink BOOLEAN DEFAULT 0");
 
815
816 if( !db_local_column_exists("undo_vfile", "islink") &&
817 db_local_table_exists("undo_vfile") )
818 db_multi_exec("ALTER TABLE undo_vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
819
820 return 1;
821 }
822
823 /*
824 ** Locate the root directory of the local repository tree. The root
@@ -853,10 +854,13 @@
853 while( n>1 && zPwd[n-1]=='/' ){
854 n--;
855 zPwd[n] = 0;
856 }
857 g.zLocalRoot = mprintf("%s/", zPwd);
 
 
 
858 return 1;
859 }
860 }
861 n--;
862 while( n>0 && zPwd[n]!='/' ){ n--; }
@@ -865,20 +869,38 @@
865 }
866
867 /* A checkout database file could not be found */
868 return 0;
869 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
870
871 /*
872 ** Open the repository database given by zDbName. If zDbName==NULL then
873 ** get the name from the already open local database.
874 */
875 void db_open_repository(const char *zDbName){
876 if( g.repositoryOpen ) return;
877 if( zDbName==0 ){
878 if( g.localOpen ){
879 zDbName = db_lget("repository", 0);
880 }
881 if( zDbName==0 ){
882 db_err("unable to find the name of a repository database");
883 }
884 }
@@ -930,11 +952,11 @@
930 }
931 if( zRep==0 ){
932 if( db_open_local()==0 ){
933 goto rep_not_found;
934 }
935 zRep = db_lget("repository", 0)/*leak here*/;
936 if( zRep==0 ){
937 goto rep_not_found;
938 }
939 }
940 db_open_repository(zRep);
@@ -1667,11 +1689,11 @@
1667 */
1668 void db_record_repository_filename(const char *zName){
1669 Blob full;
1670 if( zName==0 ){
1671 if( !g.localOpen ) return;
1672 zName = db_lget("repository", 0);
1673 }
1674 file_canonical_name(zName, &full);
1675 db_swap_connections();
1676 db_multi_exec(
1677 "INSERT OR IGNORE INTO global_config(name,value)"
@@ -1725,11 +1747,11 @@
1725 file_canonical_name(g.argv[2], &path);
1726 db_open_repository(blob_str(&path));
1727 db_init_database("./_FOSSIL_", zLocalSchema, (char*)0);
1728 db_delete_on_failure("./_FOSSIL_");
1729 db_open_local();
1730 db_lset("repository", blob_str(&path));
1731 db_record_repository_filename(blob_str(&path));
1732 vid = db_int(0, "SELECT pid FROM plink y"
1733 " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)");
1734 if( vid==0 ){
1735 db_lset_int("checkout", 1);
1736
--- src/db.c
+++ src/db.c
@@ -785,40 +785,41 @@
785
786 if( file_access(zDbName, F_OK) ) return 0;
787 lsize = file_size(zDbName);
788 if( lsize%1024!=0 || lsize<4096 ) return 0;
789 db_open_or_attach(zDbName, "localdb");
 
 
 
790
791 /* If the "isexe" column is missing from the vfile table, then
792 ** add it now. This code added on 2010-03-06. After all users have
793 ** upgraded, this code can be safely deleted.
794 */
795 if( !db_local_column_exists("vfile", "isexe") ){
796 db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
797 }
798
799 /* If "islink"/"isLink" columns are missing from tables, then
800 ** add them now. This code added on 2011-01-17 and 2011-08-27.
801 ** After all users have upgraded, this code can be safely deleted.
802 */
803 if( !db_local_column_exists("vfile", "islink") ){
804 db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
805 }
806
807 if( !db_local_column_exists("stashfile", "isLink") &&
808 db_local_table_exists("stashfile") ){
809 db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN DEFAULT 0");
810 }
811
812 if( !db_local_column_exists("undo", "isLink") &&
813 db_local_table_exists("undo") ){
814 db_multi_exec("ALTER TABLE undo ADD COLUMN isLink BOOLEAN DEFAULT 0");
815 }
816
817 if( !db_local_column_exists("undo_vfile", "islink") &&
818 db_local_table_exists("undo_vfile") ){
819 db_multi_exec("ALTER TABLE undo_vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
820 }
821 return 1;
822 }
823
824 /*
825 ** Locate the root directory of the local repository tree. The root
@@ -853,10 +854,13 @@
854 while( n>1 && zPwd[n-1]=='/' ){
855 n--;
856 zPwd[n] = 0;
857 }
858 g.zLocalRoot = mprintf("%s/", zPwd);
859 g.localOpen = 1;
860 db_open_config(0);
861 db_open_repository(0);
862 return 1;
863 }
864 }
865 n--;
866 while( n>0 && zPwd[n]!='/' ){ n--; }
@@ -865,20 +869,38 @@
869 }
870
871 /* A checkout database file could not be found */
872 return 0;
873 }
874
875 /*
876 ** Get the full pathname to the repository database file. The
877 ** local database (the _FOSSIL_ or .fos database) must have already
878 ** been opened before this routine is called.
879 */
880 const char *db_repository_filename(void){
881 static char *zRepo = 0;
882 assert( g.localOpen );
883 assert( g.zLocalRoot );
884 if( zRepo==0 ){
885 zRepo = db_lget("repository", 0);
886 if( zRepo && !file_is_absolute_path(zRepo) ){
887 zRepo = mprintf("%s%s", g.zLocalRoot, zRepo);
888 }
889 }
890 return zRepo;
891 }
892
893 /*
894 ** Open the repository database given by zDbName. If zDbName==NULL then
895 ** get the name from the already open local database.
896 */
897 void db_open_repository(const char *zDbName){
898 if( g.repositoryOpen ) return;
899 if( zDbName==0 ){
900 if( g.localOpen ){
901 zDbName = db_repository_filename();
902 }
903 if( zDbName==0 ){
904 db_err("unable to find the name of a repository database");
905 }
906 }
@@ -930,11 +952,11 @@
952 }
953 if( zRep==0 ){
954 if( db_open_local()==0 ){
955 goto rep_not_found;
956 }
957 zRep = db_repository_filename();
958 if( zRep==0 ){
959 goto rep_not_found;
960 }
961 }
962 db_open_repository(zRep);
@@ -1667,11 +1689,11 @@
1689 */
1690 void db_record_repository_filename(const char *zName){
1691 Blob full;
1692 if( zName==0 ){
1693 if( !g.localOpen ) return;
1694 zName = db_repository_filename();
1695 }
1696 file_canonical_name(zName, &full);
1697 db_swap_connections();
1698 db_multi_exec(
1699 "INSERT OR IGNORE INTO global_config(name,value)"
@@ -1725,11 +1747,11 @@
1747 file_canonical_name(g.argv[2], &path);
1748 db_open_repository(blob_str(&path));
1749 db_init_database("./_FOSSIL_", zLocalSchema, (char*)0);
1750 db_delete_on_failure("./_FOSSIL_");
1751 db_open_local();
1752 db_lset("repository", g.argv[2]);
1753 db_record_repository_filename(blob_str(&path));
1754 vid = db_int(0, "SELECT pid FROM plink y"
1755 " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)");
1756 if( vid==0 ){
1757 db_lset_int("checkout", 1);
1758
+19 -7
--- src/file.c
+++ src/file.c
@@ -581,26 +581,38 @@
581581
strerror(errno));
582582
}
583583
}
584584
#endif
585585
}
586
+
587
+/*
588
+** Return true if zPath is an absolute pathname. Return false
589
+** if it is relative.
590
+*/
591
+int file_is_absolute_path(const char *zPath){
592
+ if( zPath[0]=='/'
593
+#if defined(_WIN32)
594
+ || zPath[0]=='\\'
595
+ || (strlen(zPath)>3 && zPath[1]==':'
596
+ && (zPath[2]=='\\' || zPath[2]=='/'))
597
+#endif
598
+ ){
599
+ return 1;
600
+ }else{
601
+ return 0;
602
+ }
603
+}
586604
587605
/*
588606
** Compute a canonical pathname for a file or directory.
589607
** Make the name absolute if it is relative.
590608
** Remove redundant / characters
591609
** Remove all /./ path elements.
592610
** Convert /A/../ to just /
593611
*/
594612
void file_canonical_name(const char *zOrigName, Blob *pOut){
595
- if( zOrigName[0]=='/'
596
-#if defined(_WIN32)
597
- || zOrigName[0]=='\\'
598
- || (strlen(zOrigName)>3 && zOrigName[1]==':'
599
- && (zOrigName[2]=='\\' || zOrigName[2]=='/'))
600
-#endif
601
- ){
613
+ if( file_is_absolute_path(zOrigName) ){
602614
blob_set(pOut, zOrigName);
603615
blob_materialize(pOut);
604616
}else{
605617
char zPwd[2000];
606618
file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName));
607619
--- src/file.c
+++ src/file.c
@@ -581,26 +581,38 @@
581 strerror(errno));
582 }
583 }
584 #endif
585 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
586
587 /*
588 ** Compute a canonical pathname for a file or directory.
589 ** Make the name absolute if it is relative.
590 ** Remove redundant / characters
591 ** Remove all /./ path elements.
592 ** Convert /A/../ to just /
593 */
594 void file_canonical_name(const char *zOrigName, Blob *pOut){
595 if( zOrigName[0]=='/'
596 #if defined(_WIN32)
597 || zOrigName[0]=='\\'
598 || (strlen(zOrigName)>3 && zOrigName[1]==':'
599 && (zOrigName[2]=='\\' || zOrigName[2]=='/'))
600 #endif
601 ){
602 blob_set(pOut, zOrigName);
603 blob_materialize(pOut);
604 }else{
605 char zPwd[2000];
606 file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName));
607
--- src/file.c
+++ src/file.c
@@ -581,26 +581,38 @@
581 strerror(errno));
582 }
583 }
584 #endif
585 }
586
587 /*
588 ** Return true if zPath is an absolute pathname. Return false
589 ** if it is relative.
590 */
591 int file_is_absolute_path(const char *zPath){
592 if( zPath[0]=='/'
593 #if defined(_WIN32)
594 || zPath[0]=='\\'
595 || (strlen(zPath)>3 && zPath[1]==':'
596 && (zPath[2]=='\\' || zPath[2]=='/'))
597 #endif
598 ){
599 return 1;
600 }else{
601 return 0;
602 }
603 }
604
605 /*
606 ** Compute a canonical pathname for a file or directory.
607 ** Make the name absolute if it is relative.
608 ** Remove redundant / characters
609 ** Remove all /./ path elements.
610 ** Convert /A/../ to just /
611 */
612 void file_canonical_name(const char *zOrigName, Blob *pOut){
613 if( file_is_absolute_path(zOrigName) ){
 
 
 
 
 
 
614 blob_set(pOut, zOrigName);
615 blob_materialize(pOut);
616 }else{
617 char zPwd[2000];
618 file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName));
619
+1 -1
--- src/info.c
+++ src/info.c
@@ -157,11 +157,11 @@
157157
int vid;
158158
/* 012345678901234 */
159159
db_record_repository_filename(0);
160160
fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
161161
if( g.localOpen ){
162
- fossil_print("repository: %s\n", db_lget("repository", ""));
162
+ fossil_print("repository: %s\n", db_repository_filename());
163163
fossil_print("local-root: %s\n", g.zLocalRoot);
164164
}
165165
#if defined(_WIN32)
166166
if( g.zHome ){
167167
fossil_print("user-home: %s\n", g.zHome);
168168
--- src/info.c
+++ src/info.c
@@ -157,11 +157,11 @@
157 int vid;
158 /* 012345678901234 */
159 db_record_repository_filename(0);
160 fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
161 if( g.localOpen ){
162 fossil_print("repository: %s\n", db_lget("repository", ""));
163 fossil_print("local-root: %s\n", g.zLocalRoot);
164 }
165 #if defined(_WIN32)
166 if( g.zHome ){
167 fossil_print("user-home: %s\n", g.zHome);
168
--- src/info.c
+++ src/info.c
@@ -157,11 +157,11 @@
157 int vid;
158 /* 012345678901234 */
159 db_record_repository_filename(0);
160 fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
161 if( g.localOpen ){
162 fossil_print("repository: %s\n", db_repository_filename());
163 fossil_print("local-root: %s\n", g.zLocalRoot);
164 }
165 #if defined(_WIN32)
166 if( g.zHome ){
167 fossil_print("user-home: %s\n", g.zHome);
168

Keyboard Shortcuts

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