| | @@ -142,10 +142,103 @@ |
| 142 | 142 | fossil_print("\n------------------ BEGIN TRACE LOG ------------------\n"); |
| 143 | 143 | fossil_print("%s", blob_str(&g.thLog)); |
| 144 | 144 | fossil_print("\n------------------- END TRACE LOG -------------------\n"); |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | + |
| 148 | +/* |
| 149 | +** - adopted from ls_cmd_rev in checkin.c |
| 150 | +** - adopted commands/error handling for usage within th1 |
| 151 | +** - interface adopted to allow result creation as TH1 List |
| 152 | +** |
| 153 | +** Takes a checkin identifier in zRev and an optiona glob pattern in zGLOB |
| 154 | +** as parameter returns a TH list in pzList,pnList with filenames matching |
| 155 | +** glob pattern with the checking |
| 156 | +*/ |
| 157 | +static void dir_cmd_rev( |
| 158 | + Th_Interp *interp, |
| 159 | + char **pzList, |
| 160 | + int *pnList, |
| 161 | + const char *zRev, /* Revision string given */ |
| 162 | + const char *zGlob, /* Glob pattern given */ |
| 163 | + int bDetails |
| 164 | +){ |
| 165 | + Stmt q; |
| 166 | + char *zOrderBy = "pathname COLLATE nocase"; |
| 167 | + int rid; |
| 168 | + |
| 169 | + rid = th1_name_to_typed_rid(interp, zRev, "ci"); |
| 170 | + compute_fileage(rid, zGlob); |
| 171 | + db_prepare(&q, |
| 172 | + "SELECT datetime(fileage.mtime, 'localtime'), fileage.pathname,\n" |
| 173 | + " blob.size\n" |
| 174 | + " FROM fileage, blob\n" |
| 175 | + " WHERE blob.rid=fileage.fid \n" |
| 176 | + " ORDER BY %s;", zOrderBy /*safe-for-%s*/ |
| 177 | + ); |
| 178 | + while( db_step(&q)==SQLITE_ROW ){ |
| 179 | + const char *zFile = db_column_text(&q, 1); |
| 180 | + if( bDetails ){ |
| 181 | + const char *zTime = db_column_text(&q, 0); |
| 182 | + int size = db_column_int(&q, 2); |
| 183 | + char zSize[50]; |
| 184 | + char *zSubList = 0; |
| 185 | + int nSubList = 0; |
| 186 | + sqlite3_snprintf(sizeof(zSize), zSize, "%d", size); |
| 187 | + Th_ListAppend(interp, &zSubList, &nSubList, zFile, -1); |
| 188 | + Th_ListAppend(interp, &zSubList, &nSubList, zSize, -1); |
| 189 | + Th_ListAppend(interp, &zSubList, &nSubList, zTime, -1); |
| 190 | + Th_ListAppend(interp, pzList, pnList, zSubList, -1); |
| 191 | + Th_Free(interp, zSubList); |
| 192 | + }else{ |
| 193 | + Th_ListAppend(interp, pzList, pnList, zFile, -1); |
| 194 | + } |
| 195 | + } |
| 196 | + db_finalize(&q); |
| 197 | +} |
| 198 | + |
| 199 | +/* |
| 200 | +** TH1 command: dir CHECKIN ?GLOB? ?DETAILS? |
| 201 | +** |
| 202 | +** Returns a list containing all files in CHECKIN. If GLOB is given only |
| 203 | +** the files matching the pattern GLOB within CHECKIN will be returned. |
| 204 | +** If DETAILS is non-zero, the result will be a list-of-lists, with each |
| 205 | +** element containing at least three elements: the file name, the file |
| 206 | +** size (in bytes), and the file last modification time (relative to the |
| 207 | +** time zone configured for the repository). |
| 208 | +*/ |
| 209 | +static int dirCmd( |
| 210 | + Th_Interp *interp, |
| 211 | + void *ctx, |
| 212 | + int argc, |
| 213 | + const char **argv, |
| 214 | + int *argl |
| 215 | +){ |
| 216 | + const char *zGlob = 0; |
| 217 | + int bDetails = 0; |
| 218 | + |
| 219 | + if( argc<2 || argc>4 ){ |
| 220 | + return Th_WrongNumArgs(interp, "dir CHECKIN ?GLOB? ?DETAILS?"); |
| 221 | + } |
| 222 | + if( argc>=3 ){ |
| 223 | + zGlob = argv[2]; |
| 224 | + } |
| 225 | + if( argc>=4 && Th_ToInt(interp, argv[3], argl[3], &bDetails) ){ |
| 226 | + return TH_ERROR; |
| 227 | + } |
| 228 | + if( Th_IsRepositoryOpen() ){ |
| 229 | + char *zList = 0; |
| 230 | + int nList = 0; |
| 231 | + dir_cmd_rev(interp, &zList, &nList, argv[1], zGlob, bDetails); |
| 232 | + Th_SetResult(interp, zList, nList); |
| 233 | + Th_Free(interp, zList); |
| 234 | + return TH_OK; |
| 235 | + }else{ |
| 236 | + Th_SetResult(interp, "repository unavailable", -1); |
| 237 | + return TH_ERROR; |
| 238 | + } |
| 239 | +} |
| 147 | 240 | |
| 148 | 241 | /* |
| 149 | 242 | ** TH1 command: httpize STRING |
| 150 | 243 | ** |
| 151 | 244 | ** Escape all characters of STRING which have special meaning in URI |
| | @@ -1632,10 +1725,11 @@ |
| 1632 | 1725 | {"artifact", artifactCmd, 0}, |
| 1633 | 1726 | {"checkout", checkoutCmd, 0}, |
| 1634 | 1727 | {"combobox", comboboxCmd, 0}, |
| 1635 | 1728 | {"date", dateCmd, 0}, |
| 1636 | 1729 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 1730 | + {"dir", dirCmd, 0}, |
| 1637 | 1731 | {"enable_output", enableOutputCmd, 0}, |
| 1638 | 1732 | {"getParameter", getParameterCmd, 0}, |
| 1639 | 1733 | {"glob_match", globMatchCmd, 0}, |
| 1640 | 1734 | {"globalState", globalStateCmd, 0}, |
| 1641 | 1735 | {"httpize", httpizeCmd, 0}, |
| 1642 | 1736 | |
| 1643 | 1737 | ADDED test/th1-repo.test |