Fossil SCM

implemented th1 comman 'dir' similar to cli 'ls'

ckolumbus 2015-08-14 19:29 ckol-th1-dir-cmd
Commit 5d56fb7e2c184cd8fb654b7ac7b9a5721f7ba452
2 files changed +3 +86
+3
--- src/doc.c
+++ src/doc.c
@@ -540,10 +540,13 @@
540540
Blob filebody; /* Content of the documentation file */
541541
Blob title; /* Document title */
542542
int nMiss = (-1); /* Failed attempts to find the document */
543543
static const char *const azSuffix[] = {
544544
"index.html", "index.wiki", "index.md"
545
+#ifdef FOSSIL_ENABLE_TH1_DOCS
546
+ , "index.th1"
547
+#endif
545548
};
546549
547550
login_check_credentials();
548551
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
549552
blob_init(&title, 0, 0);
550553
--- 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
--- src/th_main.c
+++ src/th_main.c
@@ -143,10 +143,95 @@
143143
fossil_print("%s", blob_str(&g.thLog));
144144
fossil_print("\n------------------- END TRACE LOG -------------------\n");
145145
}
146146
}
147147
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
+
148233
/*
149234
** TH1 command: httpize STRING
150235
**
151236
** Escape all characters of STRING which have special meaning in URI
152237
** components. Return a new string result.
@@ -1632,10 +1717,11 @@
16321717
{"artifact", artifactCmd, 0},
16331718
{"checkout", checkoutCmd, 0},
16341719
{"combobox", comboboxCmd, 0},
16351720
{"date", dateCmd, 0},
16361721
{"decorate", wikiCmd, (void*)&aFlags[2]},
1722
+ {"dir", dirCmd, 0},
16371723
{"enable_output", enableOutputCmd, 0},
16381724
{"getParameter", getParameterCmd, 0},
16391725
{"glob_match", globMatchCmd, 0},
16401726
{"globalState", globalStateCmd, 0},
16411727
{"httpize", httpizeCmd, 0},
16421728
--- 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

Keyboard Shortcuts

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