Fossil

Check-in [5d56fb7e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:implemented th1 comman 'dir' similar to cli 'ls'
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | ckol-th1-dir-cmd
Files: files | file ages | folders
SHA1: 5d56fb7e2c184cd8fb654b7ac7b9a5721f7ba452
User & Date: ckolumbus 2015-08-14 19:29:57.247
Context
2015-08-14
19:40
added documentation for new th1 command 'dir' ... (check-in: 00e634fe user: ckolumbus tags: ckol-th1-dir-cmd)
19:29
implemented th1 comman 'dir' similar to cli 'ls' ... (check-in: 5d56fb7e user: ckolumbus tags: ckol-th1-dir-cmd)
19:17
Create new branch named "ckol-th1-dir-cmd" ... (check-in: 19503f88 user: ckolumbus tags: ckol-th1-dir-cmd)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/doc.c.
538
539
540
541
542
543
544



545
546
547
548
549
550
551
  int rid = 0;                      /* Artifact of file */
  int i;                            /* Loop counter */
  Blob filebody;                    /* Content of the documentation file */
  Blob title;                       /* Document title */
  int nMiss = (-1);                 /* Failed attempts to find the document */
  static const char *const azSuffix[] = {
     "index.html", "index.wiki", "index.md"



  };

  login_check_credentials();
  if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
  blob_init(&title, 0, 0);
  db_begin_transaction();
  while( rid==0 && (++nMiss)<=ArraySize(azSuffix) ){







>
>
>







538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
  int rid = 0;                      /* Artifact of file */
  int i;                            /* Loop counter */
  Blob filebody;                    /* Content of the documentation file */
  Blob title;                       /* Document title */
  int nMiss = (-1);                 /* Failed attempts to find the document */
  static const char *const azSuffix[] = {
     "index.html", "index.wiki", "index.md"
#ifdef FOSSIL_ENABLE_TH1_DOCS
      , "index.th1"
#endif 
  };

  login_check_credentials();
  if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
  blob_init(&title, 0, 0);
  db_begin_transaction();
  while( rid==0 && (++nMiss)<=ArraySize(azSuffix) ){
Changes to src/th_main.c.
141
142
143
144
145
146
147





















































































148
149
150
151
152
153
154
  if( g.thTrace ){
    fossil_print("\n------------------ BEGIN TRACE LOG ------------------\n");
    fossil_print("%s", blob_str(&g.thLog));
    fossil_print("\n------------------- END TRACE LOG -------------------\n");
  }
}






















































































/*
** TH1 command: httpize STRING
**
** Escape all characters of STRING which have special meaning in URI
** components. Return a new string result.
*/
static int httpizeCmd(







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
  if( g.thTrace ){
    fossil_print("\n------------------ BEGIN TRACE LOG ------------------\n");
    fossil_print("%s", blob_str(&g.thLog));
    fossil_print("\n------------------- END TRACE LOG -------------------\n");
  }
}


/*
** - adopted from ls_cmd_rev in checkin.c 
** - adopted commands/error handling for usage within th1
** - interface adopted to allow result creation as TH1 List
**
** Takes a checkin identifier in zRev and an optiona glob pattern in zGLOB
** as parameter returns a TH list in pzList,pnList with filenames matching
** glob pattern with the checking
*/
static void dir_cmd_rev(
  Th_Interp *interp,
  char** pzList,
  int*   pnList,
  const char *zRev,  /* Revision string given */
  const char* zGlob  /* */
){
  Stmt q;
  char *zOrderBy = "pathname COLLATE nocase";
  char *zName;
  int rid;
  int i;

  rid = th1_name_to_typed_rid(interp, zRev, "ci");

  compute_fileage(rid, zGlob);
  db_prepare(&q,
    "SELECT datetime(fileage.mtime, 'localtime'), fileage.pathname,\n"
    "       blob.size\n"
    "  FROM fileage, blob\n"
    " WHERE blob.rid=fileage.fid \n"
    " ORDER BY %s;", zOrderBy /*safe-for-%s*/
  );

  while( db_step(&q)==SQLITE_ROW ){
    const char *zTime = db_column_text(&q,0);
    const char *zFile = db_column_text(&q,1);
    int size = db_column_int(&q,2);

    Th_ListAppend(interp, pzList, pnList, zFile, -1);
    //fossil_print("%s\n", zFile);
  }
  db_finalize(&q);
}

/*
** TH1 command: dir CHECKIN ?GLOB?
**
** Returns a list containing all files in CHECKIN. If GLOB is given
** only the files matching the pattern GLOB within CHECKIN will be returned.
*/
static int dirCmd(
  Th_Interp *interp,
  void *ctx,
  int argc,
  const char **argv,
  int *argl
){
  const char *zGlob = 0;
  char *zList = 0;
  int nList = 0;
  int i;

  if( argc!=2 && argc != 3){
    return Th_WrongNumArgs(interp, "dir CHECKIN ?GLOB?");
  }

  if( argc == 3){
    zGlob = argv[2];
  }

  if( Th_IsRepositoryOpen() ){
    dir_cmd_rev(interp, &zList, &nList, argv[1], zGlob);

    Th_SetResult(interp, zList, nList);
    Th_Free(interp, zList);

    return TH_OK;

  } else {
    Th_SetResult(interp, "repository unavailable", -1);
    return TH_ERROR;
  }
}

/*
** TH1 command: httpize STRING
**
** Escape all characters of STRING which have special meaning in URI
** components. Return a new string result.
*/
static int httpizeCmd(
1630
1631
1632
1633
1634
1635
1636

1637
1638
1639
1640
1641
1642
1643
    {"anoncap",       hascapCmd,            (void*)&anonFlag},
    {"anycap",        anycapCmd,            0},
    {"artifact",      artifactCmd,          0},
    {"checkout",      checkoutCmd,          0},
    {"combobox",      comboboxCmd,          0},
    {"date",          dateCmd,              0},
    {"decorate",      wikiCmd,              (void*)&aFlags[2]},

    {"enable_output", enableOutputCmd,      0},
    {"getParameter",  getParameterCmd,      0},
    {"glob_match",    globMatchCmd,         0},
    {"globalState",   globalStateCmd,       0},
    {"httpize",       httpizeCmd,           0},
    {"hascap",        hascapCmd,            (void*)&zeroInt},
    {"hasfeature",    hasfeatureCmd,        0},







>







1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
    {"anoncap",       hascapCmd,            (void*)&anonFlag},
    {"anycap",        anycapCmd,            0},
    {"artifact",      artifactCmd,          0},
    {"checkout",      checkoutCmd,          0},
    {"combobox",      comboboxCmd,          0},
    {"date",          dateCmd,              0},
    {"decorate",      wikiCmd,              (void*)&aFlags[2]},
    {"dir",           dirCmd,               0},
    {"enable_output", enableOutputCmd,      0},
    {"getParameter",  getParameterCmd,      0},
    {"glob_match",    globMatchCmd,         0},
    {"globalState",   globalStateCmd,       0},
    {"httpize",       httpizeCmd,           0},
    {"hascap",        hascapCmd,            (void*)&zeroInt},
    {"hasfeature",    hasfeatureCmd,        0},