static int l_list (lua_State *L) { const char *path = (lua_gettop (L) < 1 || lua_isnil (L, 1)) ? "" : luaL_checkstring (L, 1); svn_opt_revision_t revision; svn_opt_revision_t peg_revision; peg_revision.kind = svn_opt_revision_unspecified; if (lua_gettop (L) < 2 || lua_isnil (L, 2)) { revision.kind = get_revision_kind (path); } else { revision.kind = svn_opt_revision_number; revision.value.number = lua_tointeger (L, 2); } apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); path = svn_path_canonicalize (path, pool); lua_newtable (L); err = svn_client_list (path, &peg_revision, &revision, TRUE, SVN_DIRENT_ALL, TRUE, list_func, L, ctx, pool); IF_ERROR_RETURN (err, pool, L); svn_pool_destroy (pool); return 1; }
static int l_revprop_list (lua_State *L) { const char *url = luaL_checkstring (L, 1); svn_opt_revision_t revision; if (lua_gettop (L) < 2 || lua_isnil (L, 2)) { revision.kind = get_revision_kind (url); } else { revision.kind = svn_opt_revision_number; revision.value.number = lua_tointeger (L, 2); } apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); url = svn_path_canonicalize (url, pool); apr_hash_t *entries; apr_hash_index_t *hi; void *val; const void *key; svn_revnum_t rev; err = svn_client_revprop_list (&entries, url, &revision, &rev, ctx, pool); IF_ERROR_RETURN (err, pool, L); lua_newtable (L); for (hi = apr_hash_first (pool, entries); hi; hi = apr_hash_next (hi)) { const char *pname; svn_string_t *pval; apr_hash_this (hi, &key, NULL, &val); pname = key; pval = (svn_string_t *) val; if (svn_prop_needs_translation (pname)) { err = svn_subst_translate_string (&pval, pval, APR_LOCALE_CHARSET, pool); IF_ERROR_RETURN (err, pool, L); } err = svn_cmdline_cstring_from_utf8 (&pname, pname, pool); IF_ERROR_RETURN (err, pool, L); lua_pushstring (L, pval->data); lua_setfield (L, -2, pname); } svn_pool_destroy (pool); return 1; }
static int l_revprop_set (lua_State *L) { apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; svn_opt_revision_t revision; svn_revnum_t rev; const char *url = luaL_checkstring (L, 1); const char *propname = luaL_checkstring (L, 2); const char *propval = lua_isnil (L, 3) ? NULL : luaL_checkstring (L, 3); const char *propname_utf8 = NULL; int itable = 5; svn_boolean_t force = FALSE; if (lua_gettop (L) < 4 || lua_isnil (L, 4)) { revision.kind = get_revision_kind (url); } else { revision.kind = svn_opt_revision_number; revision.value.number = lua_tointeger (L, 4); } if (lua_gettop (L) >= itable && lua_istable (L, itable)) { lua_getfield (L, itable, "force"); if (lua_isboolean (L, -1)) { force = lua_toboolean (L, -1); } } init_function (&ctx, &pool, L); url = svn_path_canonicalize (url, pool); err = svn_utf_cstring_to_utf8 (&propname_utf8, propname, pool); IF_ERROR_RETURN (err, pool, L); if (propval != NULL) { svn_string_t *sstring = svn_string_create (propval, pool); if (svn_prop_needs_translation (propname_utf8)) { err = svn_subst_translate_string (&sstring, sstring, APR_LOCALE_CHARSET, pool); IF_ERROR_RETURN (err, pool, L); } err = svn_client_revprop_set (propname_utf8, sstring, url, &revision, &rev, force, ctx, pool); } else { err = svn_client_revprop_set (propname_utf8, NULL, url, &revision, &rev, force, ctx, pool); } IF_ERROR_RETURN (err, pool, L); svn_pool_destroy (pool); return 0; }
static int l_list (lua_State *L) { const char *path = (lua_gettop (L) < 1 || lua_isnil (L, 1)) ? "" : luaL_checkstring (L, 1); svn_opt_revision_t revision; svn_opt_revision_t peg_revision; peg_revision.kind = svn_opt_revision_unspecified; if (lua_gettop (L) < 2 || lua_isnil (L, 2)) { revision.kind = get_revision_kind (path); } else { revision.kind = svn_opt_revision_number; revision.value.number = lua_tointeger (L, 2); } svn_boolean_t recursive = FALSE; svn_boolean_t fetch_locks = FALSE; int itable = 3; if (lua_gettop (L) >= itable && lua_istable (L, itable)) { lua_getfield (L, itable, "recursive"); if (lua_isboolean (L, -1)) { recursive = lua_toboolean (L, -1); } lua_getfield (L, itable, "fetch_locks"); if (lua_isboolean (L, -1)) { fetch_locks = lua_toboolean (L, -1); } } apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); path = svn_path_canonicalize (path, pool); lua_newtable (L); err = svn_client_list (path, &peg_revision, &revision, recursive, SVN_DIRENT_ALL, fetch_locks, list_func, L, ctx, pool); IF_ERROR_RETURN (err, pool, L); svn_pool_destroy (pool); return 1; }
static int l_log (lua_State *L) { const char *path = (lua_gettop (L) < 1 || lua_isnil (L, 1)) ? "" : luaL_checkstring (L, 1); svn_opt_revision_t start, end; svn_opt_revision_t peg_revision; peg_revision.kind = svn_opt_revision_unspecified; start.kind = svn_opt_revision_number; if (lua_gettop (L) < 2 || lua_isnil (L, 2)) { start.value.number = 0; } else { start.value.number = lua_tointeger (L, 2); } if (lua_gettop (L) < 3 || lua_isnil (L, 3)) { end.kind = get_revision_kind (path); } else { end.kind = svn_opt_revision_number; end.value.number = lua_tointeger (L, 3); } apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); path = svn_path_canonicalize (path, pool); apr_array_header_t *array; array = apr_array_make (pool, 1, sizeof (const char *)); (*((const char **) apr_array_push (array))) = path; const int limit = 0; lua_newtable (L); err = svn_client_log3 (array, &peg_revision, &start, &end, limit, FALSE, FALSE, log_receiver, L, ctx, pool); IF_ERROR_RETURN (err, pool, L); svn_pool_destroy (pool); return 1; }
static int l_revprop_get (lua_State *L) { const char *url = luaL_checkstring (L, 1); const char *propname = luaL_checkstring (L, 2); svn_opt_revision_t revision; if (lua_gettop (L) < 3 || lua_isnil (L, 3)) { revision.kind = get_revision_kind (url); } else { revision.kind = svn_opt_revision_number; revision.value.number = lua_tointeger (L, 3); } apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); url = svn_path_canonicalize (url, pool); const char *propname_utf8; err = svn_utf_cstring_to_utf8 (&propname_utf8, propname, pool); IF_ERROR_RETURN (err, pool, L); svn_string_t *propval; svn_revnum_t rev; err = svn_client_revprop_get (propname_utf8, &propval, url, &revision, &rev, ctx, pool); IF_ERROR_RETURN (err, pool, L); svn_string_t *printable_val = propval; if (svn_prop_needs_translation (propname_utf8)) { err = svn_subst_detranslate_string (&printable_val, propval, TRUE, pool); IF_ERROR_RETURN (err, pool, L); } lua_pushstring (L, printable_val->data); svn_pool_destroy (pool); return 1; }
static int l_cat (lua_State *L) { const char *path = luaL_checkstring (L, 1); svn_opt_revision_t peg_revision; svn_opt_revision_t revision; peg_revision.kind = svn_opt_revision_unspecified; if (lua_gettop (L) < 2 || lua_isnil (L, 2)) { revision.kind = get_revision_kind (path); } else { revision.kind = svn_opt_revision_number; revision.value.number = lua_tointeger (L, 2); } apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); path = svn_path_canonicalize (path, pool); svn_stream_t *stream; stream = svn_stream_empty (pool); svn_stream_set_write (stream, write_fn); svn_stringbuf_t *buffer = svn_stringbuf_create ("\0", pool); svn_stream_set_baton (stream, buffer); err = svn_client_cat2 (stream, path, &peg_revision, &revision, ctx, pool); IF_ERROR_RETURN (err, pool, L); lua_pushstring (L, buffer->data); svn_pool_destroy (pool); return 1; }
static int l_diff (lua_State *L) { const char *path1 = (lua_gettop (L) < 1 || lua_isnil (L, 1)) ? "" : luaL_checkstring (L, 1); svn_opt_revision_t rev1; if (lua_gettop (L) < 2 || lua_isnil (L, 2)) { rev1.kind = get_revision_kind (path1); } else { rev1.kind = svn_opt_revision_number; rev1.value.number = lua_tointeger (L, 2); } const char *path2 = (lua_gettop (L) < 3 || lua_isnil (L, 3)) ? path1 : luaL_checkstring (L, 3); svn_opt_revision_t rev2; if (lua_gettop (L) < 4 || lua_isnil (L, 4)) { if (svn_path_is_url (path2)) { rev2.kind = svn_opt_revision_head; } else { rev2.kind = svn_opt_revision_working; } } else { rev2.kind = svn_opt_revision_number; rev2.value.number = lua_tointeger (L, 4); } const char *outfile = (lua_gettop (L) < 5 || lua_isnil (L, 5)) ? NULL : luaL_checkstring (L, 5); const char *errfile = (lua_gettop (L) < 6 || lua_isnil (L, 6)) ? NULL : luaL_checkstring (L, 6); apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); path1 = svn_path_canonicalize (path1, pool); path2 = svn_path_canonicalize (path2, pool); apr_file_t *aprout; apr_file_t *aprerr; apr_status_t status; if (outfile) { status = apr_file_open (&aprout, outfile, APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, pool); } else { status = apr_file_open_stdout(&aprout, pool); } if (status) { IF_ERROR_RETURN (svn_error_wrap_apr(status, "Can't open output file"), pool, L); } if (errfile) { status = apr_file_open (&aprerr, errfile, APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, pool); } else { status = apr_file_open_stderr(&aprerr, pool); } if (status) { IF_ERROR_RETURN (svn_error_wrap_apr(status, "Can't open error file"), pool , L); } apr_array_header_t *array; array = apr_array_make (pool, 0, sizeof (const char *)); err = svn_client_diff3 (array, path1, &rev1, path2, &rev2, TRUE, TRUE, FALSE, FALSE, APR_LOCALE_CHARSET, aprout, aprerr, ctx, pool); IF_ERROR_RETURN (err, pool, L); svn_pool_destroy (pool); return 0; }
static int l_log (lua_State *L) { const char *path = (lua_gettop (L) < 1 || lua_isnil (L, 1)) ? "" : luaL_checkstring (L, 1); svn_opt_revision_t start, end; svn_opt_revision_t peg_revision; peg_revision.kind = svn_opt_revision_unspecified; start.kind = svn_opt_revision_number; if (lua_gettop (L) < 2 || lua_isnil (L, 2)) { start.value.number = 0; } else { start.value.number = lua_tointeger (L, 2); } if (lua_gettop (L) < 3 || lua_isnil (L, 3)) { end.kind = get_revision_kind (path); } else { end.kind = svn_opt_revision_number; end.value.number = lua_tointeger (L, 3); } int limit = 0; if (lua_gettop (L) >= 4) { limit = lua_tointeger (L, 4); } svn_boolean_t discover_changed_paths = FALSE; svn_boolean_t stop_on_copy = FALSE; int itable = 5; if (lua_gettop (L) >= itable && lua_istable (L, itable)) { lua_getfield (L, itable, "discover_changed_paths"); if (lua_isboolean (L, -1)) { discover_changed_paths = lua_toboolean (L, -1); } lua_getfield (L, itable, "stop_on_copy"); if (lua_isboolean (L, -1)) { stop_on_copy = lua_toboolean (L, -1); } } apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); path = svn_path_canonicalize (path, pool); apr_array_header_t *array; array = apr_array_make (pool, 1, sizeof (const char *)); (*((const char **) apr_array_push (array))) = path; lua_newtable (L); err = svn_client_log3 (array, &peg_revision, &end, &start, limit, discover_changed_paths, stop_on_copy, log_receiver, L, ctx, pool); IF_ERROR_RETURN (err, pool, L); svn_pool_destroy (pool); return 1; }
static int l_diff (lua_State *L) { apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; apr_file_t *aprout; apr_file_t *aprerr; apr_status_t status; apr_array_header_t *array; svn_opt_revision_t rev1; svn_opt_revision_t rev2; const char *path1 = NULL; const char *path2 = NULL; const char *outfile = NULL; const char *errfile = NULL; int itable = 7; svn_boolean_t recursive = TRUE; svn_boolean_t ignore_ancestry = TRUE; svn_boolean_t no_diff_deleted = FALSE; svn_boolean_t force = FALSE; path1 = (lua_gettop (L) < 1 || lua_isnil (L, 1)) ? "" : luaL_checkstring (L, 1); if (lua_gettop (L) < 2 || lua_isnil (L, 2)) { rev1.kind = get_revision_kind (path1); } else { rev1.kind = svn_opt_revision_number; rev1.value.number = lua_tointeger (L, 2); } path2 = (lua_gettop (L) < 3 || lua_isnil (L, 3)) ? path1 : luaL_checkstring (L, 3); if (lua_gettop (L) < 4 || lua_isnil (L, 4)) { if (svn_path_is_url (path2)) { rev2.kind = svn_opt_revision_head; } else { rev2.kind = svn_opt_revision_working; } } else { rev2.kind = svn_opt_revision_number; rev2.value.number = lua_tointeger (L, 4); } outfile = (lua_gettop (L) < 5 || lua_isnil (L, 5)) ? NULL : luaL_checkstring (L, 5); errfile = (lua_gettop (L) < 6 || lua_isnil (L, 6)) ? NULL : luaL_checkstring (L, 6); if (lua_gettop (L) >= itable && lua_istable (L, itable)) { lua_getfield (L, itable, "recursive"); if (lua_isboolean (L, -1)) { recursive = lua_toboolean (L, -1); } lua_getfield (L, itable, "ignore_ancestry"); if (lua_isboolean (L, -1)) { ignore_ancestry = lua_toboolean (L, -1); } lua_getfield (L, itable, "no_diff_deleted"); if (lua_isboolean (L, -1)) { no_diff_deleted = lua_toboolean (L, -1); } lua_getfield (L, itable, "force"); if (lua_isboolean (L, -1)) { force = lua_toboolean (L, -1); } } init_function (&ctx, &pool, L); path1 = svn_path_canonicalize (path1, pool); path2 = svn_path_canonicalize (path2, pool); if (outfile) { status = apr_file_open (&aprout, outfile, APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, pool); } else { status = apr_file_open_stdout(&aprout, pool); } if (status) { IF_ERROR_RETURN (svn_error_wrap_apr(status, "Can't open output file"), pool, L); } if (errfile) { status = apr_file_open (&aprerr, errfile, APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, pool); } else { status = apr_file_open_stderr(&aprerr, pool); } if (status) { IF_ERROR_RETURN (svn_error_wrap_apr(status, "Can't open error file"), pool , L); } array = apr_array_make (pool, 0, sizeof (const char *)); err = svn_client_diff3 (array, path1, &rev1, path2, &rev2, recursive, ignore_ancestry, no_diff_deleted, force, APR_LOCALE_CHARSET, aprout, aprerr, ctx, pool); IF_ERROR_RETURN (err, pool, L); svn_pool_destroy (pool); return 0; }