std::vector<svn_revnum_t>
  Client::update(const Targets & targets,
                 const Revision & revision,
                 bool recurse,
                 bool ignore_externals) throw(ClientException)
  {
    Pool pool;
    apr_array_header_t * result_revs;

    svn_error_t * error =
      svn_client_update2(&result_revs,
                         const_cast<apr_array_header_t*>(targets.array(pool)),
                         revision.revision(),
                         recurse,
                         ignore_externals,
                         *m_context,
                         pool);
    if (error != NULL)
      throw ClientException(error);

    std::vector<svn_revnum_t> revnums;
    int i;
    for (i = 0; i < result_revs->nelts; i++)
    {
      svn_revnum_t revnum=
        APR_ARRAY_IDX(result_revs, i, svn_revnum_t);

      revnums.push_back(revnum);
    }

    return revnums;
  }
Beispiel #2
0
  std::pair<svn_revnum_t,std::string>
  Client::revpropget(const char *propName,
                     const Path &path,
                     const Revision &revision)
  {
    Pool pool;

    svn_string_t *propval;
    svn_revnum_t revnum;
    svn_error_t * error =
      svn_client_revprop_get(propName,
                             &propval,
                             path.c_str(),
                             revision.revision(),
                             &revnum,
                             *m_context,
                             pool);
    if (error != nullptr)
    {
      throw ClientException(error);
    }

    // if the property does not exist NULL is returned
    if (propval == nullptr)
      return std::pair<svn_revnum_t,std::string> (0, std::string());

    return std::pair<svn_revnum_t,std::string> (revnum, std::string(propval->data));
  }
Beispiel #3
0
  std::string
  Client::cat(const Path & path,
              const Revision & revision,
              const Revision & peg_revision) throw(ClientException)
  {
    Pool pool;

    svn_stringbuf_t * stringbuf = svn_stringbuf_create("", pool);
    svn_stream_t * stream = svn_stream_from_stringbuf(stringbuf, pool);

    svn_error_t * error;
    error = svn_client_cat2(stream,
                            path.c_str(),
                            peg_revision.revision(),
                            revision.revision(),
                            *m_context,
                            pool);

    if (error != 0)
      throw ClientException(error);

    return std::string(stringbuf->data, stringbuf->len);
  }
Beispiel #4
0
  InfoVector
  Client::info(const Path & pathOrUrl,
               bool recurse,
               const Revision & revision,
               const Revision & pegRevision) throw(ClientException)
  {
    Pool pool;
    InfoVector infoVector;

    svn_error_t * error =
      svn_client_info(pathOrUrl.c_str(),
                      pegRevision.revision(),
                      revision.revision(),
                      infoReceiverFunc,
                      &infoVector,
                      recurse,
                      *m_context,
                      pool);

    if (error != 0)
      throw ClientException(error);

    return infoVector;
  }
Beispiel #5
0
  /**
   * lists properties in @a path no matter whether local or
   * repository
   *
   * @param path
   * @param revision
   * @param recurse
   * @return PropertiesList
   */
  PathPropertiesMapList
  Client::proplist(const Path & path,
                   const Revision & revision,
                   bool recurse)
  {
    Pool pool;
    apr_array_header_t * props;

    svn_error_t * error =
      svn_client_proplist(&props,
                          path.c_str(),
                          revision.revision(),
                          recurse,
                          *m_context,
                          pool);
    if (error != nullptr)
    {
      throw ClientException(error);
    }

    PathPropertiesMapList path_prop_map_list;
    for (int j = 0; j < props->nelts; ++j)
    {
      svn_client_proplist_item_t *item =
        ((svn_client_proplist_item_t **)props->elts)[j];

      PropertiesMap prop_map;

      apr_hash_index_t *hi;
      for (hi = apr_hash_first(pool, item->prop_hash); hi;
           hi = apr_hash_next(hi))
      {
        const void *key;
        void *val;

        apr_hash_this(hi, &key, nullptr, &val);

        prop_map [std::string((const char *)key)] =
          std::string(((const svn_string_t *)val)->data);
      }

      path_prop_map_list.push_back(PathPropertiesMapEntry(item->node_name->data, prop_map));
    }

    return path_prop_map_list;
  }
  void
  Client::copy(const Path & srcPath,
               const Revision & srcRevision,
               const Path & destPath) throw(ClientException)
  {
    Pool pool;
    svn_client_commit_info_t *commit_info = NULL;
    svn_error_t * error =
      svn_client_copy(&commit_info,
                      srcPath.c_str(),
                      srcRevision.revision(),
                      destPath.c_str(),
                      *m_context,
                      pool);

    if (error != NULL)
      throw ClientException(error);
  }
