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.
Commit
d5695157d0caade4fc251dcfbeb1ac8e8602f672
Parent
0690aa18a4aa3df…
5 files changed
+16
-3
+1
+31
+5
+1
+16
-3
| --- src/allrepo.c | ||
| +++ src/allrepo.c | ||
| @@ -111,18 +111,22 @@ | ||
| 111 | 111 | fossil_fatal("\"all\" subcommand should be one of: " |
| 112 | 112 | "list ls push pull rebuild sync"); |
| 113 | 113 | } |
| 114 | 114 | zFossil = quoteFilename(g.argv[0]); |
| 115 | 115 | 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 | + ); | |
| 118 | 121 | while( db_step(&q)==SQLITE_ROW ){ |
| 119 | 122 | const char *zFilename = db_column_text(&q, 0); |
| 120 | 123 | if( access(zFilename, 0) ){ |
| 121 | 124 | nMissing++; |
| 122 | 125 | continue; |
| 123 | 126 | } |
| 127 | + if( !file_is_canonical(zFilename) ) nMissing++; | |
| 124 | 128 | if( zCmd[0]=='l' ){ |
| 125 | 129 | printf("%s\n", zFilename); |
| 126 | 130 | continue; |
| 127 | 131 | } |
| 128 | 132 | zQFilename = quoteFilename(zFilename); |
| @@ -132,11 +136,11 @@ | ||
| 132 | 136 | portable_system(zSyscmd); |
| 133 | 137 | free(zSyscmd); |
| 134 | 138 | free(zQFilename); |
| 135 | 139 | } |
| 136 | 140 | |
| 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 | |
| 138 | 142 | ** be found, remove those names from the ~/.fossil file. |
| 139 | 143 | */ |
| 140 | 144 | if( nMissing ){ |
| 141 | 145 | db_begin_transaction(); |
| 142 | 146 | db_reset(&q); |
| @@ -143,13 +147,22 @@ | ||
| 143 | 147 | while( db_step(&q)==SQLITE_ROW ){ |
| 144 | 148 | const char *zFilename = db_column_text(&q, 0); |
| 145 | 149 | if( access(zFilename, 0) ){ |
| 146 | 150 | char *zRepo = mprintf("repo:%s", zFilename); |
| 147 | 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); | |
| 148 | 161 | free(zRepo); |
| 149 | 162 | } |
| 150 | 163 | } |
| 151 | 164 | db_reset(&q); |
| 152 | 165 | db_end_transaction(0); |
| 153 | 166 | } |
| 154 | 167 | db_finalize(&q); |
| 155 | 168 | } |
| 156 | 169 |
| --- 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 |
M
src/db.c
+1
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -701,10 +701,11 @@ | ||
| 701 | 701 | if( zHome==0 ){ |
| 702 | 702 | db_err("cannot locate home directory - " |
| 703 | 703 | "please set the HOME environment variable"); |
| 704 | 704 | } |
| 705 | 705 | #endif |
| 706 | + g.zHome = mprintf("%/", zHome); | |
| 706 | 707 | #ifdef __MINGW32__ |
| 707 | 708 | /* . filenames give some window systems problems and many apps problems */ |
| 708 | 709 | zDbName = mprintf("%//_fossil", zHome); |
| 709 | 710 | #else |
| 710 | 711 | zDbName = mprintf("%s/.fossil", zHome); |
| 711 | 712 |
| --- 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 @@ | ||
| 213 | 213 | ** |
| 214 | 214 | ** Changes are made in-place. Return the new name length. |
| 215 | 215 | */ |
| 216 | 216 | int file_simplify_name(char *z, int n){ |
| 217 | 217 | int i, j; |
| 218 | +#ifdef __MINGW32__ | |
| 219 | + for(i=0; i<n; i++){ | |
| 220 | + if( z[i]=='\\' ) z[i] = '/'; | |
| 221 | + } | |
| 222 | +#endif | |
| 218 | 223 | while( n>1 && z[n-1]=='/' ){ n--; } |
| 219 | 224 | for(i=j=0; i<n; i++){ |
| 220 | 225 | if( z[i]=='/' ){ |
| 221 | 226 | if( z[i+1]=='/' ) continue; |
| 222 | 227 | if( z[i+1]=='.' && i+2<n && z[i+2]=='/' ){ |
| @@ -278,10 +283,36 @@ | ||
| 278 | 283 | file_canonical_name(g.argv[i], &x); |
| 279 | 284 | printf("%s\n", blob_buffer(&x)); |
| 280 | 285 | blob_reset(&x); |
| 281 | 286 | } |
| 282 | 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 | +} | |
| 283 | 314 | |
| 284 | 315 | /* |
| 285 | 316 | ** Compute a pathname for a file or directory that is relative |
| 286 | 317 | ** to the current directory. |
| 287 | 318 | */ |
| 288 | 319 |
| --- 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 @@ | ||
| 127 | 127 | /* 012345678901234 */ |
| 128 | 128 | db_record_repository_filename(0); |
| 129 | 129 | printf("project-name: %s\n", db_get("project-name", "<unnamed>")); |
| 130 | 130 | printf("repository: %s\n", db_lget("repository", "")); |
| 131 | 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 | |
| 132 | 137 | printf("project-code: %s\n", db_get("project-code", "")); |
| 133 | 138 | printf("server-code: %s\n", db_get("server-code", "")); |
| 134 | 139 | vid = db_lget_int("checkout", 0); |
| 135 | 140 | if( vid==0 ){ |
| 136 | 141 | printf("checkout: nil\n"); |
| 137 | 142 |
| --- 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 @@ | ||
| 61 | 61 | int useAttach; /* True if global_config is attached to repository */ |
| 62 | 62 | int configOpen; /* True if the config database is open */ |
| 63 | 63 | long long int now; /* Seconds since 1970 */ |
| 64 | 64 | int repositoryOpen; /* True if the main repository database is open */ |
| 65 | 65 | char *zRepositoryName; /* Name of the repository database */ |
| 66 | + const char *zHome; /* Name of user home directory */ | |
| 66 | 67 | int localOpen; /* True if the local database is open */ |
| 67 | 68 | char *zLocalRoot; /* The directory holding the local database */ |
| 68 | 69 | int minPrefix; /* Number of digits needed for a distinct UUID */ |
| 69 | 70 | int fSqlTrace; /* True if -sqltrace flag is present */ |
| 70 | 71 | int fSqlPrint; /* True if -sqlprint flag is present */ |
| 71 | 72 |
| --- 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 |