Fossil SCM

Remove appropriate "ckout:" records from the config table when closing a checkout. Do not attempt to modify the repository with "ckout:" records if the repository is read-only.

drh 2012-04-29 16:54 trunk
Commit 02051489a03874d4f16446e8fb58d74711d98cfa
3 files changed +3 +17 -6 +9 -5
--- src/checkout.c
+++ src/checkout.c
@@ -291,9 +291,12 @@
291291
int forceFlag = find_option("force","f",0)!=0;
292292
db_must_be_within_tree();
293293
if( !forceFlag && unsaved_changes()==1 ){
294294
fossil_fatal("there are unsaved changes in the current checkout");
295295
}
296
+ if( db_is_writeable("repository") ){
297
+ db_multi_exec("DELETE FROM config WHERE name='ckout:%q'", g.zLocalRoot);
298
+ }
296299
unlink_local_database(1);
297300
db_close(1);
298301
unlink_local_database(0);
299302
}
300303
--- src/checkout.c
+++ src/checkout.c
@@ -291,9 +291,12 @@
291 int forceFlag = find_option("force","f",0)!=0;
292 db_must_be_within_tree();
293 if( !forceFlag && unsaved_changes()==1 ){
294 fossil_fatal("there are unsaved changes in the current checkout");
295 }
 
 
 
296 unlink_local_database(1);
297 db_close(1);
298 unlink_local_database(0);
299 }
300
--- src/checkout.c
+++ src/checkout.c
@@ -291,9 +291,12 @@
291 int forceFlag = find_option("force","f",0)!=0;
292 db_must_be_within_tree();
293 if( !forceFlag && unsaved_changes()==1 ){
294 fossil_fatal("there are unsaved changes in the current checkout");
295 }
296 if( db_is_writeable("repository") ){
297 db_multi_exec("DELETE FROM config WHERE name='ckout:%q'", g.zLocalRoot);
298 }
299 unlink_local_database(1);
300 db_close(1);
301 unlink_local_database(0);
302 }
303
+17 -6
--- src/db.c
+++ src/db.c
@@ -502,12 +502,12 @@
502502
/*
503503
** Optionally make the following changes to the database if feasible and
504504
** convenient. Do not start a transaction for these changes, but only
505505
** make these changes if other changes are also being made.
506506
*/
507
-void db_optional_sql(const char *zSql, ...){
508
- if( db.nBeforeCommit < count(db.azBeforeCommit) ){
507
+void db_optional_sql(const char *zDb, const char *zSql, ...){
508
+ if( db_is_writeable(zDb) && db.nBeforeCommit < count(db.azBeforeCommit) ){
509509
va_list ap;
510510
va_start(ap, zSql);
511511
db.azBeforeCommit[db.nBeforeCommit++] = sqlite3_vmprintf(zSql, ap);
512512
va_end(ap);
513513
}
@@ -1020,10 +1020,17 @@
10201020
int db_schema_is_outofdate(void){
10211021
return db_exists("SELECT 1 FROM config"
10221022
" WHERE name='aux-schema'"
10231023
" AND value<>'%s'", AUX_SCHEMA);
10241024
}
1025
+
1026
+/*
1027
+** Return true if the database is writeable
1028
+*/
1029
+int db_is_writeable(const char *zName){
1030
+ return !sqlite3_db_readonly(g.db, db_name(zName));
1031
+}
10251032
10261033
/*
10271034
** Verify that the repository schema is correct. If it is not correct,
10281035
** issue a fatal error and die.
10291036
*/
@@ -1736,16 +1743,20 @@
17361743
db_multi_exec(
17371744
"REPLACE INTO global_config(name, value)"
17381745
"VALUES('ckout:%q','%q');",
17391746
blob_str(&localRoot), blob_str(&full)
17401747
);
1741
- db_optional_sql("REPLACE INTO config(name,value,mtime)"
1742
- "VALUES('ckout:%q',1,now())",
1743
- blob_str(&localRoot));
1748
+ db_swap_connections();
1749
+ db_optional_sql("repository",
1750
+ "REPLACE INTO config(name,value,mtime)"
1751
+ "VALUES('ckout:%q',1,now())",
1752
+ blob_str(&localRoot)
1753
+ );
17441754
blob_reset(&localRoot);
1755
+ }else{
1756
+ db_swap_connections();
17451757
}
1746
- db_swap_connections();
17471758
blob_reset(&full);
17481759
}
17491760
17501761
/*
17511762
** COMMAND: open
17521763
--- src/db.c
+++ src/db.c
@@ -502,12 +502,12 @@
502 /*
503 ** Optionally make the following changes to the database if feasible and
504 ** convenient. Do not start a transaction for these changes, but only
505 ** make these changes if other changes are also being made.
506 */
507 void db_optional_sql(const char *zSql, ...){
508 if( db.nBeforeCommit < count(db.azBeforeCommit) ){
509 va_list ap;
510 va_start(ap, zSql);
511 db.azBeforeCommit[db.nBeforeCommit++] = sqlite3_vmprintf(zSql, ap);
512 va_end(ap);
513 }
@@ -1020,10 +1020,17 @@
1020 int db_schema_is_outofdate(void){
1021 return db_exists("SELECT 1 FROM config"
1022 " WHERE name='aux-schema'"
1023 " AND value<>'%s'", AUX_SCHEMA);
1024 }
 
 
 
 
 
 
 
1025
1026 /*
1027 ** Verify that the repository schema is correct. If it is not correct,
1028 ** issue a fatal error and die.
1029 */
@@ -1736,16 +1743,20 @@
1736 db_multi_exec(
1737 "REPLACE INTO global_config(name, value)"
1738 "VALUES('ckout:%q','%q');",
1739 blob_str(&localRoot), blob_str(&full)
1740 );
1741 db_optional_sql("REPLACE INTO config(name,value,mtime)"
1742 "VALUES('ckout:%q',1,now())",
1743 blob_str(&localRoot));
 
 
 
1744 blob_reset(&localRoot);
 
 
1745 }
1746 db_swap_connections();
1747 blob_reset(&full);
1748 }
1749
1750 /*
1751 ** COMMAND: open
1752
--- src/db.c
+++ src/db.c
@@ -502,12 +502,12 @@
502 /*
503 ** Optionally make the following changes to the database if feasible and
504 ** convenient. Do not start a transaction for these changes, but only
505 ** make these changes if other changes are also being made.
506 */
507 void db_optional_sql(const char *zDb, const char *zSql, ...){
508 if( db_is_writeable(zDb) && db.nBeforeCommit < count(db.azBeforeCommit) ){
509 va_list ap;
510 va_start(ap, zSql);
511 db.azBeforeCommit[db.nBeforeCommit++] = sqlite3_vmprintf(zSql, ap);
512 va_end(ap);
513 }
@@ -1020,10 +1020,17 @@
1020 int db_schema_is_outofdate(void){
1021 return db_exists("SELECT 1 FROM config"
1022 " WHERE name='aux-schema'"
1023 " AND value<>'%s'", AUX_SCHEMA);
1024 }
1025
1026 /*
1027 ** Return true if the database is writeable
1028 */
1029 int db_is_writeable(const char *zName){
1030 return !sqlite3_db_readonly(g.db, db_name(zName));
1031 }
1032
1033 /*
1034 ** Verify that the repository schema is correct. If it is not correct,
1035 ** issue a fatal error and die.
1036 */
@@ -1736,16 +1743,20 @@
1743 db_multi_exec(
1744 "REPLACE INTO global_config(name, value)"
1745 "VALUES('ckout:%q','%q');",
1746 blob_str(&localRoot), blob_str(&full)
1747 );
1748 db_swap_connections();
1749 db_optional_sql("repository",
1750 "REPLACE INTO config(name,value,mtime)"
1751 "VALUES('ckout:%q',1,now())",
1752 blob_str(&localRoot)
1753 );
1754 blob_reset(&localRoot);
1755 }else{
1756 db_swap_connections();
1757 }
 
