Fossil SCM
Remember which database was opened first (as the "main" database) in the g.zMainDbType global variable.
Commit
99f52f3806ead4cdbef4b1a05f0dc36119d48ae4
Parent
bf919337bb4c2f2…
4 files changed
+1
-2
+1
-1
+8
-5
+7
-5
M
src/db.c
+1
-2
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -618,18 +618,17 @@ | ||
| 618 | 618 | ** already open, then attach zDbName using the name zLabel. |
| 619 | 619 | */ |
| 620 | 620 | static void db_open_or_attach(const char *zDbName, const char *zLabel){ |
| 621 | 621 | if( !g.db ){ |
| 622 | 622 | g.db = openDatabase(zDbName); |
| 623 | - g.zRepoDb = "main"; | |
| 623 | + g.zMainDbType = zLabel; | |
| 624 | 624 | db_connection_init(); |
| 625 | 625 | }else{ |
| 626 | 626 | #if defined(_WIN32) |
| 627 | 627 | zDbName = sqlite3_win32_mbcs_to_utf8(zDbName); |
| 628 | 628 | #endif |
| 629 | 629 | db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel); |
| 630 | - g.zRepoDb = mprintf("%s", zLabel); | |
| 631 | 630 | } |
| 632 | 631 | } |
| 633 | 632 | |
| 634 | 633 | /* |
| 635 | 634 | ** Open the user database in "~/.fossil". Create the database anew if |
| 636 | 635 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -618,18 +618,17 @@ | |
| 618 | ** already open, then attach zDbName using the name zLabel. |
| 619 | */ |
| 620 | static void db_open_or_attach(const char *zDbName, const char *zLabel){ |
| 621 | if( !g.db ){ |
| 622 | g.db = openDatabase(zDbName); |
| 623 | g.zRepoDb = "main"; |
| 624 | db_connection_init(); |
| 625 | }else{ |
| 626 | #if defined(_WIN32) |
| 627 | zDbName = sqlite3_win32_mbcs_to_utf8(zDbName); |
| 628 | #endif |
| 629 | db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel); |
| 630 | g.zRepoDb = mprintf("%s", zLabel); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | ** Open the user database in "~/.fossil". Create the database anew if |
| 636 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -618,18 +618,17 @@ | |
| 618 | ** already open, then attach zDbName using the name zLabel. |
| 619 | */ |
| 620 | static void db_open_or_attach(const char *zDbName, const char *zLabel){ |
| 621 | if( !g.db ){ |
| 622 | g.db = openDatabase(zDbName); |
| 623 | g.zMainDbType = zLabel; |
| 624 | db_connection_init(); |
| 625 | }else{ |
| 626 | #if defined(_WIN32) |
| 627 | zDbName = sqlite3_win32_mbcs_to_utf8(zDbName); |
| 628 | #endif |
| 629 | db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | /* |
| 634 | ** Open the user database in "~/.fossil". Create the database anew if |
| 635 |
+1
-1
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -55,11 +55,11 @@ | ||
| 55 | 55 | int useAttach; /* True if global_config is attached to repository */ |
| 56 | 56 | int configOpen; /* True if the config database is open */ |
| 57 | 57 | long long int now; /* Seconds since 1970 */ |
| 58 | 58 | int repositoryOpen; /* True if the main repository database is open */ |
| 59 | 59 | char *zRepositoryName; /* Name of the repository database */ |
| 60 | - char *zRepoDb; /* SQLite database name for the repository */ | |
| 60 | + const char *zMainDbType;/* "configdb", "localdb", or "repository" */ | |
| 61 | 61 | const char *zHome; /* Name of user home directory */ |
| 62 | 62 | int localOpen; /* True if the local database is open */ |
| 63 | 63 | char *zLocalRoot; /* The directory holding the local database */ |
| 64 | 64 | int minPrefix; /* Number of digits needed for a distinct UUID */ |
| 65 | 65 | int fSqlTrace; /* True if -sqltrace flag is present */ |
| 66 | 66 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -55,11 +55,11 @@ | |
| 55 | int useAttach; /* True if global_config is attached to repository */ |
| 56 | int configOpen; /* True if the config database is open */ |
| 57 | long long int now; /* Seconds since 1970 */ |
| 58 | int repositoryOpen; /* True if the main repository database is open */ |
| 59 | char *zRepositoryName; /* Name of the repository database */ |
| 60 | char *zRepoDb; /* SQLite database name for the repository */ |
| 61 | const char *zHome; /* Name of user home directory */ |
| 62 | int localOpen; /* True if the local database is open */ |
| 63 | char *zLocalRoot; /* The directory holding the local database */ |
| 64 | int minPrefix; /* Number of digits needed for a distinct UUID */ |
| 65 | int fSqlTrace; /* True if -sqltrace flag is present */ |
| 66 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -55,11 +55,11 @@ | |
| 55 | int useAttach; /* True if global_config is attached to repository */ |
| 56 | int configOpen; /* True if the config database is open */ |
| 57 | long long int now; /* Seconds since 1970 */ |
| 58 | int repositoryOpen; /* True if the main repository database is open */ |
| 59 | char *zRepositoryName; /* Name of the repository database */ |
| 60 | const char *zMainDbType;/* "configdb", "localdb", or "repository" */ |
| 61 | const char *zHome; /* Name of user home directory */ |
| 62 | int localOpen; /* True if the local database is open */ |
| 63 | char *zLocalRoot; /* The directory holding the local database */ |
| 64 | int minPrefix; /* Number of digits needed for a distinct UUID */ |
| 65 | int fSqlTrace; /* True if -sqltrace flag is present */ |
| 66 |
+8
-5
| --- src/stat.c | ||
| +++ src/stat.c | ||
| @@ -29,10 +29,11 @@ | ||
| 29 | 29 | */ |
| 30 | 30 | void stat_page(void){ |
| 31 | 31 | i64 t, fsize; |
| 32 | 32 | int n, m; |
| 33 | 33 | int szMax, szAvg; |
| 34 | + const char *zDb; | |
| 34 | 35 | char zBuf[100]; |
| 35 | 36 | |
| 36 | 37 | login_check_credentials(); |
| 37 | 38 | if( !g.okRead ){ login_needed(); return; } |
| 38 | 39 | style_header("Repository Statistics"); |
| @@ -108,18 +109,20 @@ | ||
| 108 | 109 | @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION) (%h(COMPILER_NAME)) |
| 109 | 110 | @ </td></tr> |
| 110 | 111 | @ <tr><th>SQLite Version:</th><td> |
| 111 | 112 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%.19s [%.10s] (%s)", |
| 112 | 113 | SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], SQLITE_VERSION); |
| 114 | + zDb = "repository"; | |
| 115 | + if( strcmp(g.zMainDbType, zDb)==0 ) zDb = "main"; | |
| 113 | 116 | @ %s(zBuf) |
| 114 | 117 | @ </td></tr> |
| 115 | 118 | @ <tr><th>Database Stats:</th><td> |
| 116 | - @ %d(db_int(0, "PRAGMA %s.page_count", g.zRepoDb)) pages, | |
| 117 | - @ %d(db_int(0, "PRAGMA %s.page_size", g.zRepoDb)) bytes/page, | |
| 118 | - @ %d(db_int(0, "PRAGMA %s.freelist_count", g.zRepoDb)) free pages, | |
| 119 | - @ %s(db_text(0, "PRAGMA %s.encoding", g.zRepoDb)), | |
| 120 | - @ %s(db_text(0, "PRAGMA %s.journal_mode", g.zRepoDb)) mode | |
| 119 | + @ %d(db_int(0, "PRAGMA %s.page_count", zDb)) pages, | |
| 120 | + @ %d(db_int(0, "PRAGMA %s.page_size", zDb)) bytes/page, | |
| 121 | + @ %d(db_int(0, "PRAGMA %s.freelist_count", zDb)) free pages, | |
| 122 | + @ %s(db_text(0, "PRAGMA %s.encoding", zDb)), | |
| 123 | + @ %s(db_text(0, "PRAGMA %s.journal_mode", zDb)) mode | |
| 121 | 124 | @ </td></tr> |
| 122 | 125 | |
| 123 | 126 | @ </table> |
| 124 | 127 | style_footer(); |
| 125 | 128 | } |
| 126 | 129 |
| --- src/stat.c | |
| +++ src/stat.c | |
| @@ -29,10 +29,11 @@ | |
| 29 | */ |
| 30 | void stat_page(void){ |
| 31 | i64 t, fsize; |
| 32 | int n, m; |
| 33 | int szMax, szAvg; |
| 34 | char zBuf[100]; |
| 35 | |
| 36 | login_check_credentials(); |
| 37 | if( !g.okRead ){ login_needed(); return; } |
| 38 | style_header("Repository Statistics"); |
| @@ -108,18 +109,20 @@ | |
| 108 | @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION) (%h(COMPILER_NAME)) |
| 109 | @ </td></tr> |
| 110 | @ <tr><th>SQLite Version:</th><td> |
| 111 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%.19s [%.10s] (%s)", |
| 112 | SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], SQLITE_VERSION); |
| 113 | @ %s(zBuf) |
| 114 | @ </td></tr> |
| 115 | @ <tr><th>Database Stats:</th><td> |
| 116 | @ %d(db_int(0, "PRAGMA %s.page_count", g.zRepoDb)) pages, |
| 117 | @ %d(db_int(0, "PRAGMA %s.page_size", g.zRepoDb)) bytes/page, |
| 118 | @ %d(db_int(0, "PRAGMA %s.freelist_count", g.zRepoDb)) free pages, |
| 119 | @ %s(db_text(0, "PRAGMA %s.encoding", g.zRepoDb)), |
| 120 | @ %s(db_text(0, "PRAGMA %s.journal_mode", g.zRepoDb)) mode |
| 121 | @ </td></tr> |
| 122 | |
| 123 | @ </table> |
| 124 | style_footer(); |
| 125 | } |
| 126 |
| --- src/stat.c | |
| +++ src/stat.c | |
| @@ -29,10 +29,11 @@ | |
| 29 | */ |
| 30 | void stat_page(void){ |
| 31 | i64 t, fsize; |
| 32 | int n, m; |
| 33 | int szMax, szAvg; |
| 34 | const char *zDb; |
| 35 | char zBuf[100]; |
| 36 | |
| 37 | login_check_credentials(); |
| 38 | if( !g.okRead ){ login_needed(); return; } |
| 39 | style_header("Repository Statistics"); |
| @@ -108,18 +109,20 @@ | |
| 109 | @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION) (%h(COMPILER_NAME)) |
| 110 | @ </td></tr> |
| 111 | @ <tr><th>SQLite Version:</th><td> |
| 112 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%.19s [%.10s] (%s)", |
| 113 | SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], SQLITE_VERSION); |
| 114 | zDb = "repository"; |
| 115 | if( strcmp(g.zMainDbType, zDb)==0 ) zDb = "main"; |
| 116 | @ %s(zBuf) |
| 117 | @ </td></tr> |
| 118 | @ <tr><th>Database Stats:</th><td> |
| 119 | @ %d(db_int(0, "PRAGMA %s.page_count", zDb)) pages, |
| 120 | @ %d(db_int(0, "PRAGMA %s.page_size", zDb)) bytes/page, |
| 121 | @ %d(db_int(0, "PRAGMA %s.freelist_count", zDb)) free pages, |
| 122 | @ %s(db_text(0, "PRAGMA %s.encoding", zDb)), |
| 123 | @ %s(db_text(0, "PRAGMA %s.journal_mode", zDb)) mode |
| 124 | @ </td></tr> |
| 125 | |
| 126 | @ </table> |
| 127 | style_footer(); |
| 128 | } |
| 129 |
+7
-5
| --- src/undo.c | ||
| +++ src/undo.c | ||
| @@ -151,23 +151,25 @@ | ||
| 151 | 151 | /* |
| 152 | 152 | ** Begin capturing a snapshot that can be undone. |
| 153 | 153 | */ |
| 154 | 154 | void undo_begin(void){ |
| 155 | 155 | int cid; |
| 156 | + const char *zDb = "localdb"; | |
| 156 | 157 | static const char zSql[] = |
| 157 | - @ CREATE TABLE undo( | |
| 158 | + @ CREATE TABLE %s.undo( | |
| 158 | 159 | @ pathname TEXT UNIQUE, -- Name of the file |
| 159 | 160 | @ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable |
| 160 | 161 | @ existsflag BOOLEAN, -- True if the file exists |
| 161 | 162 | @ content BLOB -- Saved content |
| 162 | 163 | @ ); |
| 163 | - @ CREATE TABLE undo_vfile AS SELECT * FROM vfile; | |
| 164 | - @ CREATE TABLE undo_vmerge AS SELECT * FROM vmerge; | |
| 165 | - @ CREATE TABLE undo_pending(undoId INTEGER PRIMARY KEY); | |
| 164 | + @ CREATE TABLE %s.undo_vfile AS SELECT * FROM vfile; | |
| 165 | + @ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge; | |
| 166 | + @ CREATE TABLE %s.undo_pending(undoId INTEGER PRIMARY KEY); | |
| 166 | 167 | ; |
| 167 | 168 | undo_reset(); |
| 168 | - db_multi_exec(zSql); | |
| 169 | + if( strcmp(g.zMainDbType,zDb)==0 ) zDb = "main"; | |
| 170 | + db_multi_exec(zSql, zDb, zDb, zDb, zDb); | |
| 169 | 171 | cid = db_lget_int("checkout", 0); |
| 170 | 172 | db_lset_int("undo_checkout", cid); |
| 171 | 173 | db_lset_int("undo_available", 1); |
| 172 | 174 | undoActive = 1; |
| 173 | 175 | } |
| 174 | 176 |
| --- src/undo.c | |
| +++ src/undo.c | |
| @@ -151,23 +151,25 @@ | |
| 151 | /* |
| 152 | ** Begin capturing a snapshot that can be undone. |
| 153 | */ |
| 154 | void undo_begin(void){ |
| 155 | int cid; |
| 156 | static const char zSql[] = |
| 157 | @ CREATE TABLE undo( |
| 158 | @ pathname TEXT UNIQUE, -- Name of the file |
| 159 | @ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable |
| 160 | @ existsflag BOOLEAN, -- True if the file exists |
| 161 | @ content BLOB -- Saved content |
| 162 | @ ); |
| 163 | @ CREATE TABLE undo_vfile AS SELECT * FROM vfile; |
| 164 | @ CREATE TABLE undo_vmerge AS SELECT * FROM vmerge; |
| 165 | @ CREATE TABLE undo_pending(undoId INTEGER PRIMARY KEY); |
| 166 | ; |
| 167 | undo_reset(); |
| 168 | db_multi_exec(zSql); |
| 169 | cid = db_lget_int("checkout", 0); |
| 170 | db_lset_int("undo_checkout", cid); |
| 171 | db_lset_int("undo_available", 1); |
| 172 | undoActive = 1; |
| 173 | } |
| 174 |
| --- src/undo.c | |
| +++ src/undo.c | |
| @@ -151,23 +151,25 @@ | |
| 151 | /* |
| 152 | ** Begin capturing a snapshot that can be undone. |
| 153 | */ |
| 154 | void undo_begin(void){ |
| 155 | int cid; |
| 156 | const char *zDb = "localdb"; |
| 157 | static const char zSql[] = |
| 158 | @ CREATE TABLE %s.undo( |
| 159 | @ pathname TEXT UNIQUE, -- Name of the file |
| 160 | @ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable |
| 161 | @ existsflag BOOLEAN, -- True if the file exists |
| 162 | @ content BLOB -- Saved content |
| 163 | @ ); |
| 164 | @ CREATE TABLE %s.undo_vfile AS SELECT * FROM vfile; |
| 165 | @ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge; |
| 166 | @ CREATE TABLE %s.undo_pending(undoId INTEGER PRIMARY KEY); |
| 167 | ; |
| 168 | undo_reset(); |
| 169 | if( strcmp(g.zMainDbType,zDb)==0 ) zDb = "main"; |
| 170 | db_multi_exec(zSql, zDb, zDb, zDb, zDb); |
| 171 | cid = db_lget_int("checkout", 0); |
| 172 | db_lset_int("undo_checkout", cid); |
| 173 | db_lset_int("undo_available", 1); |
| 174 | undoActive = 1; |
| 175 | } |
| 176 |