Beispiel #7
0
  PathPropertiesMapList
  Client::propget(const char *propName,
                  const Path &path,
                  const Revision &revision,
                  bool recurse)
  {
    Pool pool;

    apr_hash_t *props;
    svn_error_t * error =
      svn_client_propget(&props,
                         propName,
                         path.c_str(),
                         revision.revision(),
                         recurse,
                         *m_context,
                         pool);
    if (error != nullptr)
    {
      throw ClientException(error);
    }

    PathPropertiesMapList path_prop_map_list;


    apr_hash_index_t *hi;
    for (hi = apr_hash_first(pool, props); hi;
         hi = apr_hash_next(hi))
    {
      PropertiesMap prop_map;

      const void *key;
      void *val;

      apr_hash_this(hi, &key, nullptr, &val);

      prop_map [std::string(propName)] = std::string(((const svn_string_t *)val)->data);

      path_prop_map_list.push_back(PathPropertiesMapEntry((const char *)key, prop_map));
    }

    return path_prop_map_list;
  }
Beispiel #8
0
void SVNRepos::deltify(File &path, Revision &revStart, Revision &revEnd)
{
  SVN::Pool requestPool;
  svn_repos_t *repos;
  svn_fs_t *fs;
  svn_revnum_t start = SVN_INVALID_REVNUM, end = SVN_INVALID_REVNUM;
  svn_revnum_t youngest, revision;
  SVN::Pool revisionPool;

  if (path.isNull())
    {
      JNIUtil::throwNullPointerException("path");
      return;
    }

  SVN_JNI_ERR(svn_repos_open3(&repos,
                              path.getInternalStyle(requestPool), NULL,
                              requestPool.getPool(),
                              requestPool.getPool()), );
  fs = svn_repos_fs(repos);
  SVN_JNI_ERR(svn_fs_youngest_rev(&youngest, fs, requestPool.getPool()), );

  if (revStart.revision()->kind == svn_opt_revision_number)
    /* ### We only handle revision numbers right now, not dates. */
    start = revStart.revision()->value.number;
  else if (revStart.revision()->kind == svn_opt_revision_head)
    start = youngest;
  else
    start = SVN_INVALID_REVNUM;

  if (revEnd.revision()->kind == svn_opt_revision_number)
    end = revEnd.revision()->value.number;
  else if (revEnd.revision()->kind == svn_opt_revision_head)
    end = youngest;
  else
    end = SVN_INVALID_REVNUM;

  /* Fill in implied revisions if necessary. */
  if (start == SVN_INVALID_REVNUM)
    start = youngest;
  if (end == SVN_INVALID_REVNUM)
    end = start;

  if (start > end)
    {
      SVN_JNI_ERR(svn_error_create
                  (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
                   _("First revision cannot be higher than second")), );
    }
  svn_revnum_t
  Client::doSwitch(const Path & path,
                   const char * url,
                   const Revision & revision,
                   bool recurse) throw(ClientException)
  {
    Pool pool;
    svn_revnum_t revnum = 0;
    svn_error_t * error =
      svn_client_switch(&revnum,
                        path.c_str(),
                        url,
                        revision.revision(),
                        recurse,
                        *m_context,
                        pool);

    if (error != NULL)
      throw ClientException(error);
    return revnum;
  }
Beispiel #10
0
  /**
   * delete property in @a path no matter whether local or
   * repository
   *
   * @param path
   * @param revision
   * @param propName
   * @param propValue
   * @param recurse
   * @param revprop
   * @return PropertiesList
   */
  svn_revnum_t
  Client::revpropdel(const char *propName,
                     const Path &path,
                     const Revision &revision,
                     bool force)
  {
    Pool pool;

    svn_revnum_t revnum;
    svn_error_t * error =
      svn_client_revprop_set(propName,
                             nullptr, // value = NULL
                             path.c_str(),
                             revision.revision(),
                             &revnum,
                             force,
                             *m_context,
                             pool);
    if (error != nullptr)
      throw ClientException(error);

    return revnum;
  }
Beispiel #11
0
  /**
   * lists revision properties in @a path no matter whether local or
   * repository
   *
   * @param path
   * @param revision
   * @param recurse
   * @return PropertiesList
   */
  std::pair<svn_revnum_t,PropertiesMap>
  Client::revproplist(const Path &path,
                      const Revision &revision)
  {
    Pool pool;

    apr_hash_t * props;
    svn_revnum_t revnum;
    svn_error_t * error =
      svn_client_revprop_list(&props,
                              path.c_str(),
                              revision.revision(),
                              &revnum,
                              *m_context,
                              pool);
    if (error != nullptr)
    {
      throw ClientException(error);
    }

    PropertiesMap prop_map;

    apr_hash_index_t *hi;
    for (hi = apr_hash_first(pool, props); hi;
         hi = apr_hash_next(hi))
    {
      const void *key;
      void *val;

      apr_hash_this(hi, &key, nullptr, &val);

      prop_map [std::string((const char *)key)] =
        std::string(((const svn_string_t *)val)->data);
    }

    return std::pair<svn_revnum_t,PropertiesMap> (revnum, prop_map);
  }
Beispiel #12
0
void SVNAdmin::deltify(const char *path, Revision &revStart, Revision &revEnd)
{
  Pool requestPool;
  SVN_JNI_NULL_PTR_EX(path, "path", );
  path = svn_path_internal_style(path, requestPool.pool());
  svn_repos_t *repos;
  svn_fs_t *fs;
  svn_revnum_t start = SVN_INVALID_REVNUM, end = SVN_INVALID_REVNUM;
  svn_revnum_t youngest, revision;
  Pool revisionPool;

  SVN_JNI_ERR(svn_repos_open(&repos, path, requestPool.pool()), );
  fs = svn_repos_fs (repos);
  SVN_JNI_ERR(svn_fs_youngest_rev(&youngest, fs, requestPool.pool()), );

  if (revStart.revision()->kind == svn_opt_revision_number)
    /* ### We only handle revision numbers right now, not dates. */
    start = revStart.revision()->value.number;
  else if (revStart.revision()->kind == svn_opt_revision_head)
    start = youngest;
  else
    start = SVN_INVALID_REVNUM;

  if (revEnd.revision()->kind == svn_opt_revision_number)
    end = revEnd.revision()->value.number;
  else if (revEnd.revision()->kind == svn_opt_revision_head)
    end = youngest;
  else
    end = SVN_INVALID_REVNUM;

  /* Fill in implied revisions if necessary. */
  if (start == SVN_INVALID_REVNUM)
    start = youngest;
  if (end == SVN_INVALID_REVNUM)
    end = start;

  if (start > end)
    {
      SVN_JNI_ERR(svn_error_create
                  (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
                   _("First revision cannot be higher than second")), );
    }
Beispiel #13
0
  std::string
  Client::diff(const Path & tmpPath, const Path & path,
               const Revision & revision1, const Revision & revision2,
               const bool recurse, const bool ignoreAncestry,
               const bool noDiffDeleted) throw(ClientException)
  {
    Pool pool;
    svn_error_t * error;
    apr_status_t status;
    apr_file_t * outfile = nullptr;
    const char * outfileName = nullptr;
    apr_file_t * errfile = nullptr;
    const char * errfileName = nullptr;
    apr_array_header_t * options;
    svn_stringbuf_t * stringbuf;

    // svn_client_diff needs an options array, even if it is empty
    options = apr_array_make(pool, 0, 0);

    // svn_client_diff needs a temporary file to write diff output to
    error = svn_io_open_unique_file(&outfile, &outfileName,
                                    tmpPath.c_str(), ".tmp",
                                    false, pool);

    if (error != nullptr)
    {
      diffCleanup(outfile, outfileName, errfile, errfileName, pool);
      throw ClientException(error);
    }

    // and another one to write errors to
    error = svn_io_open_unique_file(&errfile, &errfileName,
                                    tmpPath.c_str(), ".tmp",
                                    false, pool);

    if (error != nullptr)
    {
      diffCleanup(outfile, outfileName, errfile, errfileName, pool);
      throw ClientException(error);
    }

    // run diff
    error = svn_client_diff(options,
                            path.c_str(), revision1.revision(),
                            path.c_str(), revision2.revision(),
                            recurse, ignoreAncestry, noDiffDeleted,
                            outfile, errfile,
                            *m_context,
                            pool);

    if (error != nullptr)
    {
      diffCleanup(outfile, outfileName, errfile, errfileName, pool);
      throw ClientException(error);
    }

    // then we reopen outfile for reading
    status = apr_file_close(outfile);
    if (status)
    {
      diffCleanup(outfile, outfileName, errfile, errfileName, pool);
      fail(pool, status, "failed to close '%s'", outfileName);
    }

    status = apr_file_open(&outfile, outfileName, APR_READ, APR_OS_DEFAULT, pool);
    if (status)
    {
      diffCleanup(outfile, outfileName, errfile, errfileName, pool);
      fail(pool, status, "failed to open '%s'", outfileName);
    }

    // now we can read the diff output from outfile and return that
    error = svn_stringbuf_from_aprfile(&stringbuf, outfile, pool);

    if (error != nullptr)
    {
      diffCleanup(outfile, outfileName, errfile, errfileName, pool);
      throw ClientException(error);
    }

    diffCleanup(outfile, outfileName, errfile, errfileName, pool);
    return stringbuf->data;
  }
Beispiel #14
0
 Revision::Revision(const Revision & revision)
 {
   init(revision.revision());
 }