Fossil SCM

Deal with windows filename aliasing in the "all" command. Ticket [974618fe5a8]. Also display the home directory for windows users with the "info" command since the home directory is non-obvious in windows.

drh 2009-11-11 16:21 trunk
Commit d5695157d0caade4fc251dcfbeb1ac8e8602f672
+16 -3
--- src/allrepo.c
+++ src/allrepo.c
@@ -111,18 +111,22 @@
111111
fossil_fatal("\"all\" subcommand should be one of: "
112112
"list ls push pull rebuild sync");
113113
}
114114
zFossil = quoteFilename(g.argv[0]);
115115
nMissing = 0;
116
- db_prepare(&q, "SELECT substr(name, 6) FROM global_config"
117
- " WHERE substr(name, 1, 5)=='repo:' ORDER BY 1");
116
+ db_prepare(&q,
117
+ "SELECT DISTINCT substr(name, 6) COLLATE nocase"
118
+ " FROM global_config"
119
+ " WHERE substr(name, 1, 5)=='repo:' ORDER BY 1"
120
+ );
118121
while( db_step(&q)==SQLITE_ROW ){
119122
const char *zFilename = db_column_text(&q, 0);
120123
if( access(zFilename, 0) ){
121124
nMissing++;
122125
continue;
123126
}
127
+ if( !file_is_canonical(zFilename) ) nMissing++;
124128
if( zCmd[0]=='l' ){
125129
printf("%s\n", zFilename);
126130
continue;
127131
}
128132
zQFilename = quoteFilename(zFilename);
@@ -132,11 +136,11 @@
132136
portable_system(zSyscmd);
133137
free(zSyscmd);
134138
free(zQFilename);
135139
}
136140
137
- /* If any repositories hows names appear in the ~/.fossil file could not
141
+ /* If any repositories whose names appear in the ~/.fossil file could not
138142
** be found, remove those names from the ~/.fossil file.
139143
*/
140144
if( nMissing ){
141145
db_begin_transaction();
142146
db_reset(&q);
@@ -143,13 +147,22 @@
143147
while( db_step(&q)==SQLITE_ROW ){
144148
const char *zFilename = db_column_text(&q, 0);
145149
if( access(zFilename, 0) ){
146150
char *zRepo = mprintf("repo:%s", zFilename);
147151
db_unset(zRepo, 1);
152
+ free(zRepo);
153
+ }else if( !file_is_canonical(zFilename) ){
154
+ Blob cname;
155
+ char *zRepo = mprintf("repo:%s", zFilename);
156
+ db_unset(zRepo, 1);
157
+ free(zRepo);
158
+ file_canonical_name(zFilename, &cname);
159
+ zRepo = mprintf("repo:%s", blob_str(&cname));
160
+ db_set(zRepo, "1", 1);
148161
free(zRepo);
149162
}
150163
}
151164
db_reset(&q);
152165
db_end_transaction(0);
153166
}
154167
db_finalize(&q);
155168
}
156169
--- src/allrepo.c
+++ src/allrepo.c
@@ -111,18 +111,22 @@
111 fossil_fatal("\"all\" subcommand should be one of: "
112 "list ls push pull rebuild sync");
113 }
114 zFossil = quoteFilename(g.argv[0]);
115 nMissing = 0;
116 db_prepare(&q, "SELECT substr(name, 6) FROM global_config"
117 " WHERE substr(name, 1, 5)=='repo:' ORDER BY 1");
 
 
 
