Fossil SCM
implemented th1 comman 'dir' similar to cli 'ls'
Commit
5d56fb7e2c184cd8fb654b7ac7b9a5721f7ba452
Parent
19503f888bec682…
2 files changed
+3
+86
+3
| --- src/doc.c | ||
| +++ src/doc.c | ||
| @@ -540,10 +540,13 @@ | ||
| 540 | 540 | Blob filebody; /* Content of the documentation file */ |
| 541 | 541 | Blob title; /* Document title */ |
| 542 | 542 | int nMiss = (-1); /* Failed attempts to find the document */ |
| 543 | 543 | static const char *const azSuffix[] = { |
| 544 | 544 | "index.html", "index.wiki", "index.md" |
| 545 | +#ifdef FOSSIL_ENABLE_TH1_DOCS | |
| 546 | + , "index.th1" | |
| 547 | +#endif | |
| 545 | 548 | }; |
| 546 | 549 | |
| 547 | 550 | login_check_credentials(); |
| 548 | 551 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 549 | 552 | blob_init(&title, 0, 0); |
| 550 | 553 |
| --- src/doc.c | |
| +++ src/doc.c | |
| @@ -540,10 +540,13 @@ | |
| 540 | Blob filebody; /* Content of the documentation file */ |
| 541 | Blob title; /* Document title */ |
| 542 | int nMiss = (-1); /* Failed attempts to find the document */ |
| 543 | static const char *const azSuffix[] = { |
| 544 | "index.html", "index.wiki", "index.md" |
| 545 | }; |
| 546 | |
| 547 | login_check_credentials(); |
| 548 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 549 | blob_init(&title, 0, 0); |
| 550 |
| --- src/doc.c | |
| +++ src/doc.c | |
| @@ -540,10 +540,13 @@ | |
| 540 | Blob filebody; /* Content of the documentation file */ |
| 541 | Blob title; /* Document title */ |
| 542 | int nMiss = (-1); /* Failed attempts to find the document */ |
| 543 | static const char *const azSuffix[] = { |
| 544 | "index.html", "index.wiki", "index.md" |
| 545 | #ifdef FOSSIL_ENABLE_TH1_DOCS |
| 546 | , "index.th1" |
| 547 | #endif |
| 548 | }; |
| 549 | |
| 550 | login_check_credentials(); |
| 551 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 552 | blob_init(&title, 0, 0); |
| 553 |
+86
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -143,10 +143,95 @@ | ||
| 143 | 143 | fossil_print("%s", blob_str(&g.thLog)); |
| 144 | 144 | fossil_print("\n------------------- END TRACE LOG -------------------\n"); |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | + | |
| 149 | +/* | |
| 150 | +** - adopted from ls_cmd_rev in checkin.c | |
| 151 | +** - adopted commands/error handling for usage within th1 | |
| 152 | +** - interface adopted to allow result creation as TH1 List | |
| 153 | +** | |
| 154 | +** Takes a checkin identifier in zRev and an optiona glob pattern in zGLOB | |
| 155 | +** as parameter returns a TH list in pzList,pnList with filenames matching | |
| 156 | +** glob pattern with the checking | |
| 157 | +*/ | |
| 158 | +static void dir_cmd_rev( | |
| 159 | + Th_Interp *interp, | |
| 160 | + char** pzList, | |
| 161 | + int* pnList, | |
| 162 | + const char *zRev, /* Revision string given */ | |
| 163 | + const char* zGlob /* */ | |
| 164 | +){ | |
| 165 | + Stmt q; | |
| 166 | + char *zOrderBy = "pathname COLLATE nocase"; | |
| 167 | + char *zName; | |
| 168 | + int rid; | |
| 169 | + int i; | |
| 170 | + | |
| 171 | + rid = th1_name_to_typed_rid(interp, zRev, "ci"); | |
| 172 | + | |
| 173 | + compute_fileage(rid, zGlob); | |
| 174 | + db_prepare(&q, | |
| 175 | + "SELECT datetime(fileage.mtime, 'localtime'), fileage.pathname,\n" | |
| 176 | + " blob.size\n" | |
| 177 | + " FROM fileage, blob\n" | |
| 178 | + " WHERE blob.rid=fileage.fid \n" | |
| 179 | + " ORDER BY %s;", zOrderBy /*safe-for-%s*/ | |
| 180 | + ); | |
| 181 | + | |
| 182 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 183 | + const char *zTime = db_column_text(&q,0); | |
| 184 | + const char *zFile = db_column_text(&q,1); | |
| 185 | + int size = db_column_int(&q,2); | |
| 186 | + | |
| 187 | + Th_ListAppend(interp, pzList, pnList, zFile, -1); | |
| 188 | + //fossil_print("%s\n", zFile); | |
| 189 | + } | |
| 190 | + db_finalize(&q); | |
| 191 | +} | |
| 192 | + | |
| 193 | +/* | |
| 194 | +** TH1 command: dir CHECKIN ?GLOB? | |
| 195 | +** | |
| 196 | +** Returns a list containing all files in CHECKIN. If GLOB is given | |
| 197 | +** only the files matching the pattern GLOB within CHECKIN will be returned. | |
| 198 | +*/ | |
| 199 | +static int dirCmd( | |
| 200 | + Th_Interp *interp, | |
| 201 | + void *ctx, | |
| 202 | + int argc, | |
| 203 | + const char **argv, | |
| 204 | + int *argl | |
| 205 | +){ | |
| 206 | + const char *zGlob = 0; | |
| 207 | + char *zList = 0; | |
| 208 | + int nList = 0; | |
| 209 | + int i; | |
| 210 | + | |
| 211 | + if( argc!=2 && argc != 3){ | |
| 212 | + return Th_WrongNumArgs(interp, "dir CHECKIN ?GLOB?"); | |
| 213 | + } | |
| 214 | + | |
| 215 | + if( argc == 3){ | |
| 216 | + zGlob = argv[2]; | |
| 217 | + } | |
| 218 | + | |
| 219 | + if( Th_IsRepositoryOpen() ){ | |
| 220 | + dir_cmd_rev(interp, &zList, &nList, argv[1], zGlob); | |
| 221 | + | |
| 222 | + Th_SetResult(interp, zList, nList); | |
| 223 | + Th_Free(interp, zList); | |
| 224 | + | |
| 225 | + return TH_OK; | |
| 226 | + | |
| 227 | + } else { | |
| 228 | + Th_SetResult(interp, "repository unavailable", -1); | |
| 229 | + return TH_ERROR; | |
| 230 | + } | |
| 231 | +} | |
| 232 | + | |
| 148 | 233 | /* |
| 149 | 234 | ** TH1 command: httpize STRING |
| 150 | 235 | ** |
| 151 | 236 | ** Escape all characters of STRING which have special meaning in URI |
| 152 | 237 | ** components. Return a new string result. |
| @@ -1632,10 +1717,11 @@ | ||
| 1632 | 1717 | {"artifact", artifactCmd, 0}, |
| 1633 | 1718 | {"checkout", checkoutCmd, 0}, |
| 1634 | 1719 | {"combobox", comboboxCmd, 0}, |
| 1635 | 1720 | {"date", dateCmd, 0}, |
| 1636 | 1721 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 1722 | + {"dir", dirCmd, 0}, | |
| 1637 | 1723 | {"enable_output", enableOutputCmd, 0}, |
| 1638 | 1724 | {"getParameter", getParameterCmd, 0}, |
| 1639 | 1725 | {"glob_match", globMatchCmd, 0}, |
| 1640 | 1726 | {"globalState", globalStateCmd, 0}, |
| 1641 | 1727 | {"httpize", httpizeCmd, 0}, |
| 1642 | 1728 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -143,10 +143,95 @@ | |
| 143 | fossil_print("%s", blob_str(&g.thLog)); |
| 144 | fossil_print("\n------------------- END TRACE LOG -------------------\n"); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | ** TH1 command: httpize STRING |
| 150 | ** |
| 151 | ** Escape all characters of STRING which have special meaning in URI |
| 152 | ** components. Return a new string result. |
| @@ -1632,10 +1717,11 @@ | |
| 1632 | {"artifact", artifactCmd, 0}, |
| 1633 | {"checkout", checkoutCmd, 0}, |
| 1634 | {"combobox", comboboxCmd, 0}, |
| 1635 | {"date", dateCmd, 0}, |
| 1636 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 1637 | {"enable_output", enableOutputCmd, 0}, |
| 1638 | {"getParameter", getParameterCmd, 0}, |
| 1639 | {"glob_match", globMatchCmd, 0}, |
| 1640 | {"globalState", globalStateCmd, 0}, |
| 1641 | {"httpize", httpizeCmd, 0}, |
| 1642 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -143,10 +143,95 @@ | |
| 143 | fossil_print("%s", blob_str(&g.thLog)); |
| 144 | fossil_print("\n------------------- END TRACE LOG -------------------\n"); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | |
| 149 | /* |
| 150 | ** - adopted from ls_cmd_rev in checkin.c |
| 151 | ** - adopted commands/error handling for usage within th1 |
| 152 | ** - interface adopted to allow result creation as TH1 List |
| 153 | ** |
| 154 | ** Takes a checkin identifier in zRev and an optiona glob pattern in zGLOB |
| 155 | ** as parameter returns a TH list in pzList,pnList with filenames matching |
| 156 | ** glob pattern with the checking |
| 157 | */ |
| 158 | static void dir_cmd_rev( |
| 159 | Th_Interp *interp, |
| 160 | char** pzList, |
| 161 | int* pnList, |
| 162 | const char *zRev, /* Revision string given */ |
| 163 | const char* zGlob /* */ |
| 164 | ){ |
| 165 | Stmt q; |
| 166 | char *zOrderBy = "pathname COLLATE nocase"; |
| 167 | char *zName; |
| 168 | int rid; |
| 169 | int i; |
| 170 | |
| 171 | rid = th1_name_to_typed_rid(interp, zRev, "ci"); |
| 172 | |
| 173 | compute_fileage(rid, zGlob); |
| 174 | db_prepare(&q, |
| 175 | "SELECT datetime(fileage.mtime, 'localtime'), fileage.pathname,\n" |
| 176 | " blob.size\n" |
| 177 | " FROM fileage, blob\n" |
| 178 | " WHERE blob.rid=fileage.fid \n" |
| 179 | " ORDER BY %s;", zOrderBy /*safe-for-%s*/ |
| 180 | ); |
| 181 | |
| 182 | while( db_step(&q)==SQLITE_ROW ){ |
| 183 | const char *zTime = db_column_text(&q,0); |
| 184 | const char *zFile = db_column_text(&q,1); |
| 185 | int size = db_column_int(&q,2); |
| 186 | |
| 187 | Th_ListAppend(interp, pzList, pnList, zFile, -1); |
| 188 | //fossil_print("%s\n", zFile); |
| 189 | } |
| 190 | db_finalize(&q); |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | ** TH1 command: dir CHECKIN ?GLOB? |
| 195 | ** |
| 196 | ** Returns a list containing all files in CHECKIN. If GLOB is given |
| 197 | ** only the files matching the pattern GLOB within CHECKIN will be returned. |
| 198 | */ |
| 199 | static int dirCmd( |
| 200 | Th_Interp *interp, |
| 201 | void *ctx, |
| 202 | int argc, |
| 203 | const char **argv, |
| 204 | int *argl |
| 205 | ){ |
| 206 | const char *zGlob = 0; |
| 207 | char *zList = 0; |
| 208 | int nList = 0; |
| 209 | int i; |
| 210 | |
| 211 | if( argc!=2 && argc != 3){ |
| 212 | return Th_WrongNumArgs(interp, "dir CHECKIN ?GLOB?"); |
| 213 | } |
| 214 | |
| 215 | if( argc == 3){ |
| 216 | zGlob = argv[2]; |
| 217 | } |
| 218 | |
| 219 | if( Th_IsRepositoryOpen() ){ |
| 220 | dir_cmd_rev(interp, &zList, &nList, argv[1], zGlob); |
| 221 | |
| 222 | Th_SetResult(interp, zList, nList); |
| 223 | Th_Free(interp, zList); |
| 224 | |
| 225 | return TH_OK; |
| 226 | |
| 227 | } else { |
| 228 | Th_SetResult(interp, "repository unavailable", -1); |
| 229 | return TH_ERROR; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | ** TH1 command: httpize STRING |
| 235 | ** |
| 236 | ** Escape all characters of STRING which have special meaning in URI |
| 237 | ** components. Return a new string result. |
| @@ -1632,10 +1717,11 @@ | |
| 1717 | {"artifact", artifactCmd, 0}, |
| 1718 | {"checkout", checkoutCmd, 0}, |
| 1719 | {"combobox", comboboxCmd, 0}, |
| 1720 | {"date", dateCmd, 0}, |
| 1721 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 1722 | {"dir", dirCmd, 0}, |
| 1723 | {"enable_output", enableOutputCmd, 0}, |
| 1724 | {"getParameter", getParameterCmd, 0}, |
| 1725 | {"glob_match", globMatchCmd, 0}, |
| 1726 | {"globalState", globalStateCmd, 0}, |
| 1727 | {"httpize", httpizeCmd, 0}, |
| 1728 |