1758 blob_reset(&full);
1759 }
1760
1761 /*
1762 ** COMMAND: open
1763
+9 -5
--- src/main.c
+++ src/main.c
@@ -1092,16 +1092,20 @@
10921092
g.zTop = &g.zBaseURL[8+strlen(zHost)];
10931093
}else{
10941094
g.zBaseURL = mprintf("http://%s%.*s", zHost, i, zCur);
10951095
g.zTop = &g.zBaseURL[7+strlen(zHost)];
10961096
}
1097
- if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", g.zBaseURL) ){
1098
- db_multi_exec("INSERT INTO config(name,value,mtime)"
1099
- "VALUES('baseurl:%q',1,now())", g.zBaseURL);
1100
- }else{
1101
- db_optional_sql("REPLACE INTO config(name,value,mtime)"
1097
+ if( db_is_writeable("repository") ){
1098
+ if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", g.zBaseURL) ){
1099
+ db_multi_exec("INSERT INTO config(name,value,mtime)"
11021100
"VALUES('baseurl:%q',1,now())", g.zBaseURL);
1101
+ }else{
1102
+ db_optional_sql("repository",
1103
+ "REPLACE INTO config(name,value,mtime)"
1104
+ "VALUES('baseurl:%q',1,now())", g.zBaseURL
1105
+ );
1106
+ }
11031107
}
11041108
}
11051109
11061110
/*
11071111
** Send an HTTP redirect back to the designated Index Page.
11081112
--- src/main.c
+++ src/main.c
@@ -1092,16 +1092,20 @@
1092 g.zTop = &g.zBaseURL[8+strlen(zHost)];
1093 }else{
1094 g.zBaseURL = mprintf("http://%s%.*s", zHost, i, zCur);
1095 g.zTop = &g.zBaseURL[7+strlen(zHost)];
1096 }
1097 if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", g.zBaseURL) ){
1098 db_multi_exec("INSERT INTO config(name,value,mtime)"
1099 "VALUES('baseurl:%q',1,now())", g.zBaseURL);
1100 }else{
1101 db_optional_sql("REPLACE INTO config(name,value,mtime)"
1102 "VALUES('baseurl:%q',1,now())", g.zBaseURL);
 
 
 
 
 
 
1103 }
1104 }
1105
1106 /*
1107 ** Send an HTTP redirect back to the designated Index Page.
1108
--- src/main.c
+++ src/main.c
@@ -1092,16 +1092,20 @@
1092 g.zTop = &g.zBaseURL[8+strlen(zHost)];
1093 }else{
1094 g.zBaseURL = mprintf("http://%s%.*s", zHost, i, zCur);
1095 g.zTop = &g.zBaseURL[7+strlen(zHost)];
1096 }
1097 if( db_is_writeable("repository") ){
1098 if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", g.zBaseURL) ){
1099 db_multi_exec("INSERT INTO config(name,value,mtime)"
 
 
1100 "VALUES('baseurl:%q',1,now())", g.zBaseURL);
1101 }else{
1102 db_optional_sql("repository",
1103 "REPLACE INTO config(name,value,mtime)"
1104 "VALUES('baseurl:%q',1,now())", g.zBaseURL
1105 );
1106 }
1107 }
1108 }
1109
1110 /*
1111 ** Send an HTTP redirect back to the designated Index Page.
1112

Keyboard Shortcuts

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