svnclient.cpp

来自「linux subdivision ying gai ke yi le ba」· C++ 代码 · 共 2,291 行 · 第 1/5 页

CPP
2,291
字号

        JNIEnv *env = JNIUtil::getEnv();
        jclass clazz = env->FindClass(JAVA_PACKAGE"/LogMessage");
        if(JNIUtil::isJavaExceptionThrown())
        {
            return NULL;
        }
        jobjectArray ret = env->NewObjectArray(size, clazz, NULL);
        if(JNIUtil::isJavaExceptionThrown())
        {
            return NULL;
        }
        env->DeleteLocalRef(clazz);
        if(JNIUtil::isJavaExceptionThrown())
        {
            return NULL;
        }
        for(int i = 0; i < size; i++)
        {
            jobject log = logs[i];
            env->SetObjectArrayElement(ret, i, log);
            if(JNIUtil::isJavaExceptionThrown())
            {
                return NULL;
            }
            env->DeleteLocalRef(log);
            if(JNIUtil::isJavaExceptionThrown())
            {
                return NULL;
            }
        }
        return ret;
    }
    else
    {
         JNIUtil::handleSVNError(Err);
        return NULL;
    }
}

jlong SVNClient::checkout(const char *moduleName, const char *destPath, 
                          Revision &revision, bool recurse)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();

    if(moduleName == NULL)
    {
        JNIUtil::throwNullPointerException("moduleName");
        return -1;
    }
    if(destPath == NULL)
    {
        JNIUtil::throwNullPointerException("destPath");
        return -1;
    }

    Path url(moduleName);
    Path path(destPath);
    svn_error_t *Err = url.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return -1;
    }
    Err = path.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return -1;
    }
    svn_revnum_t retval;

    svn_client_ctx_t *ctx = getContext(NULL);
    if(ctx == NULL)
    {
        return -1;
    }

	Err = svn_client_checkout (&retval, url.c_str(),
                                 path.c_str (),
                                 revision.revision (),
                                 recurse, ctx,
                                 apr_pool);

    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return -1;
    }
    return retval;

}

void SVNClient::notification(Notify *notify)
{
    delete m_notify;
    m_notify = notify;
}

void SVNClient::remove(Targets &targets, const char *message, bool force)
{
    svn_client_commit_info_t *commit_info = NULL;
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();
    svn_client_ctx_t *ctx = getContext(message);
    if(ctx == NULL)
    {
        return;
    }
    const apr_array_header_t *targets2 = targets.array(requestPool);
    svn_error_t *Err = targets.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return;
    }

    Err = svn_client_delete (&commit_info, 
                                          targets2, force,
                                          ctx, apr_pool);
    if(Err != NULL)
         JNIUtil::handleSVNError(Err);

}

void SVNClient::revert(const char *path, bool recurse)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();

    if(path == NULL)
    {
        JNIUtil::throwNullPointerException("path");
        return;
    }

    svn_client_ctx_t *ctx = getContext(NULL);
    Targets target (path);
    const apr_array_header_t *targets = target.array(requestPool);
    svn_error_t *Err = target.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return;
    }
    if(ctx == NULL)
    {
        return;
    }
    Err = svn_client_revert (targets, recurse, 
                                          ctx, apr_pool);

    if(Err != NULL)
         JNIUtil::handleSVNError(Err);

}

void SVNClient::add(const char *path, bool recurse)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();

    if(path == NULL)
    {
        JNIUtil::throwNullPointerException("path");
        return;
    }

    Path intPath(path);
    svn_error_t *Err = intPath.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return;
    }
    svn_client_ctx_t *ctx = getContext(NULL);
    if(ctx == NULL)
    {
        return;
    }
    Err = svn_client_add (intPath.c_str (), recurse, ctx, 
                                       apr_pool);

    if(Err != NULL)
         JNIUtil::handleSVNError(Err);
}

jlong SVNClient::update(const char *path, Revision &revision, bool recurse)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();

    if(path == NULL)
    {
        JNIUtil::throwNullPointerException("path");
        return -1;
    }

    Path intPath(path);
    svn_error_t *Err = intPath.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return -1;
    }
    svn_client_ctx_t *ctx = getContext(NULL);
    svn_revnum_t retval;
    if(ctx == NULL)
    {
        return -1;
    }
    Err = svn_client_update (&retval, intPath.c_str (),
                                          revision.revision (),
                                          recurse,
                                          ctx,
                                          apr_pool);
    if(Err != NULL)
    {
         JNIUtil::handleSVNError(Err);
        return -1;
    }

    return retval;

}

