| | @@ -785,40 +785,41 @@ |
| 785 | 785 | |
| 786 | 786 | if( file_access(zDbName, F_OK) ) return 0; |
| 787 | 787 | lsize = file_size(zDbName); |
| 788 | 788 | if( lsize%1024!=0 || lsize<4096 ) return 0; |
| 789 | 789 | db_open_or_attach(zDbName, "localdb"); |
| 790 | | - g.localOpen = 1; |
| 791 | | - db_open_config(0); |
| 792 | | - db_open_repository(0); |
| 793 | 790 | |
| 794 | 791 | /* If the "isexe" column is missing from the vfile table, then |
| 795 | 792 | ** add it now. This code added on 2010-03-06. After all users have |
| 796 | 793 | ** upgraded, this code can be safely deleted. |
| 797 | 794 | */ |
| 798 | | - if( !db_local_column_exists("vfile", "isexe") ) |
| 795 | + if( !db_local_column_exists("vfile", "isexe") ){ |
| 799 | 796 | db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0"); |
| 797 | + } |
| 800 | 798 | |
| 801 | 799 | /* If "islink"/"isLink" columns are missing from tables, then |
| 802 | 800 | ** add them now. This code added on 2011-01-17 and 2011-08-27. |
| 803 | 801 | ** After all users have upgraded, this code can be safely deleted. |
| 804 | 802 | */ |
| 805 | | - if( !db_local_column_exists("vfile", "islink") ) |
| 803 | + if( !db_local_column_exists("vfile", "islink") ){ |
| 806 | 804 | db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0"); |
| 805 | + } |
| 807 | 806 | |
| 808 | 807 | if( !db_local_column_exists("stashfile", "isLink") && |
| 809 | | - db_local_table_exists("stashfile") ) |
| 808 | + db_local_table_exists("stashfile") ){ |
| 810 | 809 | db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN DEFAULT 0"); |
| 810 | + } |
| 811 | 811 | |
| 812 | 812 | if( !db_local_column_exists("undo", "isLink") && |
| 813 | | - db_local_table_exists("undo") ) |
| 813 | + db_local_table_exists("undo") ){ |
| 814 | 814 | db_multi_exec("ALTER TABLE undo ADD COLUMN isLink BOOLEAN DEFAULT 0"); |
| 815 | + } |
| 815 | 816 | |
| 816 | 817 | if( !db_local_column_exists("undo_vfile", "islink") && |
| 817 | | - db_local_table_exists("undo_vfile") ) |
| 818 | + db_local_table_exists("undo_vfile") ){ |
| 818 | 819 | db_multi_exec("ALTER TABLE undo_vfile ADD COLUMN islink BOOLEAN DEFAULT 0"); |
| 819 | | - |
| 820 | + } |
| 820 | 821 | return 1; |
| 821 | 822 | } |
| 822 | 823 | |
| 823 | 824 | /* |
| 824 | 825 | ** Locate the root directory of the local repository tree. The root |
| | @@ -853,10 +854,13 @@ |
| 853 | 854 | while( n>1 && zPwd[n-1]=='/' ){ |
| 854 | 855 | n--; |
| 855 | 856 | zPwd[n] = 0; |
| 856 | 857 | } |
| 857 | 858 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 859 | + g.localOpen = 1; |
| 860 | + db_open_config(0); |
| 861 | + db_open_repository(0); |
| 858 | 862 | return 1; |
| 859 | 863 | } |
| 860 | 864 | } |
| 861 | 865 | n--; |
| 862 | 866 | while( n>0 && zPwd[n]!='/' ){ n--; } |
| | @@ -865,20 +869,38 @@ |
| 865 | 869 | } |
| 866 | 870 | |
| 867 | 871 | /* A checkout database file could not be found */ |
| 868 | 872 | return 0; |
| 869 | 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 | +} |
| 870 | 892 | |
| 871 | 893 | /* |
| 872 | 894 | ** Open the repository database given by zDbName. If zDbName==NULL then |
| 873 | 895 | ** get the name from the already open local database. |
| 874 | 896 | */ |
| 875 | 897 | void db_open_repository(const char *zDbName){ |
| 876 | 898 | if( g.repositoryOpen ) return; |
| 877 | 899 | if( zDbName==0 ){ |
| 878 | 900 | if( g.localOpen ){ |
| 879 | | - zDbName = db_lget("repository", 0); |
| 901 | + zDbName = db_repository_filename(); |
| 880 | 902 | } |
| 881 | 903 | if( zDbName==0 ){ |
| 882 | 904 | db_err("unable to find the name of a repository database"); |
| 883 | 905 | } |
| 884 | 906 | } |
| | @@ -930,11 +952,11 @@ |
| 930 | 952 | } |
| 931 | 953 | if( zRep==0 ){ |
| 932 | 954 | if( db_open_local()==0 ){ |
| 933 | 955 | goto rep_not_found; |
| 934 | 956 | } |
| 935 | | - zRep = db_lget("repository", 0)/*leak here*/; |
| 957 | + zRep = db_repository_filename(); |
| 936 | 958 | if( zRep==0 ){ |
| 937 | 959 | goto rep_not_found; |
| 938 | 960 | } |
| 939 | 961 | } |
| 940 | 962 | db_open_repository(zRep); |
| | @@ -1667,11 +1689,11 @@ |
| 1667 | 1689 | */ |
| 1668 | 1690 | void db_record_repository_filename(const char *zName){ |
| 1669 | 1691 | Blob full; |
| 1670 | 1692 | if( zName==0 ){ |
| 1671 | 1693 | if( !g.localOpen ) return; |
| 1672 | | - zName = db_lget("repository", 0); |
| 1694 | + zName = db_repository_filename(); |
| 1673 | 1695 | } |
| 1674 | 1696 | file_canonical_name(zName, &full); |
| 1675 | 1697 | db_swap_connections(); |
| 1676 | 1698 | db_multi_exec( |
| 1677 | 1699 | "INSERT OR IGNORE INTO global_config(name,value)" |
| | @@ -1725,11 +1747,11 @@ |
| 1725 | 1747 | file_canonical_name(g.argv[2], &path); |
| 1726 | 1748 | db_open_repository(blob_str(&path)); |
| 1727 | 1749 | db_init_database("./_FOSSIL_", zLocalSchema, (char*)0); |
| 1728 | 1750 | db_delete_on_failure("./_FOSSIL_"); |
| 1729 | 1751 | db_open_local(); |
| 1730 | | - db_lset("repository", blob_str(&path)); |
| 1752 | + db_lset("repository", g.argv[2]); |
| 1731 | 1753 | db_record_repository_filename(blob_str(&path)); |
| 1732 | 1754 | vid = db_int(0, "SELECT pid FROM plink y" |
| 1733 | 1755 | " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)"); |
| 1734 | 1756 | if( vid==0 ){ |
| 1735 | 1757 | db_lset_int("checkout", 1); |
| 1736 | 1758 | |