118 while( db_step(&q)==SQLITE_ROW ){
119 const char *zFilename = db_column_text(&q, 0);
120 if( access(zFilename, 0) ){
121 nMissing++;
122 continue;
123 }
 
124 if( zCmd[0]=='l' ){
125 printf("%s\n", zFilename);
126 continue;
127 }
128 zQFilename = quoteFilename(zFilename);
@@ -132,11 +136,11 @@
132 portable_system(zSyscmd);
133 free(zSyscmd);
134 free(zQFilename);
135 }
136
137 /* If any repositories hows names appear in the ~/.fossil file could not
138 ** be found, remove those names from the ~/.fossil file.
139 */
140 if( nMissing ){
141 db_begin_transaction();
142 db_reset(&q);
@@ -143,13 +147,22 @@
143 while( db_step(&q)==SQLITE_ROW ){
144 const char *zFilename = db_column_text(&q, 0);
145 if( access(zFilename, 0) ){
146 char *zRepo = mprintf("repo:%s", zFilename);
147 db_unset(zRepo, 1);
 
 
 
 
 
 
 
 
 
148 free(zRepo);
149 }
150 }
151 db_reset(&q);
152 db_end_transaction(0);
153 }
154 db_finalize(&q);
155 }
156
--- src/allrepo.c
+++ src/allrepo.c
@@ -111,18 +111,22 @@
111 fossil_fatal("\"all\" subcommand should be one of: "
112 "list ls push pull rebuild sync");
113 }
114 zFossil = quoteFilename(g.argv[0]);
115 nMissing = 0;
116 db_prepare(&q,
117 "SELECT DISTINCT substr(name, 6) COLLATE nocase"
118 " FROM global_config"
119 " WHERE substr(name, 1, 5)=='repo:' ORDER BY 1"
120 );
121 while( db_step(&q)==SQLITE_ROW ){
122 const char *zFilename = db_column_text(&q, 0);
123 if( access(zFilename, 0) ){
124 nMissing++;
125 continue;
126 }
127 if( !file_is_canonical(zFilename) ) nMissing++;
128 if( zCmd[0]=='l' ){
129 printf("%s\n", zFilename);
130 continue;
131 }
132 zQFilename = quoteFilename(zFilename);
@@ -132,11 +136,11 @@
136 portable_system(zSyscmd);
137 free(zSyscmd);
138 free(zQFilename);
139 }
140
141 /* If any repositories whose names appear in the ~/.fossil file could not
142 ** be found, remove those names from the ~/.fossil file.
143 */
144 if( nMissing ){
145 db_begin_transaction();
146 db_reset(&q);
@@ -143,13 +147,22 @@
147 while( db_step(&q)==SQLITE_ROW ){
148 const char *zFilename = db_column_text(&q, 0);
149 if( access(zFilename, 0) ){
150 char *zRepo = mprintf("repo:%s", zFilename);
151 db_unset(zRepo, 1);
152 free(zRepo);
153 }else if( !file_is_canonical(zFilename) ){
154 Blob cname;
155 char *zRepo = mprintf("repo:%s", zFilename);
156 db_unset(zRepo, 1);
157 free(zRepo);
158 file_canonical_name(zFilename, &cname);
159 zRepo = mprintf("repo:%s", blob_str(&cname));
160 db_set(zRepo, "1", 1);
161 free(zRepo);
162 }
163 }
164 db_reset(&q);
165 db_end_transaction(0);
166 }
167 db_finalize(&q);
168 }
169
+1
--- src/db.c
+++ src/db.c
@@ -701,10 +701,11 @@
701701
if( zHome==0 ){
702702
db_err("cannot locate home directory - "
703703
"please set the HOME environment variable");
704704
}
705705
#endif
706
+ g.zHome = mprintf("%/", zHome);
706707
#ifdef __MINGW32__
707708
/* . filenames give some window systems problems and many apps problems */
708709
zDbName = mprintf("%//_fossil", zHome);
709710
#else
710711
zDbName = mprintf("%s/.fossil", zHome);
711712
--- src/db.c
+++ src/db.c
@@ -701,10 +701,11 @@
701 if( zHome==0 ){
702 db_err("cannot locate home directory - "
703 "please set the HOME environment variable");
704 }
705 #endif
 
