Fossil SCM

Add support for optional per-file details in the TH1 dir cmd, using a list-of-lists.

mistachkin 2015-08-18 07:49 ckol-th1-dir-cmd
Commit 83f50997bee18f1bb18a8677f51e24ce712ebe5c
+30 -7
--- src/th_main.c
+++ src/th_main.c
@@ -156,12 +156,13 @@
156156
*/
157157
static void dir_cmd_rev(
158158
Th_Interp *interp,
159159
char **pzList,
160160
int *pnList,
161
- const char *zRev, /* Revision string given */
162
- const char *zGlob /* Glob pattern given */
161
+ const char *zRev, /* Revision string given */
162
+ const char *zGlob, /* Glob pattern given */
163
+ int bDetails
163164
){
164165
Stmt q;
165166
char *zOrderBy = "pathname COLLATE nocase";
166167
int rid;
167168
@@ -174,40 +175,62 @@
174175
" WHERE blob.rid=fileage.fid \n"
175176
" ORDER BY %s;", zOrderBy /*safe-for-%s*/
176177
);
177178
while( db_step(&q)==SQLITE_ROW ){
178179
const char *zFile = db_column_text(&q, 1);
179
- Th_ListAppend(interp, pzList, pnList, zFile, -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
+ }
180195
}
181196
db_finalize(&q);
182197
}
183198
184199
/*
185
-** TH1 command: dir CHECKIN ?GLOB?
200
+** TH1 command: dir CHECKIN ?GLOB? ?DETAILS?
186201
**
187202
** Returns a list containing all files in CHECKIN. If GLOB is given only
188203
** 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).
189208
*/
190209
static int dirCmd(
191210
Th_Interp *interp,
192211
void *ctx,
193212
int argc,
194213
const char **argv,
195214
int *argl
196215
){
197216
const char *zGlob = 0;
217
+ int bDetails = 0;
198218
199
- if( argc!=2 && argc!=3 ){
219
+ if( argc<2 || argc>4 ){
200220
return Th_WrongNumArgs(interp, "dir CHECKIN ?GLOB?");
201221
}
202
- if( argc==3 ){
222
+ if( argc>=3 ){
203223
zGlob = argv[2];
224
+ }
225
+ if( argc>=4 && Th_ToInt(interp, argv[3], argl[3], &bDetails) ){
226
+ return TH_ERROR;
204227
}
205228
if( Th_IsRepositoryOpen() ){
206229
char *zList = 0;
207230
int nList = 0;
208
- dir_cmd_rev(interp, &zList, &nList, argv[1], zGlob);
231
+ dir_cmd_rev(interp, &zList, &nList, argv[1], zGlob, bDetails);
209232
Th_SetResult(interp, zList, nList);
210233
Th_Free(interp, zList);
211234
return TH_OK;
212235
}else{
213236
Th_SetResult(interp, "repository unavailable", -1);
214237
--- src/th_main.c
+++ src/th_main.c
@@ -156,12 +156,13 @@
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 ){
164 Stmt q;
165 char *zOrderBy = "pathname COLLATE nocase";
166 int rid;
167
@@ -174,40 +175,62 @@
174 " WHERE blob.rid=fileage.fid \n"
175 " ORDER BY %s;", zOrderBy /*safe-for-%s*/
176 );
177 while( db_step(&q)==SQLITE_ROW ){
178 const char *zFile = db_column_text(&q, 1);
179 Th_ListAppend(interp, pzList, pnList, zFile, -1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180 }
181 db_finalize(&q);
182 }
183
184 /*
185 ** TH1 command: dir CHECKIN ?GLOB?
186 **
187 ** Returns a list containing all files in CHECKIN. If GLOB is given only
188 ** the files matching the pattern GLOB within CHECKIN will be returned.
 
 
 
 
189 */
190 static int dirCmd(
191 Th_Interp *interp,
192 void *ctx,
193 int argc,
194 const char **argv,
195 int *argl
196 ){
197 const char *zGlob = 0;
 
198
199 if( argc!=2 && argc!=3 ){
200 return Th_WrongNumArgs(interp, "dir CHECKIN ?GLOB?");
201 }
202 if( argc==3 ){
203 zGlob = argv[2];
 
 
 
204 }
205 if( Th_IsRepositoryOpen() ){
206 char *zList = 0;
207 int nList = 0;
208 dir_cmd_rev(interp, &zList, &nList, argv[1], zGlob);
209 Th_SetResult(interp, zList, nList);
210 Th_Free(interp, zList);
211 return TH_OK;
212 }else{
213 Th_SetResult(interp, "repository unavailable", -1);
214
--- src/th_main.c
+++ src/th_main.c
@@ -156,12 +156,13 @@
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
@@ -174,40 +175,62 @@
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?");
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
--- test/th1-repo.test
+++ test/th1-repo.test
@@ -64,12 +64,27 @@
6464
###############################################################################
6565
6666
fossil test-th-eval --open-config "dir trunk subdir*/*.md"
6767
test th1-dir-1 {[llength $RESULT] eq [llength $files_md]}
6868
69
-###############################################################################
70
-
7169
set n 1
7270
foreach i $RESULT j $files_md {
7371
test th1-dir-2.$n {$i eq $j}
7472
set n [expr {$n + 1}]
7573
}
74
+
75
+###############################################################################
76
+
77
+set dateTime {\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}}
78
+fossil test-th-eval --open-config "dir trunk subdir*/*.md 1"
79
+test th1-dir-3.1 {[lindex [lindex $RESULT 0] 0] eq "subdirB/f5.md"}
80
+test th1-dir-3.2 {[lindex [lindex $RESULT 0] 1] == 2}
81
+test th1-dir-3.3 {[regexp -- $dateTime [lindex [lindex $RESULT 0] 2]]}
82
+test th1-dir-3.4 {[lindex [lindex $RESULT 1] 0] eq "subdirB/f6.md"}
83
+test th1-dir-3.5 {[lindex [lindex $RESULT 1] 1] == 2}
84
+test th1-dir-3.6 {[regexp -- $dateTime [lindex [lindex $RESULT 1] 2]]}
85
+test th1-dir-3.7 {[lindex [lindex $RESULT 2] 0] eq "subdirB/f8.md"}
86
+test th1-dir-3.8 {[lindex [lindex $RESULT 2] 1] == 2}
87
+test th1-dir-3.9 {[regexp -- $dateTime [lindex [lindex $RESULT 2] 2]]}
88
+test th1-dir-3.10 {[lindex [lindex $RESULT 3] 0] eq "subdirC/f10.md"}
89
+test th1-dir-3.11 {[lindex [lindex $RESULT 3] 1] == 3}
90
+test th1-dir-3.12 {[regexp -- $dateTime [lindex [lindex $RESULT 3] 2]]}
7691
--- test/th1-repo.test
+++ test/th1-repo.test
@@ -64,12 +64,27 @@
64 ###############################################################################
65
66 fossil test-th-eval --open-config "dir trunk subdir*/*.md"
67 test th1-dir-1 {[llength $RESULT] eq [llength $files_md]}
68
69 ###############################################################################
70
71 set n 1
72 foreach i $RESULT j $files_md {
73 test th1-dir-2.$n {$i eq $j}
74 set n [expr {$n + 1}]
75 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
--- test/th1-repo.test
+++ test/th1-repo.test
@@ -64,12 +64,27 @@
64 ###############################################################################
65
66 fossil test-th-eval --open-config "dir trunk subdir*/*.md"
67 test th1-dir-1 {[llength $RESULT] eq [llength $files_md]}
68
 
 
69 set n 1
70 foreach i $RESULT j $files_md {
71 test th1-dir-2.$n {$i eq $j}
72 set n [expr {$n + 1}]
73 }
74
75 ###############################################################################
76
77 set dateTime {\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}}
78 fossil test-th-eval --open-config "dir trunk subdir*/*.md 1"
79 test th1-dir-3.1 {[lindex [lindex $RESULT 0] 0] eq "subdirB/f5.md"}
80 test th1-dir-3.2 {[lindex [lindex $RESULT 0] 1] == 2}
81 test th1-dir-3.3 {[regexp -- $dateTime [lindex [lindex $RESULT 0] 2]]}
82 test th1-dir-3.4 {[lindex [lindex $RESULT 1] 0] eq "subdirB/f6.md"}
83 test th1-dir-3.5 {[lindex [lindex $RESULT 1] 1] == 2}
84 test th1-dir-3.6 {[regexp -- $dateTime [lindex [lindex $RESULT 1] 2]]}
85 test th1-dir-3.7 {[lindex [lindex $RESULT 2] 0] eq "subdirB/f8.md"}
86 test th1-dir-3.8 {[lindex [lindex $RESULT 2] 1] == 2}
87 test th1-dir-3.9 {[regexp -- $dateTime [lindex [lindex $RESULT 2] 2]]}
88 test th1-dir-3.10 {[lindex [lindex $RESULT 3] 0] eq "subdirC/f10.md"}
89 test th1-dir-3.11 {[lindex [lindex $RESULT 3] 1] == 3}
90 test th1-dir-3.12 {[regexp -- $dateTime [lindex [lindex $RESULT 3] 2]]}
91
+5 -1
--- www/th1.md
+++ www/th1.md
@@ -239,12 +239,16 @@
239239
<a name="dir"></a>TH1 dir Command
240240
-------------------------------------------
241241
242242
* dir CHECKIN ?GLOB?
243243
244
-Returns a list containing all files in CHECKIN. If GLOB is given only
244
+Returns a list containing all files in CHECKIN. If GLOB is given only
245245
the files matching the pattern GLOB within CHECKIN will be returned.
246
+If DETAILS is non-zero, the result will be a list-of-lists, with each
247
+element containing at least three elements: the file name, the file
248
+size (in bytes), and the file last modification time (relative to the
249
+time zone configured for the repository).
246250
247251
<a name="enable_output"></a>TH1 enable_output Command
248252
-----------------------------------------------------
249253
250254
* enable_output BOOLEAN
251255
--- www/th1.md
+++ www/th1.md
@@ -239,12 +239,16 @@
239 <a name="dir"></a>TH1 dir Command
240 -------------------------------------------
241
242 * dir CHECKIN ?GLOB?
243
244 Returns a list containing all files in CHECKIN. If GLOB is given only
245 the files matching the pattern GLOB within CHECKIN will be returned.
 
 
 
 
246
247 <a name="enable_output"></a>TH1 enable_output Command
248 -----------------------------------------------------
249
250 * enable_output BOOLEAN
251
--- www/th1.md
+++ www/th1.md
@@ -239,12 +239,16 @@
239 <a name="dir"></a>TH1 dir Command
240 -------------------------------------------
241
242 * dir CHECKIN ?GLOB?
243
244 Returns a list containing all files in CHECKIN. If GLOB is given only
245 the files matching the pattern GLOB within CHECKIN will be returned.
246 If DETAILS is non-zero, the result will be a list-of-lists, with each
247 element containing at least three elements: the file name, the file
248 size (in bytes), and the file last modification time (relative to the
249 time zone configured for the repository).
250
251 <a name="enable_output"></a>TH1 enable_output Command
252 -----------------------------------------------------
253
254 * enable_output BOOLEAN
255

Keyboard Shortcuts

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