Fossil

Check-in [5484968158]
Login

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

Overview
Comment:Add the "fossil all whatis" command.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5484968158a915dc36941394dee809082ad6708d128cab54fadb8b859594fa57
User & Date: drh 2023-06-05 19:01:34.010
Context
2023-06-06
00:46
Improved documentation of "fossil all whatis" check-in: 401711d484 user: drh tags: trunk
2023-06-05
19:01
Add the "fossil all whatis" command. check-in: 5484968158 user: drh tags: trunk
2023-06-03
10:27
Fixed a typo in an error message check-in: f25da6ec97 user: wyoung tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/allrepo.c.
129
130
131
132
133
134
135


136
137
138
139
140
141
142
**                The root URI gives a listing of all repos.
**
**    ui          Run the "ui" command on all repositories.  Like "server"
**                but bind to the loopback TCP address only, enable
**                the --localauth option and automatically launch a
**                web-browser
**


**
** In addition, the following maintenance operations are supported:
**
**    add         Add all the repositories named to the set of repositories
**                tracked by Fossil.  Normally Fossil is able to keep up with
**                this list by itself, but sometimes it can benefit from this
**                hint if you rename repositories.







>
>







129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
**                The root URI gives a listing of all repos.
**
**    ui          Run the "ui" command on all repositories.  Like "server"
**                but bind to the loopback TCP address only, enable
**                the --localauth option and automatically launch a
**                web-browser
**
**    whatis XX   Search for artifacts that have hash prefix XX     
**
**
** In addition, the following maintenance operations are supported:
**
**    add         Add all the repositories named to the set of repositories
**                tracked by Fossil.  Normally Fossil is able to keep up with
**                this list by itself, but sometimes it can benefit from this
**                hint if you rename repositories.
406
407
408
409
410
411
412