706 #ifdef __MINGW32__
707 /* . filenames give some window systems problems and many apps problems */
708 zDbName = mprintf("%//_fossil", zHome);
709 #else
710 zDbName = mprintf("%s/.fossil", zHome);
711
--- src/db.c
+++ src/db.c
@@ -701,10 +701,11 @@
701 if( zHome==0 ){
702 db_err("cannot locate home directory - "
703 "please set the HOME environment variable");
704 }
705 #endif
706 g.zHome = mprintf("%/", zHome);
707 #ifdef __MINGW32__
708 /* . filenames give some window systems problems and many apps problems */
709 zDbName = mprintf("%//_fossil", zHome);
710 #else
711 zDbName = mprintf("%s/.fossil", zHome);
712
+31
--- src/file.c
+++ src/file.c
@@ -213,10 +213,15 @@
213213
**
214214
** Changes are made in-place. Return the new name length.
215215
*/
216216
int file_simplify_name(char *z, int n){
217217
int i, j;
218
+#ifdef __MINGW32__
219
+ for(i=0; i<n; i++){
220
+ if( z[i]=='\\' ) z[i] = '/';
221
+ }
222
+#endif
218223
while( n>1 && z[n-1]=='/' ){ n--; }
219224
for(i=j=0; i<n; i++){
220225
if( z[i]=='/' ){
221226
if( z[i+1]=='/' ) continue;
222227
if( z[i+1]=='.' && i+2<n && z[i+2]=='/' ){
@@ -278,10 +283,36 @@
278283
file_canonical_name(g.argv[i], &x);
279284
printf("%s\n", blob_buffer(&x));
280285
blob_reset(&x);
281286
}
282287
}
288
+
289
+/*
290
+** Return TRUE if the given filename is canonical.
291
+**
292
+** Canonical names are full pathnames using "/" not "\" and which
293
+** contain no "/./" or "/../" terms.
294
+*/
295
+int file_is_canonical(const char *z){
296
+ int i;
297
+ if( z[0]!='/'
298
+#ifdef __MINGW32__
299
+ && (z[0]==0 || z[1]!=':' || z[2]!='/')
300
+#endif
301
+ ) return 0;
302
+
303
+ for(i=0; z[i]; i++){
304
+ if( z[i]=='\\' ) return 0;
305
+ if( z[i]=='/' ){
306
+ if( z[i+1]=='.' ){
307
+ if( z[i+2]=='/' || z[i+2]==0 ) return 0;
308
+ if( z[i+2]=='.' && (z[i+3]=='/' || z[i+3]==0) ) return 0;
309
+ }
310
+ }
311
+ }
312
+ return 1;
313
+}
283314
284315
/*
285316
** Compute a pathname for a file or directory that is relative
286317
** to the current directory.
287318
*/
288319
--- src/file.c
+++ src/file.c
@@ -213,10 +213,15 @@
213 **
214 ** Changes are made in-place. Return the new name length.
215 */
216 int file_simplify_name(char *z, int n){
217 int i, j;
 
 
 
 
 
218 while( n>1 && z[n-1]=='/' ){ n--; }
219 for(i=j=0; i<n; i++){
220 if( z[i]=='/' ){
221 if( z[i+1]=='/' ) continue;
222 if( z[i+1]=='.' && i+2<n && z[i+2]=='/' ){
@@ -278,10 +283,36 @@
278 file_canonical_name(g.argv[i], &x);
279 printf("%s\n", blob_buffer(&x));
280 blob_reset(&x);
281 }
282 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
284 /*
285 ** Compute a pathname for a file or directory that is relative
286 ** to the current directory.
287 */
288
--- src/file.c
+++ src/file.c
@@ -213,10 +213,15 @@
213 **
214 ** Changes are made in-place. Return the new name length.
215 */
216 int file_simplify_name(char *z, int n){
217 int i, j;
218 #ifdef __MINGW32__
219 for(i=0; i<n; i++){
220 if( z[i]=='\\' ) z[i] = '/';
221 }
222 #endif
223 while( n>1 && z[n-1]=='/' ){ n--; }
224 for(i=j=0; i<n; i++){
225 if( z[i]=='/' ){
226 if( z[i+1]=='/' ) continue;
227 if( z[i+1]=='.' && i+2<n && z[i+2]=='/' ){
@@ -278,10 +283,36 @@
283 file_canonical_name(g.argv[i], &x);
284 printf("%s\n", blob_buffer(&x));
285 blob_reset(&x);
286 }
287 }
288
289 /*
290 ** Return TRUE if the given filename is canonical.
291 **
292 ** Canonical names are full pathnames using "/" not "\" and which
293 ** contain no "/./" or "/../" terms.
294 */
295 int file_is_canonical(const char *z){
296 int i;
297 if( z[0]!='/'
298 #ifdef __MINGW32__
299 && (z[0]==0 || z[1]!=':' || z[2]!='/')
300 #endif
301 ) return 0;
302
303 for(i=0; z[i]; i++){
304 if( z[i]=='\\' ) return 0;
305 if( z[i]=='/' ){
306 if( z[i+1]=='.' ){
307 if( z[i+2]=='/' || z[i+2]==0 ) return 0;
308 if( z[i+2]=='.' && (z[i+3]=='/' || z[i+3]==0) ) return 0;
309 }
310 }
311 }
312 return 1;
313 }
314
315 /*
316 ** Compute a pathname for a file or directory that is relative
317 ** to the current directory.
318 */
319
+5
--- src/info.c
+++ src/info.c
@@ -127,10 +127,15 @@
127127
/* 012345678901234 */
128128
db_record_repository_filename(0);
129129
printf("project-name: %s\n", db_get("project-name", "<unnamed>"));
130130
printf("repository: %s\n", db_lget("repository", ""));
131131
printf("local-root: %s\n", g.zLocalRoot);
132
+#ifdef __MINGW32__
133
+ if( g.zHome ){
134
+ printf("user-home: : %s\n", g.zHome);
135
+ }
136
+#endif
132137
printf("project-code: %s\n", db_get("project-code", ""));
133138
printf("server-code: %s\n", db_get("server-code", ""));
134139
vid = db_lget_int("checkout", 0);
135140
if( vid==0 ){
136141
printf("checkout: nil\n");
137142
--- src/info.c
+++ src/info.c
@@ -127,10 +127,15 @@
127 /* 012345678901234 */
128 db_record_repository_filename(0);
129 printf("project-name: %s\n", db_get("project-name", "<unnamed>"));
130 printf("repository: %s\n", db_lget("repository", ""));
131 printf("local-root: %s\n", g.zLocalRoot);
 
 
 
 
 
132 printf("project-code: %s\n", db_get("project-code", ""));
133 printf("server-code: %s\n", db_get("server-code", ""));
134 vid = db_lget_int("checkout", 0);
135 if( vid==0 ){
136 printf("checkout: nil\n");
137
--- src/info.c
+++ src/info.c
@@ -127,10 +127,15 @@
127 /* 012345678901234 */
128 db_record_repository_filename(0);
129 printf("project-name: %s\n", db_get("project-name", "<unnamed>"));
130 printf("repository: %s\n", db_lget("repository", ""));
131 printf("local-root: %s\n", g.zLocalRoot);
132 #ifdef __MINGW32__
133 if( g.zHome ){
134 printf("user-home: : %s\n", g.zHome);
135 }
136 #endif
137 printf("project-code: %s\n", db_get("project-code", ""));
138 printf("server-code: %s\n", db_get("server-code", ""));
139 vid = db_lget_int("checkout", 0);
140 if( vid==0 ){
141 printf("checkout: nil\n");
142
+1
--- src/main.c
+++ src/main.c
@@ -61,10 +61,11 @@
6161
int useAttach; /* True if global_config is attached to repository */
6262
int configOpen; /* True if the config database is open */
6363
long long int now; /* Seconds since 1970 */
6464
int repositoryOpen; /* True if the main repository database is open */
6565
char *zRepositoryName; /* Name of the repository database */
66
+ const char *zHome; /* Name of user home directory */
6667
int localOpen; /* True if the local database is open */
6768
char *zLocalRoot; /* The directory holding the local database */
6869
int minPrefix; /* Number of digits needed for a distinct UUID */
6970
int fSqlTrace; /* True if -sqltrace flag is present */
7071
int fSqlPrint; /* True if -sqlprint flag is present */
7172
--- src/main.c
+++ src/main.c
@@ -61,10 +61,11 @@
61 int useAttach; /* True if global_config is attached to repository */
62 int configOpen; /* True if the config database is open */
63 long long int now; /* Seconds since 1970 */
64 int repositoryOpen; /* True if the main repository database is open */
65 char *zRepositoryName; /* Name of the repository database */
 
66 int localOpen; /* True if the local database is open */
67 char *zLocalRoot; /* The directory holding the local database */
68 int minPrefix; /* Number of digits needed for a distinct UUID */
69 int fSqlTrace; /* True if -sqltrace flag is present */
70 int fSqlPrint; /* True if -sqlprint flag is present */
71
--- src/main.c
+++ src/main.c
@@ -61,10 +61,11 @@
61 int useAttach; /* True if global_config is attached to repository */
62 int configOpen; /* True if the config database is open */
63 long long int now; /* Seconds since 1970 */
64 int repositoryOpen; /* True if the main repository database is open */
65 char *zRepositoryName; /* Name of the repository database */
66 const char *zHome; /* Name of user home directory */
67 int localOpen; /* True if the local database is open */
68 char *zLocalRoot; /* The directory holding the local database */
69 int minPrefix; /* Number of digits needed for a distinct UUID */
70 int fSqlTrace; /* True if -sqltrace flag is present */
71 int fSqlPrint; /* True if -sqlprint flag is present */
72

Keyboard Shortcuts

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