コード例 #1
0
ファイル: update.c プロジェクト: digsrc/fossil
/*
** Get the contents of a file within the check-in "revision".  If
** revision==NULL then get the file content for the current checkout.
*/
int historical_version_of_file(
    const char *revision,    /* The check-in containing the file */
    const char *file,        /* Full treename of the file */
    Blob *content,           /* Put the content here */
    int *pIsLink,            /* Set to true if file is link. */
    int *pIsExe,             /* Set to true if file is executable */
    int *pIsBin,             /* Set to true if file is binary */
    int errCode              /* Error code if file not found.  Panic if <= 0. */
) {
    Manifest *pManifest;
    ManifestFile *pFile;
    int rid=0;

    if( revision ) {
        rid = name_to_typed_rid(revision,"ci");
    } else if( !g.localOpen ) {
        rid = name_to_typed_rid(db_get("main-branch","trunk"),"ci");
    } else {
        rid = db_lget_int("checkout", 0);
    }
    if( !is_a_version(rid) ) {
        if( errCode>0 ) return errCode;
        fossil_fatal("no such check-in: %s", revision);
    }
    pManifest = manifest_get(rid, CFTYPE_MANIFEST, 0);

    if( pManifest ) {
        pFile = manifest_file_find(pManifest, file);
        if( pFile ) {
            int rc;
            rid = uuid_to_rid(pFile->zUuid, 0);
            if( pIsExe ) *pIsExe = ( manifest_file_mperm(pFile)==PERM_EXE );
            if( pIsLink ) *pIsLink = ( manifest_file_mperm(pFile)==PERM_LNK );
            manifest_destroy(pManifest);
            rc = content_get(rid, content);
            if( rc && pIsBin ) {
                *pIsBin = looks_like_binary(content);
            }
            return rc;
        }
        manifest_destroy(pManifest);
        if( errCode<=0 ) {
            fossil_fatal("file %s does not exist in check-in: %s", file, revision);
        }
    } else if( errCode<=0 ) {
        if( revision==0 ) {
            revision = db_text("current", "SELECT uuid FROM blob WHERE rid=%d", rid);
        }
        fossil_fatal("could not parse manifest for check-in: %s", revision);
    }
    return errCode;
}
コード例 #2
0
ファイル: vfile_.c プロジェクト: LitleWaffle/sampleDirectory
/*
** Load a vfile from a record ID.
*/
void load_vfile_from_rid(int vid){
  int rid, size;
  Stmt ins, ridq;
  Manifest *p;
  ManifestFile *pFile;

  if( db_exists("SELECT 1 FROM vfile WHERE vid=%d", vid) ){
    return;
  }

  db_begin_transaction();
  p = manifest_get(vid, CFTYPE_MANIFEST, 0);
  if( p==0 ) {
    db_end_transaction(1);
    return;
  }
  db_prepare(&ins,
    "INSERT INTO vfile(vid,isexe,islink,rid,mrid,pathname) "
    " VALUES(:vid,:isexe,:islink,:id,:id,:name)");
  db_prepare(&ridq, "SELECT rid,size FROM blob WHERE uuid=:uuid");
  db_bind_int(&ins, ":vid", vid);
  manifest_file_rewind(p);
  while( (pFile = manifest_file_next(p,0))!=0 ){
    if( pFile->zUuid==0 || uuid_is_shunned(pFile->zUuid) ) continue;
    db_bind_text(&ridq, ":uuid", pFile->zUuid);
    if( db_step(&ridq)==SQLITE_ROW ){
      rid = db_column_int(&ridq, 0);
      size = db_column_int(&ridq, 1);
    }else{
      rid = 0;
      size = 0;
    }
    db_reset(&ridq);
    if( rid==0 || size<0 ){
      fossil_warning("content missing for %s", pFile->zName);
      continue;
    }
    db_bind_int(&ins, ":isexe", ( manifest_file_mperm(pFile)==PERM_EXE ));
    db_bind_int(&ins, ":id", rid);
    db_bind_text(&ins, ":name", pFile->zName);
    db_bind_int(&ins, ":islink", ( manifest_file_mperm(pFile)==PERM_LNK ));
    db_step(&ins);
    db_reset(&ins);
  }
  db_finalize(&ridq);
  db_finalize(&ins);
  manifest_destroy(p);
  db_end_transaction(0);
}
コード例 #3
0
/*
** Given the RID for a checkin, construct a tarball containing
** all files in that checkin
**
** If RID is for an object that is not a real manifest, then the
** resulting tarball contains a single file which is the RID
** object.
**
** If the RID object does not exist in the repository, then
** pTar is zeroed.
**
** zDir is a "synthetic" subdirectory which all files get
** added to as part of the tarball. It may be 0 or an empty string, in
** which case it is ignored. The intention is to create a tarball which
** politely expands into a subdir instead of filling your current dir
** with source files. For example, pass a UUID or "ProjectName".
**
*/
void tarball_of_checkin(int rid, Blob *pTar, const char *zDir){
  Blob mfile, hash, file;
  Manifest *pManifest;
  ManifestFile *pFile;
  Blob filename;
  int nPrefix;
  char *zName;
  unsigned int mTime;

  content_get(rid, &mfile);
  if( blob_size(&mfile)==0 ){
    blob_zero(pTar);
    return;
  }
  blob_zero(&hash);
  blob_zero(&filename);

  if( zDir && zDir[0] ){
    blob_appendf(&filename, "%s/", zDir);
  }
  nPrefix = blob_size(&filename);

  pManifest = manifest_get(rid, CFTYPE_MANIFEST);
  if( pManifest ){
    mTime = (pManifest->rDate - 2440587.5)*86400.0;
    tar_begin(mTime);
    if( db_get_boolean("manifest", 0) ){
      blob_append(&filename, "manifest", -1);
      zName = blob_str(&filename);
      tar_add_file(zName, &mfile, 0, mTime);
      sha1sum_blob(&mfile, &hash);
      blob_reset(&mfile);
      blob_append(&hash, "\n", 1);
      blob_resize(&filename, nPrefix);
      blob_append(&filename, "manifest.uuid", -1);
      zName = blob_str(&filename);
      tar_add_file(zName, &hash, 0, mTime);
      blob_reset(&hash);
    }
    manifest_file_rewind(pManifest);
    while( (pFile = manifest_file_next(pManifest,0))!=0 ){
      int fid = uuid_to_rid(pFile->zUuid, 0);
      if( fid ){
        content_get(fid, &file);
        blob_resize(&filename, nPrefix);
        blob_append(&filename, pFile->zName, -1);
        zName = blob_str(&filename);
        tar_add_file(zName, &file, manifest_file_mperm(pFile), mTime);
        blob_reset(&file);
      }
    }
  }else{
    sha1sum_blob(&mfile, &hash);
    blob_append(&filename, blob_str(&hash), 16);
    zName = blob_str(&filename);
    mTime = db_int64(0, "SELECT (julianday('now') -  2440587.5)*86400.0;");
    tar_begin(mTime);
    tar_add_file(zName, &mfile, 0, mTime);
  }
  manifest_destroy(pManifest);
  blob_reset(&mfile);
  blob_reset(&filename);
  tar_finish(pTar);
}