Fossil SCM

Record the names of checkouts and access URLs in the config table and display that information using the "info" command.

drh 2012-04-27 15:43 trunk
Commit e604d483ee55e5ef392910296165f21b4e1a2fa7
3 files changed +27 -1 +34 +2
+27 -1
--- src/db.c
+++ src/db.c
@@ -115,10 +115,12 @@
115115
struct sCommitHook {
116116
int (*xHook)(void); /* Functions to call at db_end_transaction() */
117117
int sequence; /* Call functions in sequence order */
118118
} aHook[5];
119119
char *azDeleteOnFail[3]; /* Files to delete on a failure */
120
+ char *azBeforeCommit[5]; /* Commands to run prior to COMMIT */
121
+ int nBeforeCommit; /* Number of entries in azBeforeCommit */
120122
} db = {0, 0, 0, 0, 0, 0, };
121123
122124
/*
123125
** Arrange for the given file to be deleted on a failure.
124126
*/
@@ -159,11 +161,18 @@
159161
if( db.nBegin<=0 ) return;
160162
if( rollbackFlag ) db.doRollback = 1;
161163
db.nBegin--;
162164
if( db.nBegin==0 ){
163165
int i;
164
- if( db.doRollback==0 ) leaf_do_pending_checks();
166
+ if( db.doRollback==0 ){
167
+ while( db.nBeforeCommit ){
168
+ db.nBeforeCommit--;
169
+ db_multi_exec(db.azBeforeCommit[db.nBeforeCommit]);
170
+ sqlite3_free(db.azBeforeCommit[db.nBeforeCommit]);
171
+ }
172
+ leaf_do_pending_checks();
173
+ }
165174
for(i=0; db.doRollback==0 && i<db.nCommitHook; i++){
166175
db.doRollback |= db.aHook[i].xHook();
167176
}
168177
while( db.pAllStmt ){
169178
db_finalize(db.pAllStmt);
@@ -487,10 +496,24 @@
487496
db_err("%s\n%s", zErr, blob_buffer(&sql));
488497
}
489498
blob_reset(&sql);
490499
return rc;
491500
}
501
+
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
+ }
514
+}
492515
493516
/*
494517
** Execute a query and return a single integer value.
495518
*/
496519
i64 db_int64(i64 iDflt, const char *zSql, ...){
@@ -1713,10 +1736,13 @@
17131736
db_multi_exec(
17141737
"REPLACE INTO global_config(name, value)"
17151738
"VALUES('ckout:%q','%q');",
17161739
blob_str(&localRoot), blob_str(&full)
17171740
);
1741
+ db_optional_sql("REPLACE INTO config(name,value,mtime)"
1742
+ "VALUES('ckout:%q',1,now())",
1743
+ blob_str(&localRoot));
17181744
blob_reset(&localRoot);
17191745
}
17201746
db_swap_connections();
17211747
blob_reset(&full);
17221748
}
17231749
--- src/db.c
+++ src/db.c
@@ -115,10 +115,12 @@
115 struct sCommitHook {
116 int (*xHook)(void); /* Functions to call at db_end_transaction() */
117 int sequence; /* Call functions in sequence order */
118 } aHook[5];
119 char *azDeleteOnFail[3]; /* Files to delete on a failure */
 
 
120 } db = {0, 0, 0, 0, 0, 0, };
121
122 /*
123 ** Arrange for the given file to be deleted on a failure.
124 */
@@ -159,11 +161,18 @@
159 if( db.nBegin<=0 ) return;
160 if( rollbackFlag ) db.doRollback = 1;
161 db.nBegin--;
162 if( db.nBegin==0 ){
163 int i;
164 if( db.doRollback==0 ) leaf_do_pending_checks();
 
 
 
 
 
 
 
165 for(i=0; db.doRollback==0 && i<db.nCommitHook; i++){
166 db.doRollback |= db.aHook[i].xHook();
167 }
168 while( db.pAllStmt ){
169 db_finalize(db.pAllStmt);
@@ -487,10 +496,24 @@
487 db_err("%s\n%s", zErr, blob_buffer(&sql));
488 }
489 blob_reset(&sql);
490 return rc;
491 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492
493 /*
494 ** Execute a query and return a single integer value.
495 */
496 i64 db_int64(i64 iDflt, const char *zSql, ...){
@@ -1713,10 +1736,13 @@
1713 db_multi_exec(
1714 "REPLACE INTO global_config(name, value)"
1715 "VALUES('ckout:%q','%q');",
1716 blob_str(&localRoot), blob_str(&full)
1717 );
 
 
 
1718 blob_reset(&localRoot);
1719 }
1720 db_swap_connections();
1721 blob_reset(&full);
1722 }
1723
--- src/db.c
+++ src/db.c
@@ -115,10 +115,12 @@
115 struct sCommitHook {
116 int (*xHook)(void); /* Functions to call at db_end_transaction() */
117 int sequence; /* Call functions in sequence order */
118 } aHook[5];
119 char *azDeleteOnFail[3]; /* Files to delete on a failure */
120 char *azBeforeCommit[5]; /* Commands to run prior to COMMIT */
121 int nBeforeCommit; /* Number of entries in azBeforeCommit */
122 } db = {0, 0, 0, 0, 0, 0, };
123
124 /*
125 ** Arrange for the given file to be deleted on a failure.
126 */
@@ -159,11 +161,18 @@
161 if( db.nBegin<=0 ) return;
162 if( rollbackFlag ) db.doRollback = 1;
163 db.nBegin--;
164 if( db.nBegin==0 ){
165 int i;
166 if( db.doRollback==0 ){
167 while( db.nBeforeCommit ){
168 db.nBeforeCommit--;
169 db_multi_exec(db.azBeforeCommit[db.nBeforeCommit]);
170 sqlite3_free(db.azBeforeCommit[db.nBeforeCommit]);
171 }
172 leaf_do_pending_checks();
173 }
174 for(i=0; db.doRollback==0 && i<db.nCommitHook; i++){
175 db.doRollback |= db.aHook[i].xHook();
176 }
177 while( db.pAllStmt ){
178 db_finalize(db.pAllStmt);
@@ -487,10 +496,24 @@
496 db_err("%s\n%s", zErr, blob_buffer(&sql));
497 }
498 blob_reset(&sql);
499 return rc;
500 }
501
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 }
514 }
515
516 /*
517 ** Execute a query and return a single integer value.
518 */
519 i64 db_int64(i64 iDflt, const char *zSql, ...){
@@ -1713,10 +1736,13 @@
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
+34
--- src/info.c
+++ src/info.c
@@ -121,10 +121,42 @@
121121
comment_print(zComment, 14, 79);
122122
free(zComment);
123123
}
124124
}
125125
126
+/*
127
+** Print information about the URLs used to access a repository and
128
+** checkouts in a repository.
129
+*/
130
+static void extraRepoInfo(void){
131
+ Stmt s;
132
+ db_prepare(&s, "SELECT substr(name,7), date(mtime,'unixepoch')"
133
+ " FROM config"
134
+ " WHERE name GLOB 'ckout:*' ORDER BY name");
135
+ while( db_step(&s)==SQLITE_ROW ){
136
+ const char *zName;
137
+ const char *zCkout = db_column_text(&s, 0);
138
+ if( g.localOpen ){
139
+ if( fossil_strcmp(zCkout, g.zLocalRoot)==0 ) continue;
140
+ zName = "alt-root:";
141
+ }else{
142
+ zName = "check-out:";
143
+ }
144
+ fossil_print("%-11s %-54s %s\n", zName, zCkout,
145
+ db_column_text(&s, 1));
146
+ }
147
+ db_finalize(&s);
148
+ db_prepare(&s, "SELECT substr(name,9), date(mtime,'unixepoch')"
149
+ " FROM config"
150
+ " WHERE name GLOB 'baseurl:*' ORDER BY name");
151
+ while( db_step(&s)==SQLITE_ROW ){
152
+ fossil_print("access-url: %-54s %s\n", db_column_text(&s, 0),
153
+ db_column_text(&s, 1));
154
+ }
155
+ db_finalize(&s);
156
+}
157
+
126158
127159
/*
128160
** COMMAND: info
129161
**
130162
** Usage: %fossil info ?VERSION | REPOSITORY_FILENAME? ?OPTIONS?
@@ -150,10 +182,11 @@
150182
db_open_config(0);
151183
db_record_repository_filename(g.argv[2]);
152184
db_open_repository(g.argv[2]);
153185
fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
154186
fossil_print("project-code: %s\n", db_get("project-code", "<none>"));
187
+ extraRepoInfo();
155188
return;
156189
}
157190
db_find_and_open_repository(0,0);
158191
if( g.argc==2 ){
159192
int vid;
@@ -162,10 +195,11 @@
162195
fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
163196
if( g.localOpen ){
164197
fossil_print("repository: %s\n", db_repository_filename());
165198
fossil_print("local-root: %s\n", g.zLocalRoot);
166199
}
200
+ extraRepoInfo();
167201
#if defined(_WIN32)
168202
if( g.zHome ){
169203
fossil_print("user-home: %s\n", g.zHome);
170204
}
171205
#endif
172206
--- src/info.c
+++ src/info.c
@@ -121,10 +121,42 @@
121 comment_print(zComment, 14, 79);
122 free(zComment);
123 }
124 }
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
127 /*
128 ** COMMAND: info
129 **
130 ** Usage: %fossil info ?VERSION | REPOSITORY_FILENAME? ?OPTIONS?
@@ -150,10 +182,11 @@
150 db_open_config(0);
151 db_record_repository_filename(g.argv[2]);
152 db_open_repository(g.argv[2]);
153 fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
154 fossil_print("project-code: %s\n", db_get("project-code", "<none>"));
 
155 return;
156 }
157 db_find_and_open_repository(0,0);
158 if( g.argc==2 ){
159 int vid;
@@ -162,10 +195,11 @@
162 fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
163 if( g.localOpen ){
164 fossil_print("repository: %s\n", db_repository_filename());
165 fossil_print("local-root: %s\n", g.zLocalRoot);
166 }
 
167 #if defined(_WIN32)
168 if( g.zHome ){
169 fossil_print("user-home: %s\n", g.zHome);
170 }
171 #endif
172
--- src/info.c
+++ src/info.c
@@ -121,10 +121,42 @@
121 comment_print(zComment, 14, 79);
122 free(zComment);
123 }
124 }
125
126 /*
127 ** Print information about the URLs used to access a repository and
128 ** checkouts in a repository.
129 */
130 static void extraRepoInfo(void){
131 Stmt s;
132 db_prepare(&s, "SELECT substr(name,7), date(mtime,'unixepoch')"
133 " FROM config"
134 " WHERE name GLOB 'ckout:*' ORDER BY name");
135 while( db_step(&s)==SQLITE_ROW ){
136 const char *zName;
137 const char *zCkout = db_column_text(&s, 0);
138 if( g.localOpen ){
139 if( fossil_strcmp(zCkout, g.zLocalRoot)==0 ) continue;
140 zName = "alt-root:";
141 }else{
142 zName = "check-out:";
143 }
144 fossil_print("%-11s %-54s %s\n", zName, zCkout,
145 db_column_text(&s, 1));
146 }
147 db_finalize(&s);
148 db_prepare(&s, "SELECT substr(name,9), date(mtime,'unixepoch')"
149 " FROM config"
150 " WHERE name GLOB 'baseurl:*' ORDER BY name");
151 while( db_step(&s)==SQLITE_ROW ){
152 fossil_print("access-url: %-54s %s\n", db_column_text(&s, 0),
153 db_column_text(&s, 1));
154 }
155 db_finalize(&s);
156 }
157
158
159 /*
160 ** COMMAND: info
161 **
162 ** Usage: %fossil info ?VERSION | REPOSITORY_FILENAME? ?OPTIONS?
@@ -150,10 +182,11 @@
182 db_open_config(0);
183 db_record_repository_filename(g.argv[2]);
184 db_open_repository(g.argv[2]);
185 fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
186 fossil_print("project-code: %s\n", db_get("project-code", "<none>"));
187 extraRepoInfo();
188 return;
189 }
190 db_find_and_open_repository(0,0);
191 if( g.argc==2 ){
192 int vid;
@@ -162,10 +195,11 @@
195 fossil_print("project-name: %s\n", db_get("project-name", "<unnamed>"));
196 if( g.localOpen ){
197 fossil_print("repository: %s\n", db_repository_filename());
198 fossil_print("local-root: %s\n", g.zLocalRoot);
199 }
200 extraRepoInfo();
201 #if defined(_WIN32)
202 if( g.zHome ){
203 fossil_print("user-home: %s\n", g.zHome);
204 }
205 #endif
206
+2
--- src/main.c
+++ src/main.c
@@ -1087,10 +1087,12 @@
10871087
g.zTop = &g.zBaseURL[8+strlen(zHost)];
10881088
}else{
10891089
g.zBaseURL = mprintf("http://%s%.*s", zHost, i, zCur);
10901090
g.zTop = &g.zBaseURL[7+strlen(zHost)];
10911091
}
1092
+ db_optional_sql("REPLACE INTO config(name,value,mtime)"
1093
+ "VALUES('baseurl:%q',1,now())", g.zBaseURL);
10921094
}
10931095
10941096
/*
10951097
** Send an HTTP redirect back to the designated Index Page.
10961098
*/
10971099
--- src/main.c
+++ src/main.c
@@ -1087,10 +1087,12 @@
1087 g.zTop = &g.zBaseURL[8+strlen(zHost)];
1088 }else{
1089 g.zBaseURL = mprintf("http://%s%.*s", zHost, i, zCur);
1090 g.zTop = &g.zBaseURL[7+strlen(zHost)];
1091 }
 
 
1092 }
1093
1094 /*
1095 ** Send an HTTP redirect back to the designated Index Page.
1096 */
1097
--- src/main.c
+++ src/main.c
@@ -1087,10 +1087,12 @@
1087 g.zTop = &g.zBaseURL[8+strlen(zHost)];
1088 }else{
1089 g.zBaseURL = mprintf("http://%s%.*s", zHost, i, zCur);
1090 g.zTop = &g.zBaseURL[7+strlen(zHost)];
1091 }
1092 db_optional_sql("REPLACE INTO config(name,value,mtime)"
1093 "VALUES('baseurl:%q',1,now())", g.zBaseURL);
1094 }
1095
1096 /*
1097 ** Send an HTTP redirect back to the designated Index Page.
1098 */
1099

Keyboard Shortcuts

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