Fossil SCM

The "extra" and "clean" commands ignore the repository file if the repository happens to be within the check-out. Ticket [c7b35be88].

drh 2008-07-23 13:01 trunk
Commit 2ecc407d9be8f079f8cd631ddbb2e0884a1254a3
+2 -2
--- src/add.c
+++ src/add.c
@@ -60,11 +60,11 @@
6060
fossil_fatal("not found: %s", zName);
6161
}
6262
if( isDir==2 && access(zName, R_OK) ){
6363
fossil_fatal("cannot open %s", zName);
6464
}
65
- file_tree_name(zName, &pathname);
65
+ file_tree_name(zName, &pathname, 1);
6666
zPath = blob_str(&pathname);
6767
if( strcmp(zPath, "manifest")==0
6868
|| strcmp(zPath, "_FOSSIL_")==0
6969
|| strcmp(zPath, "manifest.uuid")==0
7070
){
@@ -109,11 +109,11 @@
109109
char *zName;
110110
char *zPath;
111111
Blob pathname;
112112
113113
zName = mprintf("%/", g.argv[i]);
114
- file_tree_name(zName, &pathname);
114
+ file_tree_name(zName, &pathname, 1);
115115
zPath = blob_str(&pathname);
116116
if( !db_exists(
117117
"SELECT 1 FROM vfile WHERE pathname=%Q AND NOT deleted", zPath) ){
118118
fossil_fatal("not in the repository: %s", zName);
119119
}else{
120120
--- src/add.c
+++ src/add.c
@@ -60,11 +60,11 @@
60 fossil_fatal("not found: %s", zName);
61 }
62 if( isDir==2 && access(zName, R_OK) ){
63 fossil_fatal("cannot open %s", zName);
64 }
65 file_tree_name(zName, &pathname);
66 zPath = blob_str(&pathname);
67 if( strcmp(zPath, "manifest")==0
68 || strcmp(zPath, "_FOSSIL_")==0
69 || strcmp(zPath, "manifest.uuid")==0
70 ){
@@ -109,11 +109,11 @@
109 char *zName;
110 char *zPath;
111 Blob pathname;
112
113 zName = mprintf("%/", g.argv[i]);
114 file_tree_name(zName, &pathname);
115 zPath = blob_str(&pathname);
116 if( !db_exists(
117 "SELECT 1 FROM vfile WHERE pathname=%Q AND NOT deleted", zPath) ){
118 fossil_fatal("not in the repository: %s", zName);
119 }else{
120
--- src/add.c
+++ src/add.c
@@ -60,11 +60,11 @@
60 fossil_fatal("not found: %s", zName);
61 }
62 if( isDir==2 && access(zName, R_OK) ){
63 fossil_fatal("cannot open %s", zName);
64 }
65 file_tree_name(zName, &pathname, 1);
66 zPath = blob_str(&pathname);
67 if( strcmp(zPath, "manifest")==0
68 || strcmp(zPath, "_FOSSIL_")==0
69 || strcmp(zPath, "manifest.uuid")==0
70 ){
@@ -109,11 +109,11 @@
109 char *zName;
110 char *zPath;
111 Blob pathname;
112
113 zName = mprintf("%/", g.argv[i]);
114 file_tree_name(zName, &pathname, 1);
115 zPath = blob_str(&pathname);
116 if( !db_exists(
117 "SELECT 1 FROM vfile WHERE pathname=%Q AND NOT deleted", zPath) ){
118 fossil_fatal("not in the repository: %s", zName);
119 }else{
120
+9 -2
--- src/checkin.c
+++ src/checkin.c
@@ -154,10 +154,11 @@
154154
** Print a list of all files in the source tree that are not part of
155155
** the current checkout. See also the "clean" command.
156156
*/
157157
void extra_cmd(void){
158158
Blob path;
159
+ Blob repo;
159160
Stmt q;
160161
int n;
161162
db_must_be_within_tree();
162163
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
163164
n = strlen(g.zLocalRoot);
@@ -165,10 +166,13 @@
165166
vfile_scan(0, &path, blob_size(&path));
166167
db_prepare(&q,
167168
"SELECT x FROM sfile"
168169
" WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
169170
" ORDER BY 1");
171
+ if( file_tree_name(g.zRepositoryName, &repo, 0) ){
172
+ db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
173
+ }
170174
while( db_step(&q)==SQLITE_ROW ){
171175
printf("%s\n", db_column_text(&q, 0));
172176
}
173177
db_finalize(&q);
174178
}
@@ -185,11 +189,11 @@
185189
** sure you wish to remove all "extra" files you can specify the
186190
** optional -all flag.
187191
*/
188192
void clean_cmd(void){
189193
int allFlag;
190
- Blob path;
194
+ Blob path, repo;
191195
Stmt q;
192196
int n;
193197
allFlag = find_option("all","a",0)!=0;
194198
db_must_be_within_tree();
195199
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
@@ -198,10 +202,13 @@
198202
vfile_scan(0, &path, blob_size(&path));
199203
db_prepare(&q,
200204
"SELECT %Q || x FROM sfile"
201205
" WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
202206
" ORDER BY 1", g.zLocalRoot);
207
+ if( file_tree_name(g.zRepositoryName, &repo, 0) ){
208
+ db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
209
+ }
203210
while( db_step(&q)==SQLITE_ROW ){
204211
if( allFlag ){
205212
unlink(db_column_text(&q, 0));
206213
}else{
207214
Blob ans;
@@ -303,11 +310,11 @@
303310
blob_zero(&b);
304311
g.aCommitFile = malloc(sizeof(int)*(g.argc-1));
305312
306313
for(ii=2; ii<g.argc; ii++){
307314
int iId;
308
- file_tree_name(g.argv[ii], &b);
315
+ file_tree_name(g.argv[ii], &b, 1);
309316
iId = db_int(-1, "SELECT id FROM vfile WHERE pathname=%Q", blob_str(&b));
310317
if( iId<0 ){
311318
fossil_fatal("fossil knows nothing about: %s", g.argv[ii]);
312319
}
313320
g.aCommitFile[ii-2] = iId;
314321
--- src/checkin.c
+++ src/checkin.c
@@ -154,10 +154,11 @@
154 ** Print a list of all files in the source tree that are not part of
155 ** the current checkout. See also the "clean" command.
156 */
157 void extra_cmd(void){
158 Blob path;
 
159 Stmt q;
160 int n;
161 db_must_be_within_tree();
162 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
163 n = strlen(g.zLocalRoot);
@@ -165,10 +166,13 @@
165 vfile_scan(0, &path, blob_size(&path));
166 db_prepare(&q,
167 "SELECT x FROM sfile"
168 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
169 " ORDER BY 1");
 
 
 
170 while( db_step(&q)==SQLITE_ROW ){
171 printf("%s\n", db_column_text(&q, 0));
172 }
173 db_finalize(&q);
174 }
@@ -185,11 +189,11 @@
185 ** sure you wish to remove all "extra" files you can specify the
186 ** optional -all flag.
187 */
188 void clean_cmd(void){
189 int allFlag;
190 Blob path;
191 Stmt q;
192 int n;
193 allFlag = find_option("all","a",0)!=0;
194 db_must_be_within_tree();
195 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
@@ -198,10 +202,13 @@
198 vfile_scan(0, &path, blob_size(&path));
199 db_prepare(&q,
200 "SELECT %Q || x FROM sfile"
201 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
202 " ORDER BY 1", g.zLocalRoot);
 
 
 
203 while( db_step(&q)==SQLITE_ROW ){
204 if( allFlag ){
205 unlink(db_column_text(&q, 0));
206 }else{
207 Blob ans;
@@ -303,11 +310,11 @@
303 blob_zero(&b);
304 g.aCommitFile = malloc(sizeof(int)*(g.argc-1));
305
306 for(ii=2; ii<g.argc; ii++){
307 int iId;
308 file_tree_name(g.argv[ii], &b);
309 iId = db_int(-1, "SELECT id FROM vfile WHERE pathname=%Q", blob_str(&b));
310 if( iId<0 ){
311 fossil_fatal("fossil knows nothing about: %s", g.argv[ii]);
312 }
313 g.aCommitFile[ii-2] = iId;
314
--- src/checkin.c
+++ src/checkin.c
@@ -154,10 +154,11 @@
154 ** Print a list of all files in the source tree that are not part of
155 ** the current checkout. See also the "clean" command.
156 */
157 void extra_cmd(void){
158 Blob path;
159 Blob repo;
160 Stmt q;
161 int n;
162 db_must_be_within_tree();
163 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
164 n = strlen(g.zLocalRoot);
@@ -165,10 +166,13 @@
166 vfile_scan(0, &path, blob_size(&path));
167 db_prepare(&q,
168 "SELECT x FROM sfile"
169 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
170 " ORDER BY 1");
171 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
172 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
173 }
174 while( db_step(&q)==SQLITE_ROW ){
175 printf("%s\n", db_column_text(&q, 0));
176 }
177 db_finalize(&q);
178 }
@@ -185,11 +189,11 @@
189 ** sure you wish to remove all "extra" files you can specify the
190 ** optional -all flag.
191 */
192 void clean_cmd(void){
193 int allFlag;
194 Blob path, repo;
195 Stmt q;
196 int n;
197 allFlag = find_option("all","a",0)!=0;
198 db_must_be_within_tree();
199 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
@@ -198,10 +202,13 @@
202 vfile_scan(0, &path, blob_size(&path));
203 db_prepare(&q,
204 "SELECT %Q || x FROM sfile"
205 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
206 " ORDER BY 1", g.zLocalRoot);
207 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
208 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
209 }
210 while( db_step(&q)==SQLITE_ROW ){
211 if( allFlag ){
212 unlink(db_column_text(&q, 0));
213 }else{
214 Blob ans;
@@ -303,11 +310,11 @@
310 blob_zero(&b);
311 g.aCommitFile = malloc(sizeof(int)*(g.argc-1));
312
313 for(ii=2; ii<g.argc; ii++){
314 int iId;
315 file_tree_name(g.argv[ii], &b, 1);
316 iId = db_int(-1, "SELECT id FROM vfile WHERE pathname=%Q", blob_str(&b));
317 if( iId<0 ){
318 fossil_fatal("fossil knows nothing about: %s", g.argv[ii]);
319 }
320 g.aCommitFile[ii-2] = iId;
321
+1 -1
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -99,11 +99,11 @@
9999
}
100100
blob_zero(&cmd);
101101
blob_appendf(&cmd, "%s ", zExternalCommand);
102102
}
103103
zFile = g.argv[g.argc-1];
104
- file_tree_name(zFile, &fname);
104
+ file_tree_name(zFile, &fname, 1);
105105
106106
blob_zero(&vname);
107107
do{
108108
blob_reset(&vname);
109109
blob_appendf(&vname, "%s~%d", zFile, cnt++);
110110
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -99,11 +99,11 @@
99 }
100 blob_zero(&cmd);
101 blob_appendf(&cmd, "%s ", zExternalCommand);
102 }
103 zFile = g.argv[g.argc-1];
104 file_tree_name(zFile, &fname);
105
106 blob_zero(&vname);
107 do{
108 blob_reset(&vname);
109 blob_appendf(&vname, "%s~%d", zFile, cnt++);
110
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -99,11 +99,11 @@
99 }
100 blob_zero(&cmd);
101 blob_appendf(&cmd, "%s ", zExternalCommand);
102 }
103 zFile = g.argv[g.argc-1];
104 file_tree_name(zFile, &fname, 1);
105
106 blob_zero(&vname);
107 do{
108 blob_reset(&vname);
109 blob_appendf(&vname, "%s~%d", zFile, cnt++);
110
+7 -4
--- src/file.c
+++ src/file.c
@@ -317,23 +317,26 @@
317317
}
318318
319319
/*
320320
** Compute a pathname for a file relative to the root of the local
321321
** tree. Return TRUE on success. On failure, print and error
322
-** message and quit.
322
+** message and quit if the errFatal flag is true. If errFatal is
323
+** false, then simply return 0.
323324
**
324325
** The root of the tree is defined by the g.zLocalRoot variable.
325326
*/
326
-int file_tree_name(const char *zOrigName, Blob *pOut){
327
+int file_tree_name(const char *zOrigName, Blob *pOut, int errFatal){
327328
int n;
328329
Blob full;
329330
db_must_be_within_tree();
330331
file_canonical_name(zOrigName, &full);
331332
n = strlen(g.zLocalRoot);
332333
if( blob_size(&full)<=n || memcmp(g.zLocalRoot, blob_buffer(&full), n) ){
333334
blob_reset(&full);
334
- fossil_fatal("file outside of checkout tree: %s", zOrigName);
335
+ if( errFatal ){
336
+ fossil_fatal("file outside of checkout tree: %s", zOrigName);
337
+ }
335338
return 0;
336339
}
337340
blob_zero(pOut);
338341
blob_append(pOut, blob_buffer(&full)+n, blob_size(&full)-n);
339342
return 1;
@@ -347,11 +350,11 @@
347350
void cmd_test_tree_name(void){
348351
int i;
349352
Blob x;
350353
blob_zero(&x);
351354
for(i=2; i<g.argc; i++){
352
- if( file_tree_name(g.argv[i], &x) ){
355
+ if( file_tree_name(g.argv[i], &x, 1) ){
353356
printf("%s\n", blob_buffer(&x));
354357
blob_reset(&x);
355358
}
356359
}
357360
}
358361
--- src/file.c
+++ src/file.c
@@ -317,23 +317,26 @@
317 }
318
319 /*
320 ** Compute a pathname for a file relative to the root of the local
321 ** tree. Return TRUE on success. On failure, print and error
322 ** message and quit.
 
323 **
324 ** The root of the tree is defined by the g.zLocalRoot variable.
325 */
326 int file_tree_name(const char *zOrigName, Blob *pOut){
327 int n;
328 Blob full;
329 db_must_be_within_tree();
330 file_canonical_name(zOrigName, &full);
331 n = strlen(g.zLocalRoot);
332 if( blob_size(&full)<=n || memcmp(g.zLocalRoot, blob_buffer(&full), n) ){
333 blob_reset(&full);
334 fossil_fatal("file outside of checkout tree: %s", zOrigName);
 
 
335 return 0;
336 }
337 blob_zero(pOut);
338 blob_append(pOut, blob_buffer(&full)+n, blob_size(&full)-n);
339 return 1;
@@ -347,11 +350,11 @@
347 void cmd_test_tree_name(void){
348 int i;
349 Blob x;
350 blob_zero(&x);
351 for(i=2; i<g.argc; i++){
352 if( file_tree_name(g.argv[i], &x) ){
353 printf("%s\n", blob_buffer(&x));
354 blob_reset(&x);
355 }
356 }
357 }
358
--- src/file.c
+++ src/file.c
@@ -317,23 +317,26 @@
317 }
318
319 /*
320 ** Compute a pathname for a file relative to the root of the local
321 ** tree. Return TRUE on success. On failure, print and error
322 ** message and quit if the errFatal flag is true. If errFatal is
323 ** false, then simply return 0.
324 **
325 ** The root of the tree is defined by the g.zLocalRoot variable.
326 */
327 int file_tree_name(const char *zOrigName, Blob *pOut, int errFatal){
328 int n;
329 Blob full;
330 db_must_be_within_tree();
331 file_canonical_name(zOrigName, &full);
332 n = strlen(g.zLocalRoot);
333 if( blob_size(&full)<=n || memcmp(g.zLocalRoot, blob_buffer(&full), n) ){
334 blob_reset(&full);
335 if( errFatal ){
336 fossil_fatal("file outside of checkout tree: %s", zOrigName);
337 }
338 return 0;
339 }
340 blob_zero(pOut);
341 blob_append(pOut, blob_buffer(&full)+n, blob_size(&full)-n);
342 return 1;
@@ -347,11 +350,11 @@
350 void cmd_test_tree_name(void){
351 int i;
352 Blob x;
353 blob_zero(&x);
354 for(i=2; i<g.argc; i++){
355 if( file_tree_name(g.argv[i], &x, 1) ){
356 printf("%s\n", blob_buffer(&x));
357 blob_reset(&x);
358 }
359 }
360 }
361
+2 -2
--- src/undo.c
+++ src/undo.c
@@ -215,11 +215,11 @@
215215
fossil_fatal("no update or merge operation is available to undo");
216216
}
217217
for(i=2; i<g.argc; i++){
218218
const char *zFile = g.argv[i];
219219
Blob path;
220
- file_tree_name(zFile, &path);
220
+ file_tree_name(zFile, &path, 1);
221221
undo_one(blob_str(&path), 0);
222222
blob_reset(&path);
223223
}
224224
}
225225
db_end_transaction(0);
@@ -255,12 +255,12 @@
255255
fossil_fatal("no update or merge operation is available to redo");
256256
}
257257
for(i=2; i<g.argc; i++){
258258
const char *zFile = g.argv[i];
259259
Blob path;
260
- file_tree_name(zFile, &path);
260
+ file_tree_name(zFile, &path, 1);
261261
undo_one(blob_str(&path), 0);
262262
blob_reset(&path);
263263
}
264264
}
265265
db_end_transaction(0);
266266
}
267267
--- src/undo.c
+++ src/undo.c
@@ -215,11 +215,11 @@
215 fossil_fatal("no update or merge operation is available to undo");
216 }
217 for(i=2; i<g.argc; i++){
218 const char *zFile = g.argv[i];
219 Blob path;
220 file_tree_name(zFile, &path);
221 undo_one(blob_str(&path), 0);
222 blob_reset(&path);
223 }
224 }
225 db_end_transaction(0);
@@ -255,12 +255,12 @@
255 fossil_fatal("no update or merge operation is available to redo");
256 }
257 for(i=2; i<g.argc; i++){
258 const char *zFile = g.argv[i];
259 Blob path;
260 file_tree_name(zFile, &path);
261 undo_one(blob_str(&path), 0);
262 blob_reset(&path);
263 }
264 }
265 db_end_transaction(0);
266 }
267
--- src/undo.c
+++ src/undo.c
@@ -215,11 +215,11 @@
215 fossil_fatal("no update or merge operation is available to undo");
216 }
217 for(i=2; i<g.argc; i++){
218 const char *zFile = g.argv[i];
219 Blob path;
220 file_tree_name(zFile, &path, 1);
221 undo_one(blob_str(&path), 0);
222 blob_reset(&path);
223 }
224 }
225 db_end_transaction(0);
@@ -255,12 +255,12 @@
255 fossil_fatal("no update or merge operation is available to redo");
256 }
257 for(i=2; i<g.argc; i++){
258 const char *zFile = g.argv[i];
259 Blob path;
260 file_tree_name(zFile, &path, 1);
261 undo_one(blob_str(&path), 0);
262 blob_reset(&path);
263 }
264 }
265 db_end_transaction(0);
266 }
267
+1 -1
--- src/update.c
+++ src/update.c
@@ -297,11 +297,11 @@
297297
}
298298
db_must_be_within_tree();
299299
300300
zFile = mprintf("%/", g.argv[g.argc-1]);
301301
302
- file_tree_name(zFile, &fname);
302
+ file_tree_name(zFile, &fname, 1);
303303
304304
if( access(zFile, 0) ) yesRevert = 1;
305305
if( yesRevert==0 ){
306306
char *prompt = mprintf("revert file %B? this will"
307307
" destroy local changes [y/N]? ",
308308
--- src/update.c
+++ src/update.c
@@ -297,11 +297,11 @@
297 }
298 db_must_be_within_tree();
299
300 zFile = mprintf("%/", g.argv[g.argc-1]);
301
302 file_tree_name(zFile, &fname);
303
304 if( access(zFile, 0) ) yesRevert = 1;
305 if( yesRevert==0 ){
306 char *prompt = mprintf("revert file %B? this will"
307 " destroy local changes [y/N]? ",
308
--- src/update.c
+++ src/update.c
@@ -297,11 +297,11 @@
297 }
298 db_must_be_within_tree();
299
300 zFile = mprintf("%/", g.argv[g.argc-1]);
301
302 file_tree_name(zFile, &fname, 1);
303
304 if( access(zFile, 0) ) yesRevert = 1;
305 if( yesRevert==0 ){
306 char *prompt = mprintf("revert file %B? this will"
307 " destroy local changes [y/N]? ",
308

Keyboard Shortcuts

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