Пример #1
0
/*
** COMMAND:  test-content-rawget
**
** Extract a blob from the database and write it into a file.  This
** version does not expand the delta.
*/
void test_content_rawget_cmd(void){
  int rid;
  Blob content;
  const char *zFile;
  if( g.argc!=4 && g.argc!=3 ) usage("RECORDID ?FILENAME?");
  zFile = g.argc==4 ? g.argv[3] : "-";
  db_must_be_within_tree();
  rid = name_to_rid(g.argv[2]);
  blob_zero(&content);
  db_blob(&content, "SELECT content FROM blob WHERE rid=%d", rid);
  blob_uncompress(&content, &content);
  blob_write_to_file(&content, zFile);
}
Пример #2
0
/*
** This routine takes a user-entered UUID which might be in mixed
** case and might only be a prefix of the full UUID and converts it
** into the full-length UUID in canonical form.
**
** If the input is not a UUID or a UUID prefix, then try to resolve
** the name as a tag.  If multiple tags match, pick the latest.
** If the input name matches "tag:*" then always resolve as a tag.
**
** If the input is not a tag, then try to match it as an ISO-8601 date
** string YYYY-MM-DD HH:MM:SS and pick the nearest check-in to that date.
** If the input is of the form "date:*" then always resolve the name as
** a date. The forms "utc:*" and "local:" are deprecated.
**
** Return 0 on success.  Return 1 if the name cannot be resolved.
** Return 2 name is ambiguous.
*/
int name_to_uuid(Blob *pName, int iErrPriority, const char *zType){
  char *zName = blob_str(pName);
  int rid = symbolic_name_to_rid(zName, zType);
  if( rid<0 ){
    fossil_error(iErrPriority, "ambiguous name: %s", zName);
    return 2;
  }else if( rid==0 ){
    fossil_error(iErrPriority, "not found: %s", zName);
    return 1;
  }else{
    blob_reset(pName);
    db_blob(pName, "SELECT uuid FROM blob WHERE rid=%d", rid);
    return 0;
  }
}
Пример #3
0
/*
** Load the record identify by rid.  Make sure we can reproduce it
** without error.
**
** Panic if anything goes wrong.  If this procedure returns it means
** that everything is OK.
*/
static void verify_rid(int rid){
  Blob uuid, hash, content;
  if( content_size(rid, 0)<0 ){
    return;  /* No way to verify phantoms */
  }
  blob_zero(&uuid);
  db_blob(&uuid, "SELECT uuid FROM blob WHERE rid=%d", rid);
  if( blob_size(&uuid)!=UUID_SIZE ){
    fossil_fatal("not a valid rid: %d", rid);
  }
  if( content_get(rid, &content) ){
    sha1sum_blob(&content, &hash);
    blob_reset(&content);
    if( blob_compare(&uuid, &hash) ){
      fossil_fatal("hash of rid %d (%b) does not match its uuid (%b)",
                    rid, &hash, &uuid);
    }
    blob_reset(&hash);
  }
  blob_reset(&uuid);
}
Пример #4
0
/*
** COMMAND: finfo
**
** Usage: %fossil finfo ?OPTIONS? FILENAME
**
** Print the complete change history for a single file going backwards
** in time.  The default mode is -l.
**
** For the -l|--log mode: If "-b|--brief" is specified one line per revision
** is printed, otherwise the full comment is printed.  The "-n|--limit N"
** and "--offset P" options limits the output to the first N changes
** after skipping P changes.
**
** In the -s mode prints the status as <status> <revision>.  This is
** a quick status and does not check for up-to-date-ness of the file.
**
** In the -p mode, there's an optional flag "-r|--revision REVISION".
** The specified version (or the latest checked out version) is printed
** to stdout.  The -p mode is another form of the "cat" command.
**
** Options:
**   -b|--brief           display a brief (one line / revision) summary
**   --case-sensitive B   Enable or disable case-sensitive filenames.  B is a
**                        boolean: "yes", "no", "true", "false", etc.
**   -l|--log             select log mode (the default)
**   -n|--limit N         Display the first N changes (default unlimited).
**                        N<=0 means no limit.
**   --offset P           skip P changes
**   -p|--print           select print mode
**   -r|--revision R      print the given revision (or ckout, if none is given)
**                        to stdout (only in print mode)
**   -s|--status          select status mode (print a status indicator for FILE)
**   -W|--width <num>     Width of lines (default is to auto-detect). Must be
**                        >22 or 0 (= no limit, resulting in a single line per
**                        entry).
**
** See also: artifact, cat, descendants, info, leaves
*/
void finfo_cmd(void){
  db_must_be_within_tree();
  if( find_option("status","s",0) ){
    Stmt q;
    Blob line;
    Blob fname;
    int vid;

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

    if( g.argc!=3 ) usage("-s|--status FILENAME");
    vid = db_lget_int("checkout", 0);
    if( vid==0 ){
      fossil_fatal("no checkout to finfo files in");
    }
    vfile_check_signature(vid, CKSIG_ENOTFILE);
    file_tree_name(g.argv[2], &fname, 0, 1);
    db_prepare(&q,
        "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)"
        "  FROM vfile WHERE vfile.pathname=%B %s",
        &fname, filename_collation());
    blob_zero(&line);
    if( db_step(&q)==SQLITE_ROW ) {
      Blob uuid;
      int isDeleted = db_column_int(&q, 1);
      int isNew = db_column_int(&q,2) == 0;
      int chnged = db_column_int(&q,3);
      int renamed = db_column_int(&q,4);

      blob_zero(&uuid);
      db_blob(&uuid,
           "SELECT uuid FROM blob, mlink, vfile WHERE "
           "blob.rid = mlink.mid AND mlink.fid = vfile.rid AND "
           "vfile.pathname=%B %s",
           &fname, filename_collation()
      );
      if( isNew ){
        blob_appendf(&line, "new");
      }else if( isDeleted ){
        blob_appendf(&line, "deleted");
      }else if( renamed ){
        blob_appendf(&line, "renamed");
      }else if( chnged ){
        blob_appendf(&line, "edited");
      }else{
        blob_appendf(&line, "unchanged");
      }
      blob_appendf(&line, " ");
      blob_appendf(&line, " %10.10s", blob_str(&uuid));
      blob_reset(&uuid);
    }else{
      blob_appendf(&line, "unknown 0000000000");
    }
    db_finalize(&q);
    fossil_print("%s\n", blob_str(&line));
    blob_reset(&fname);
    blob_reset(&line);
  }else if( find_option("print","p",0) ){
    Blob record;
    Blob fname;
    const char *zRevision = find_option("revision", "r", 1);

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

    file_tree_name(g.argv[2], &fname, 0, 1);
    if( zRevision ){
      historical_version_of_file(zRevision, blob_str(&fname), &record, 0,0,0,0);
    }else{
      int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B %s",
                       &fname, filename_collation());
      if( rid==0 ){
        fossil_fatal("no history for file: %b", &fname);
      }
      content_get(rid, &record);
    }
    blob_write_to_file(&record, "-");
    blob_reset(&record);
    blob_reset(&fname);
  }else{
    Blob line;
    Stmt q;
    Blob fname;
    int rid;
    const char *zFilename;
    const char *zLimit;
    const char *zWidth;
    const char *zOffset;
    int iLimit, iOffset, iBrief, iWidth;

    if( find_option("log","l",0) ){
      /* this is the default, no-op */
    }
    zLimit = find_option("limit","n",1);
    zWidth = find_option("width","W",1);
    iLimit = zLimit ? atoi(zLimit) : -1;
    zOffset = find_option("offset",0,1);
    iOffset = zOffset ? atoi(zOffset) : 0;
    iBrief = (find_option("brief","b",0) == 0);
    if( iLimit==0 ){
      iLimit = -1;
    }
    if( zWidth ){
      iWidth = atoi(zWidth);
      if( (iWidth!=0) && (iWidth<=22) ){
        fossil_fatal("-W|--width value must be >22 or 0");
      }
    }else{
      iWidth = -1;
    }

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

    if( g.argc!=3 ){
      usage("?-l|--log? ?-b|--brief? FILENAME");
    }
    file_tree_name(g.argv[2], &fname, 0, 1);
    rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B %s",
                 &fname, filename_collation());
    if( rid==0 ){
      fossil_fatal("no history for file: %b", &fname);
    }
    zFilename = blob_str(&fname);
    db_prepare(&q,
        "SELECT DISTINCT b.uuid, ci.uuid, date(event.mtime%s),"
        "       coalesce(event.ecomment, event.comment),"
        "       coalesce(event.euser, event.user),"
        "       (SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0"
                                " AND tagxref.rid=mlink.mid)" /* Tags */
        "  FROM mlink, blob b, event, blob ci, filename"
        " WHERE filename.name=%Q %s"
        "   AND mlink.fnid=filename.fnid"
        "   AND b.rid=mlink.fid"
        "   AND event.objid=mlink.mid"
        "   AND event.objid=ci.rid"
        " ORDER BY event.mtime DESC LIMIT %d OFFSET %d",
        timeline_utc(), TAG_BRANCH, zFilename, filename_collation(),
        iLimit, iOffset
    );
    blob_zero(&line);
    if( iBrief ){
      fossil_print("History of %s\n", blob_str(&fname));
    }
    while( db_step(&q)==SQLITE_ROW ){
      const char *zFileUuid = db_column_text(&q, 0);
      const char *zCiUuid = db_column_text(&q,1);
      const char *zDate = db_column_text(&q, 2);
      const char *zCom = db_column_text(&q, 3);
      const char *zUser = db_column_text(&q, 4);
      const char *zBr = db_column_text(&q, 5);
      char *zOut;
      if( zBr==0 ) zBr = "trunk";
      if( iBrief ){
        fossil_print("%s ", zDate);
        zOut = mprintf(
           "[%S] %s (user: %s, artifact: [%S], branch: %s)",
           zCiUuid, zCom, zUser, zFileUuid, zBr);
        comment_print(zOut, zCom, 11, iWidth, g.comFmtFlags);
        fossil_free(zOut);
      }else{
        blob_reset(&line);
        blob_appendf(&line, "%S ", zCiUuid);
        blob_appendf(&line, "%.10s ", zDate);
        blob_appendf(&line, "%8.8s ", zUser);
        blob_appendf(&line, "%8.8s ", zBr);
        blob_appendf(&line,"%-39.39s", zCom );
        comment_print(blob_str(&line), zCom, 0, iWidth, g.comFmtFlags);
      }
    }
    db_finalize(&q);
    blob_reset(&fname);
  }
}
Пример #5
0
/*
** COMMAND: finfo
**
** Usage: %fossil finfo ?OPTIONS? FILENAME
**
** Print the complete change history for a single file going backwards
** in time.  The default is -l.
**
** For the -l|--log option: If "-b|--brief" is specified one line per revision
** is printed, otherwise the full comment is printed.  The "--limit N"
** and "--offset P" options limits the output to the first N changes
** after skipping P changes.
**
** In the -s form prints the status as <status> <revision>.  This is
** a quick status and does not check for up-to-date-ness of the file.
**
** In the -p form, there's an optional flag "-r|--revision REVISION".
** The specified version (or the latest checked out version) is printed
** to stdout.
**
** Options:
**   --brief|-b           display a brief (one line / revision) summary
**   --limit N            display the first N changes
**   --log|-l             select log mode (the default)
**   --offset P           skip P changes
**   -p                   select print mode
**   --revision|-r R      print the given revision (or ckout, if none is given)
**                        to stdout (only in print mode)
**   -s                   select status mode (print a status indicator for FILE)
**   --case-sensitive B   Enable or disable case-sensitive filenames.  B is a
**                        boolean: "yes", "no", "true", "false", etc.
**
** See also: artifact, descendants, info, leaves
*/
void finfo_cmd(void) {
    capture_case_sensitive_option();
    db_must_be_within_tree();
    if (find_option("status","s",0)) {
        Stmt q;
        Blob line;
        Blob fname;
        int vid;

        if( g.argc!=3 ) usage("-s|--status FILENAME");
        vid = db_lget_int("checkout", 0);
        if( vid==0 ) {
            fossil_panic("no checkout to finfo files in");
        }
        vfile_check_signature(vid, 1, 0);
        file_tree_name(g.argv[2], &fname, 1);
        db_prepare(&q,
                   "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)"
                   "  FROM vfile WHERE vfile.pathname=%B %s",
                   &fname, filename_collation());
        blob_zero(&line);
        if ( db_step(&q)==SQLITE_ROW ) {
            Blob uuid;
            int isDeleted = db_column_int(&q, 1);
            int isNew = db_column_int(&q,2) == 0;
            int chnged = db_column_int(&q,3);
            int renamed = db_column_int(&q,4);

            blob_zero(&uuid);
            db_blob(&uuid,
                    "SELECT uuid FROM blob, mlink, vfile WHERE "
                    "blob.rid = mlink.mid AND mlink.fid = vfile.rid AND "
                    "vfile.pathname=%B %s",
                    &fname, filename_collation()
                   );
            if( isNew ) {
                blob_appendf(&line, "new");
            } else if( isDeleted ) {
                blob_appendf(&line, "deleted");
            } else if( renamed ) {
                blob_appendf(&line, "renamed");
            } else if( chnged ) {
                blob_appendf(&line, "edited");
            } else {
                blob_appendf(&line, "unchanged");
            }
            blob_appendf(&line, " ");
            blob_appendf(&line, " %10.10s", blob_str(&uuid));
            blob_reset(&uuid);
        } else {
            blob_appendf(&line, "unknown 0000000000");
        }
        db_finalize(&q);
        fossil_print("%s\n", blob_str(&line));
        blob_reset(&fname);
        blob_reset(&line);
    } else if( find_option("print","p",0) ) {
        Blob record;
        Blob fname;
        const char *zRevision = find_option("revision", "r", 1);

        file_tree_name(g.argv[2], &fname, 1);
        if( zRevision ) {
            historical_version_of_file(zRevision, blob_str(&fname), &record, 0, 0, 0);
        } else {
            int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B %s",
                             &fname, filename_collation());
            if( rid==0 ) {
                fossil_fatal("no history for file: %b", &fname);
            }
            content_get(rid, &record);
        }
        blob_write_to_file(&record, "-");
        blob_reset(&record);
        blob_reset(&fname);
    } else {
        Blob line;
        Stmt q;
        Blob fname;
        int rid;
        const char *zFilename;
        const char *zLimit;
        const char *zOffset;
        int iLimit, iOffset, iBrief;

        if( find_option("log","l",0) ) {
            /* this is the default, no-op */
        }
        zLimit = find_option("limit",0,1);
        iLimit = zLimit ? atoi(zLimit) : -1;
        zOffset = find_option("offset",0,1);
        iOffset = zOffset ? atoi(zOffset) : 0;
        iBrief = (find_option("brief","b",0) == 0);
        if( g.argc!=3 ) {
            usage("?-l|--log? ?-b|--brief? FILENAME");
        }
        file_tree_name(g.argv[2], &fname, 1);
        rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B %s",
                     &fname, filename_collation());
        if( rid==0 ) {
            fossil_fatal("no history for file: %b", &fname);
        }
        zFilename = blob_str(&fname);
        db_prepare(&q,
                   "SELECT b.uuid, ci.uuid, date(event.mtime,'localtime'),"
                   "       coalesce(event.ecomment, event.comment),"
                   "       coalesce(event.euser, event.user)"
                   "  FROM mlink, blob b, event, blob ci, filename"
                   " WHERE filename.name=%Q %s"
                   "   AND mlink.fnid=filename.fnid"
                   "   AND b.rid=mlink.fid"
                   "   AND event.objid=mlink.mid"
                   "   AND event.objid=ci.rid"
                   " ORDER BY event.mtime DESC LIMIT %d OFFSET %d",
                   zFilename, filename_collation(), iLimit, iOffset
                  );
        blob_zero(&line);
        if( iBrief ) {
            fossil_print("History of %s\n", blob_str(&fname));
        }
        while( db_step(&q)==SQLITE_ROW ) {
            const char *zFileUuid = db_column_text(&q, 0);
            const char *zCiUuid = db_column_text(&q,1);
            const char *zDate = db_column_text(&q, 2);
            const char *zCom = db_column_text(&q, 3);
            const char *zUser = db_column_text(&q, 4);
            char *zOut;
            if( iBrief ) {
                fossil_print("%s ", zDate);
                zOut = sqlite3_mprintf("[%.10s] %s (user: %s, artifact: [%.10s])",
                                       zCiUuid, zCom, zUser, zFileUuid);
                comment_print(zOut, 11, 79);
                sqlite3_free(zOut);
            } else {
                blob_reset(&line);
                blob_appendf(&line, "%.10s ", zCiUuid);
                blob_appendf(&line, "%.10s ", zDate);
                blob_appendf(&line, "%8.8s ", zUser);
                blob_appendf(&line,"%-40.40s\n", zCom );
                comment_print(blob_str(&line), 0, 79);
            }
        }
        db_finalize(&q);
        blob_reset(&fname);
    }
}