jlong SVNClient::commit(Targets &targets, const char *message, bool recurse)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();
    svn_client_commit_info_t *commit_info = NULL;
    const apr_array_header_t *targets2 = targets.array(requestPool);
    svn_error_t *Err = targets.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return NULL;
    }
    svn_client_ctx_t *ctx = getContext(message);
    if(ctx == NULL)
    {
        return -1;
    }
    Err = svn_client_commit (&commit_info,
                                          targets2,
                                          !recurse, ctx, apr_pool);
    if(Err != NULL)
         JNIUtil::handleSVNError(Err);

    if(commit_info && SVN_IS_VALID_REVNUM (commit_info->revision))
      return commit_info->revision;

    return -1;
}

void SVNClient::copy(const char *srcPath, const char *destPath, 
                     const char *message, Revision &revision)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();

    if(srcPath == NULL)
    {
        JNIUtil::throwNullPointerException("srcPath");
        return;
    }
    if(destPath == NULL)
    {
        JNIUtil::throwNullPointerException("destPath");
        return;
    }

    Path sourcePath(srcPath);
    svn_error_t *Err = sourcePath.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return;
    }
    Path destinationPath(destPath);
    Err = destinationPath.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return;
    }

    svn_client_commit_info_t *commit_info = NULL;
       svn_client_ctx_t *ctx = getContext(message);
    if(ctx == NULL)
    {
        return;
    }

    Err = svn_client_copy (&commit_info,
                             sourcePath.c_str (),
                             revision.revision(),
                             destinationPath.c_str (),
                             ctx,
                             apr_pool);
    if(Err != NULL)
         JNIUtil::handleSVNError(Err);

}

void SVNClient::move(const char *srcPath, const char *destPath, 
                     const char *message, Revision &revision, bool force)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();

    if(srcPath == NULL)
    {
        JNIUtil::throwNullPointerException("srcPath");
        return;
    }
    if(destPath == NULL)
    {
        JNIUtil::throwNullPointerException("destPath");
        return;
    }
    svn_client_commit_info_t *commit_info = NULL;
    Path sourcePath(srcPath);
    svn_error_t *Err = sourcePath.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return;
    }

    Path destinationPath(destPath);
    Err = destinationPath.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return;
    }

    svn_client_ctx_t *ctx = getContext(message);
    if(ctx == NULL)
    {
        return;
    }


    Err = svn_client_move (&commit_info,
                                        sourcePath.c_str (),
                                        revision.revision (),
                                        destinationPath.c_str (),
                                        force,
                                        ctx,
                                        apr_pool);
    if(Err != NULL)
         JNIUtil::handleSVNError(Err);
}

void SVNClient::mkdir(Targets &targets, const char *message)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();
    svn_client_commit_info_t *commit_info = NULL;
    svn_client_ctx_t *ctx = getContext(message);
    if(ctx == NULL)
    {
        return;
    }
    const apr_array_header_t *targets2 = targets.array(requestPool);
    svn_error_t *Err = targets.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return;
    }

    Err = svn_client_mkdir (&commit_info,
                                         targets2,
                                         ctx,
                                         apr_pool);

    if(Err != NULL)
         JNIUtil::handleSVNError(Err);

}

void SVNClient::cleanup(const char *path)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();
    if(path == NULL)
    {
        JNIUtil::throwNullPointerException("path");
        return;
    }
    Path intPath(path);
    svn_error_t *Err = intPath.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return;
    }

    svn_client_ctx_t *ctx = getContext(NULL);
    if(ctx == NULL)
    {
        return;
    }
    Err = svn_client_cleanup (intPath.c_str (), ctx, apr_pool);

    if(Err != NULL)
         JNIUtil::handleSVNError(Err);

}

void SVNClient::resolved(const char *path, bool recurse)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();
    if(path == NULL)
    {
        JNIUtil::throwNullPointerException("path");
        return;
    }
    Path intPath(path);
    svn_error_t *Err = intPath.error_occured();
    if(Err != NULL)
    {
        JNIUtil::handleSVNError(Err);
        return;
    }
    svn_client_ctx_t *ctx = getContext(NULL);
    if(ctx == NULL)
    {
        return;
    }
    Err = svn_client_resolved (intPath.c_str (),
                                            recurse,
                                            ctx,
                                            apr_pool);

    if(Err != NULL)
         JNIUtil::handleSVNError(Err);

}

jlong SVNClient::doExport(const char *srcPath, const char *destPath, 
                          Revision &revision,bool force)
{
    Pool requestPool;
    apr_pool_t * apr_pool = requestPool.pool ();
    if(srcPath == NULL)
    {
        JNIUtil::throwNullPointerException("srcPath");
        return -1;
    }
    if(destPath == NULL)
    {
        JNIUtil::throwNullPointerException("destPath");
        return -1;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?