コード例 #1
0
ファイル: clone.c プロジェクト: jwes/luagi
static void parse_options( git_clone_options* options, lua_State *L, const int tableIndex )
{
   if( ! lua_istable( L, tableIndex ) )
   {
      git_clone_init_options( options, GIT_CLONE_OPTIONS_VERSION );
      return;
   }

   lua_getfield( L, tableIndex, LUAGI_CLONE_OPTS_VERSION );
   int version = luaL_optinteger( L, -1, GIT_CLONE_OPTIONS_VERSION );

   git_clone_init_options( options, version );

   lua_getfield( L, tableIndex, LUAGI_CLONE_OPTS_CHECKOUT_OPTS );
   if( lua_istable( L, -1 ) )
   {
      git_checkout_options opts;
      luagi_parse_checkout_options( &opts, L, -1 );
      options->checkout_opts = opts;
   }
   else
   {
      lua_pop( L, -1 );
   }

   lua_getfield( L, tableIndex, LUAGI_CLONE_OPTS_BARE );
   options->bare = luaL_optinteger( L, -1, 0 );
   lua_getfield( L, tableIndex, LUAGI_CLONE_OPTS_CHECKOUT_BRANCH );
   options->checkout_branch = luaL_optstring(L, -1, NULL );
}
コード例 #2
0
ファイル: qgit.cpp プロジェクト: bokic/gitmaster
void QGit::clone(QUrl url)
{
    git_repository *repo = nullptr;
    git_clone_options opts;
#if LIBGIT2_SOVERSION <= 22
    git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
#endif
    int res = 0;

    QGitError error;

    try {

        res = git_clone_init_options(&opts, GIT_CLONE_OPTIONS_VERSION);
        if (res)
        {
            throw QGitError("git_clone_init_options", res);
        }

#if LIBGIT2_SOVERSION > 22
        opts.fetch_opts.callbacks.payload = this;
        opts.fetch_opts.callbacks.transfer_progress = [](const git_transfer_progress *stats, void *payload) -> int {

            auto _this = static_cast<QGit *>(payload);

            emit _this->cloneTransferReply(stats->total_objects, stats->indexed_objects, stats->received_objects, stats->local_objects, stats->total_deltas, stats->indexed_deltas, stats->received_bytes);

            return _this->m_abort;
        };
#else
        callbacks.payload = this;
        callbacks.transfer_progress = [](const git_transfer_progress *stats, void *payload) -> int {

            QGit *_this =  static_cast<QGit *>(payload);

			emit _this->cloneTransferReply(stats->total_objects, stats->indexed_objects, stats->received_objects, stats->local_objects, stats->total_deltas, stats->indexed_deltas, stats->received_bytes);

            return _this->m_abort;
        };

        opts.remote_callbacks = callbacks;
#endif
        opts.checkout_opts.progress_payload = this;
        opts.checkout_opts.progress_cb = [](
                const char *path,
                size_t completed_steps,
                size_t total_steps,
                void *payload)
        {
            auto _this = static_cast<QGit *>(payload);

            emit _this->cloneProgressReply(QString::fromUtf8(path), completed_steps, total_steps);

            _this = nullptr;
        };

        m_abort = 0;

        res = git_clone(&repo, url.toString().toUtf8().constData(), m_path.absolutePath().toUtf8().constData(), &opts);
        if (res)
        {
            throw QGitError("git_clone", res);
        }

    } catch(const QGitError &ex) {
        error = ex;
    }

    emit cloneReply(error);

    if (repo)
    {
        git_repository_free(repo);
        repo = nullptr;
    }
}