413
414
415
416
417
418
419
420
421
422
423
424
    zCmd = "info";
    showLabel = 1;
    quiet = 1;
  }else if( fossil_strcmp(zCmd, "cache")==0 ){
    zCmd = "cache -R";
    showLabel = 1;
    collect_argv(&extra, 3);




  }else{
    fossil_fatal("\"all\" subcommand should be one of: "
      "add cache changes clean dbstat extras fts-config git ignore "
      "info list ls pull push rebuild remote "
      "server setting sync ui unset");
  }
  verify_all_options();
  db_multi_exec("CREATE TEMP TABLE repolist(name,tag);");
  if( useCheckouts ){
    db_multi_exec(
       "INSERT INTO repolist "
       "SELECT DISTINCT substr(name, 7), name COLLATE nocase"







>
>
>
>




|







408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
    zCmd = "info";
    showLabel = 1;
    quiet = 1;
  }else if( fossil_strcmp(zCmd, "cache")==0 ){
    zCmd = "cache -R";
    showLabel = 1;
    collect_argv(&extra, 3);
  }else if( fossil_strcmp(zCmd, "whatis")==0 ){
    zCmd = "whatis -q -R";
    quiet = 1;
    collect_argv(&extra, 3);
  }else{
    fossil_fatal("\"all\" subcommand should be one of: "
      "add cache changes clean dbstat extras fts-config git ignore "
      "info list ls pull push rebuild remote "
      "server setting sync ui unset whatis");
  }
  verify_all_options();
  db_multi_exec("CREATE TEMP TABLE repolist(name,tag);");
  if( useCheckouts ){
    db_multi_exec(
       "INSERT INTO repolist "
       "SELECT DISTINCT substr(name, 7), name COLLATE nocase"
Changes to src/name.c.
977
978
979
980
981
982
983
984
985


986
987
988
989
990
991
992
  return zType;
}

/*
** Flag values for whatis_rid().
*/
#if INTERFACE
#define WHATIS_VERBOSE 0x01    /* Extra output */
#define WHATIS_BRIEF   0x02    /* Omit unnecessary output */


#endif

/*
** Generate a description of artifact "rid"
*/
void whatis_rid(int rid, int flags){
  Stmt q;







|
|
>
>







977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
  return zType;
}

/*
** Flag values for whatis_rid().
*/
#if INTERFACE
#define WHATIS_VERBOSE   0x01    /* Extra output */
#define WHATIS_BRIEF     0x02    /* Omit unnecessary output */
#define WHATIS_REPO      0x04    /* Show repository name */
#define WHATIS_OMIT_UNK  0x08    /* Do not show "unknown" lines */
#endif

/*
** Generate a description of artifact "rid"
*/
void whatis_rid(int rid, int flags){
  Stmt q;
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169



1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180

1181
1182

1183



1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200

1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211





1212
1213
1214
1215
1216
1217
1218
/*
** Generate a description of artifact from it symbolic name.
*/
void whatis_artifact(
    const char *zName,    /* Symbolic name or full hash */
    const char *zFileName,/* Optional: original filename (in file mode) */
    const char *zType,    /* Artifact type filter */
    int verboseFlag       /* Verbosity flag */
){
  const char* zNameTitle = "name:";
  int rid = symbolic_name_to_rid(zName, zType);
  if( zFileName ){
    fossil_print("%-12s%s\n", zNameTitle, zFileName);
    zNameTitle = "hash:";
  }
  if( rid<0 ){
    Stmt q;
    int cnt = 0;



    fossil_print("%-12s%s (ambiguous)\n", zNameTitle, zName);
    db_prepare(&q,
        "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')",
        zName, zName
        );
    while( db_step(&q)==SQLITE_ROW ){
      if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
      whatis_rid(db_column_int(&q, 0), verboseFlag);
    }
    db_finalize(&q);
  }else if( rid==0 ){

    /* 0123456789 12 */
    fossil_print("unknown:    %s\n", zName);

  }else{



    fossil_print("%-12s%s\n", zNameTitle, zName);
    whatis_rid(rid, verboseFlag);
  }
}

/*
** COMMAND: whatis*
**
** Usage: %fossil whatis NAME
**
** Resolve the symbol NAME into its canonical artifact hash
** artifact name and provide a description of what role that artifact
** plays.
**
** Options:
**    -f|--file            Find artifacts with the same hash as file NAME.
**                         If NAME is "-", read content from standard input.

**    --type TYPE          Only find artifacts of TYPE (one of: 'ci', 't',
**                         'w', 'g', or 'e')
**    -v|--verbose         Provide extra information (such as the RID)
*/
void whatis_cmd(void){
  int verboseFlag;
  int fileFlag;
  int i;
  const char *zType = 0;
  db_find_and_open_repository(0,0);
  verboseFlag = find_option("verbose","v",0)!=0;





  fileFlag = find_option("file","f",0)!=0;
  zType = find_option("type",0,1);

  /* We should be done with options.. */
  verify_all_options();

  if( g.argc<3 ) usage("NAME ...");







|










>
>
>







|



>
|
|
>

>
>
>

|















>





|




|
>
>
>
>
>







1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
/*
** Generate a description of artifact from it symbolic name.
*/
void whatis_artifact(
    const char *zName,    /* Symbolic name or full hash */
    const char *zFileName,/* Optional: original filename (in file mode) */
    const char *zType,    /* Artifact type filter */
    int mFlags            /* WHATIS_* flags */
){
  const char* zNameTitle = "name:";
  int rid = symbolic_name_to_rid(zName, zType);
  if( zFileName ){
    fossil_print("%-12s%s\n", zNameTitle, zFileName);
    zNameTitle = "hash:";
  }
  if( rid<0 ){
    Stmt q;
    int cnt = 0;
    if( mFlags & WHATIS_REPO ){
      fossil_print("\nrepository: %s\n", g.zRepositoryName);
    }
    fossil_print("%-12s%s (ambiguous)\n", zNameTitle, zName);
    db_prepare(&q,
        "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')",
        zName, zName
        );
    while( db_step(&q)==SQLITE_ROW ){
      if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt);
      whatis_rid(db_column_int(&q, 0), mFlags);
    }
    db_finalize(&q);
  }else if( rid==0 ){
    if( (mFlags & WHATIS_OMIT_UNK)==0 ){
                 /* 0123456789 12 */
      fossil_print("unknown:    %s\n", zName);
    }
  }else{
    if( mFlags & WHATIS_REPO ){
      fossil_print("\nrepository: %s\n", g.zRepositoryName);
    }
    fossil_print("%-12s%s\n", zNameTitle, zName);
    whatis_rid(rid, mFlags);
  }
}

/*
** COMMAND: whatis*
**
** Usage: %fossil whatis NAME
**
** Resolve the symbol NAME into its canonical artifact hash
** artifact name and provide a description of what role that artifact
** plays.
**
** Options:
**    -f|--file            Find artifacts with the same hash as file NAME.
**                         If NAME is "-", read content from standard input.
**    -q|--quiet           Show nothing if NAME is not found
**    --type TYPE          Only find artifacts of TYPE (one of: 'ci', 't',
**                         'w', 'g', or 'e')
**    -v|--verbose         Provide extra information (such as the RID)
*/
void whatis_cmd(void){
  int mFlags = 0;
  int fileFlag;
  int i;
  const char *zType = 0;
  db_find_and_open_repository(0,0);
  if( find_option("verbose","v",0)!=0 ){
    mFlags |= WHATIS_VERBOSE;
  }
  if( find_option("quiet","q",0)!=0 ){
    mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO;
  }
  fileFlag = find_option("file","f",0)!=0;
  zType = find_option("type",0,1);

  /* We should be done with options.. */
  verify_all_options();

  if( g.argc<3 ) usage("NAME ...");
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
      if( fast_uuid_to_rid(zHash)==0 ){
        /* No existing artifact with the auxiliary hash name.  Therefore, use
        ** the primary hash name. */
        blob_reset(&hash);
        hname_hash(&in, 0, &hash);
        zHash = (const char*)blob_str(&hash);
      }
      whatis_artifact(zHash, zName, zType, verboseFlag);
      blob_reset(&hash);
    }else{
      whatis_artifact(zName, 0, zType, verboseFlag);
    }
  }
}

/*
** COMMAND: test-whatis-all
**







|


|







1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
      if( fast_uuid_to_rid(zHash)==0 ){
        /* No existing artifact with the auxiliary hash name.  Therefore, use
        ** the primary hash name. */
        blob_reset(&hash);
        hname_hash(&in, 0, &hash);
        zHash = (const char*)blob_str(&hash);
      }
      whatis_artifact(zHash, zName, zType, mFlags);
      blob_reset(&hash);
    }else{
      whatis_artifact(zName, 0, zType, mFlags);
    }
  }
}

/*
** COMMAND: test-whatis-all
**