You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2018/01/12 13:28:42 UTC
svn commit: r1820979 - in /subversion/branches/shelve-checkpoint/subversion:
include/svn_client.h libsvn_client/shelve.c svn/shelve-cmd.c
Author: julianfoad
Date: Fri Jan 12 13:28:42 2018
New Revision: 1820979
URL: http://svn.apache.org/viewvc?rev=1820979&view=rev
Log:
On the 'shelve-checkpoint' branch: refactor APIs to use a shelf-version object.
Modified:
subversion/branches/shelve-checkpoint/subversion/include/svn_client.h
subversion/branches/shelve-checkpoint/subversion/libsvn_client/shelve.c
subversion/branches/shelve-checkpoint/subversion/svn/shelve-cmd.c
Modified: subversion/branches/shelve-checkpoint/subversion/include/svn_client.h
URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/include/svn_client.h?rev=1820979&r1=1820978&r2=1820979&view=diff
==============================================================================
--- subversion/branches/shelve-checkpoint/subversion/include/svn_client.h (original)
+++ subversion/branches/shelve-checkpoint/subversion/include/svn_client.h Fri Jan 12 13:28:42 2018
@@ -6740,8 +6740,25 @@ typedef struct svn_client_shelf_t
apr_pool_t *pool;
} svn_client_shelf_t;
+/** One version of a shelved change-set.
+ *
+ * @since New in 1.X.
+ * @warning EXPERIMENTAL.
+ */
+typedef struct svn_client_shelf_version_t
+{
+ /* Public fields (read-only for public use) */
+ svn_client_shelf_t *shelf;
+ apr_time_t mtime; /** time-stamp of this version */
+
+ /* TODO: these should be Private fields */
+ const char *patch_abspath; /** abspath of the patch file */
+} svn_client_shelf_version_t;
+
/** Open an existing shelf or create a new shelf.
*
+ * The shelf should be closed after use by calling svn_client_shelf_close().
+ *
* @since New in 1.X.
* @warning EXPERIMENTAL.
*/
@@ -6755,6 +6772,8 @@ svn_client_shelf_open(svn_client_shelf_t
/** Close @a shelf.
*
+ * If @a shelf is NULL, do nothing; otherwise @a shelf must be an open shelf.
+ *
* @since New in 1.X.
* @warning EXPERIMENTAL.
*/
@@ -6793,76 +6812,77 @@ svn_client_shelf_save_new_version(svn_cl
const apr_array_header_t *changelists,
apr_pool_t *scratch_pool);
-/** Apply version @a version of @a shelf to the WC.
+/** Set the newest version of @a shelf to @a version.
+ *
+ * Delete all newer versions.
*
* @since New in 1.X.
* @warning EXPERIMENTAL.
*/
SVN_EXPERIMENTAL
svn_error_t *
-svn_client_shelf_apply(svn_client_shelf_t *shelf,
- int version,
- svn_boolean_t dry_run,
- apr_pool_t *scratch_pool);
+svn_client_shelf_set_current_version(svn_client_shelf_t *shelf,
+ int version,
+ apr_pool_t *scratch_pool);
-/** Reverse-apply the current version of @a shelf to the WC.
+/** Open an existing shelf version.
+ *
+ * There is no need to "close" it after use.
*
* @since New in 1.X.
* @warning EXPERIMENTAL.
*/
SVN_EXPERIMENTAL
svn_error_t *
-svn_client_shelf_unapply(svn_client_shelf_t *shelf,
- int version,
- svn_boolean_t dry_run,
- apr_pool_t *scratch_pool);
+svn_client_shelf_version_open(svn_client_shelf_version_t **shelf_version_p,
+ svn_client_shelf_t *shelf,
+ int version,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool);
-/** Set the current version of @a shelf. Delete all newer versions.
+/** Apply version @a version of @a shelf to the WC.
*
* @since New in 1.X.
* @warning EXPERIMENTAL.
*/
SVN_EXPERIMENTAL
svn_error_t *
-svn_client_shelf_set_current_version(svn_client_shelf_t *shelf,
- int version,
- apr_pool_t *scratch_pool);
+svn_client_shelf_apply(svn_client_shelf_version_t *shelf_version,
+ svn_boolean_t dry_run,
+ apr_pool_t *scratch_pool);
-/** Output version @a version of @a shelf as a patch to @a outstream.
+/** Reverse-apply the current version of @a shelf to the WC.
*
* @since New in 1.X.
* @warning EXPERIMENTAL.
*/
SVN_EXPERIMENTAL
svn_error_t *
-svn_client_shelf_export_patch(svn_client_shelf_t *shelf,
- int version,
- svn_stream_t *outstream,
- apr_pool_t *scratch_pool);
+svn_client_shelf_unapply(svn_client_shelf_version_t *shelf_version,
+ svn_boolean_t dry_run,
+ apr_pool_t *scratch_pool);
-/** Information about one version.
+/** Set @a *patch_abspath to the patch file path of @a shelf_version.
*
* @since New in 1.X.
* @warning EXPERIMENTAL.
*/
-typedef struct svn_client_shelf_version_info_t
-{
- const char *patch_abspath; /* abspath of the patch file */
- apr_time_t mtime; /* mtime of the patch file */
-} svn_client_shelf_version_info_t;
+SVN_EXPERIMENTAL
+svn_error_t *
+svn_client_shelf_get_patch_abspath(char **patch_abspath,
+ svn_client_shelf_version_t *shelf_version,
+ apr_pool_t *scratch_pool);
-/** Set @a *info to the files affected by the current version of @a shelf.
+/** Output version @a version of @a shelf as a patch to @a outstream.
*
* @since New in 1.X.
* @warning EXPERIMENTAL.
*/
SVN_EXPERIMENTAL
svn_error_t *
-svn_client_shelf_version_get_info(svn_client_shelf_version_info_t **info,
- svn_client_shelf_t *shelf,
- int version,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool);
+svn_client_shelf_export_patch(svn_client_shelf_version_t *shelf_version,
+ svn_stream_t *outstream,
+ apr_pool_t *scratch_pool);
/** Set @a *affected_paths to a hash with one entry for each path affected
* by the @a shelf @a version. The hash key is the old path and value is
@@ -6875,8 +6895,7 @@ svn_client_shelf_version_get_info(svn_cl
SVN_EXPERIMENTAL
svn_error_t *
svn_client_shelf_get_paths(apr_hash_t **affected_paths,
- svn_client_shelf_t *shelf,
- int version,
+ svn_client_shelf_version_t *shelf_version,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool);
Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_client/shelve.c
URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_client/shelve.c?rev=1820979&r1=1820978&r2=1820979&view=diff
==============================================================================
--- subversion/branches/shelve-checkpoint/subversion/libsvn_client/shelve.c (original)
+++ subversion/branches/shelve-checkpoint/subversion/libsvn_client/shelve.c Fri Jan 12 13:28:42 2018
@@ -390,19 +390,16 @@ svn_client_shelf_delete(const char *name
svn_error_t *
svn_client_shelf_get_paths(apr_hash_t **affected_paths,
- svn_client_shelf_t *shelf,
- int version,
+ svn_client_shelf_version_t *shelf_version,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
- const char *patch_abspath;
svn_patch_file_t *patch_file;
apr_pool_t *iterpool = svn_pool_create(scratch_pool);
apr_hash_t *paths = apr_hash_make(result_pool);
- SVN_ERR(get_existing_patch_abspath(&patch_abspath, shelf, version,
- result_pool, result_pool));
- SVN_ERR(svn_diff_open_patch_file(&patch_file, patch_abspath, result_pool));
+ SVN_ERR(svn_diff_open_patch_file(&patch_file, shelf_version->patch_abspath,
+ result_pool));
while (1)
{
@@ -427,41 +424,33 @@ svn_client_shelf_get_paths(apr_hash_t **
}
svn_error_t *
-svn_client_shelf_apply(svn_client_shelf_t *shelf,
- int version,
+svn_client_shelf_apply(svn_client_shelf_version_t *shelf_version,
svn_boolean_t dry_run,
apr_pool_t *scratch_pool)
{
- const char *patch_abspath;
-
- SVN_ERR(get_existing_patch_abspath(&patch_abspath, shelf, version,
- scratch_pool, scratch_pool));
- SVN_ERR(svn_client_patch(patch_abspath, shelf->wc_root_abspath,
+ SVN_ERR(svn_client_patch(shelf_version->patch_abspath,
+ shelf_version->shelf->wc_root_abspath,
dry_run, 0 /*strip*/,
FALSE /*reverse*/,
FALSE /*ignore_whitespace*/,
TRUE /*remove_tempfiles*/, NULL, NULL,
- shelf->ctx, scratch_pool));
+ shelf_version->shelf->ctx, scratch_pool));
return SVN_NO_ERROR;
}
svn_error_t *
-svn_client_shelf_unapply(svn_client_shelf_t *shelf,
- int version,
+svn_client_shelf_unapply(svn_client_shelf_version_t *shelf_version,
svn_boolean_t dry_run,
apr_pool_t *scratch_pool)
{
- const char *patch_abspath;
-
- SVN_ERR(get_existing_patch_abspath(&patch_abspath, shelf, version,
- scratch_pool, scratch_pool));
- SVN_ERR(svn_client_patch(patch_abspath, shelf->wc_root_abspath,
+ SVN_ERR(svn_client_patch(shelf_version->patch_abspath,
+ shelf_version->shelf->wc_root_abspath,
dry_run, 0 /*strip*/,
TRUE /*reverse*/,
FALSE /*ignore_whitespace*/,
TRUE /*remove_tempfiles*/, NULL, NULL,
- shelf->ctx, scratch_pool));
+ shelf_version->shelf->ctx, scratch_pool));
return SVN_NO_ERROR;
}
@@ -485,17 +474,22 @@ svn_client_shelf_set_current_version(svn
}
svn_error_t *
-svn_client_shelf_export_patch(svn_client_shelf_t *shelf,
- int version,
+svn_client_shelf_get_patch_abspath(char **patch_abspath,
+ svn_client_shelf_version_t *shelf_version,
+ apr_pool_t *scratch_pool)
+{
+ *patch_abspath = shelf_version->patch_abspath;
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_client_shelf_export_patch(svn_client_shelf_version_t *shelf_version,
svn_stream_t *outstream,
apr_pool_t *scratch_pool)
{
- const char *patch_abspath;
svn_stream_t *instream;
- SVN_ERR(get_existing_patch_abspath(&patch_abspath, shelf, version,
- scratch_pool, scratch_pool));
- SVN_ERR(svn_stream_open_readonly(&instream, patch_abspath,
+ SVN_ERR(svn_stream_open_readonly(&instream, shelf_version->patch_abspath,
scratch_pool, scratch_pool));
SVN_ERR(svn_stream_copy3(instream,
svn_stream_disown(outstream, scratch_pool),
@@ -632,24 +626,26 @@ svn_client_shelves_any(svn_boolean_t *an
}
svn_error_t *
-svn_client_shelf_version_get_info(svn_client_shelf_version_info_t **info_p,
- svn_client_shelf_t *shelf,
- int version,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
+svn_client_shelf_version_open(svn_client_shelf_version_t **shelf_version_p,
+ svn_client_shelf_t *shelf,
+ int version,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool)
{
- svn_client_shelf_version_info_t *info
- = apr_palloc(result_pool, sizeof(*info));
+ svn_client_shelf_version_t *shelf_version
+ = apr_palloc(result_pool, sizeof(*shelf_version));
const svn_io_dirent2_t *dirent;
- SVN_ERR(get_existing_patch_abspath(&info->patch_abspath, shelf, version,
+ shelf_version->shelf = shelf;
+ SVN_ERR(get_existing_patch_abspath(&shelf_version->patch_abspath,
+ shelf, version,
result_pool, scratch_pool));
SVN_ERR(svn_io_stat_dirent2(&dirent,
- info->patch_abspath,
+ shelf_version->patch_abspath,
FALSE /*verify_truename*/,
TRUE /*ignore_enoent*/,
result_pool, scratch_pool));
- info->mtime = dirent->mtime;
- *info_p = info;
+ shelf_version->mtime = dirent->mtime;
+ *shelf_version_p = shelf_version;
return SVN_NO_ERROR;
}
Modified: subversion/branches/shelve-checkpoint/subversion/svn/shelve-cmd.c
URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/svn/shelve-cmd.c?rev=1820979&r1=1820978&r2=1820979&view=diff
==============================================================================
--- subversion/branches/shelve-checkpoint/subversion/svn/shelve-cmd.c (original)
+++ subversion/branches/shelve-checkpoint/subversion/svn/shelve-cmd.c Fri Jan 12 13:28:42 2018
@@ -74,13 +74,18 @@ friendly_duration_str(apr_time_t duratio
/* Print some details of the changes in the patch described by INFO.
*/
static svn_error_t *
-show_diffstat(const svn_client_shelf_version_info_t *info,
+show_diffstat(svn_client_shelf_version_t *shelf_version,
apr_pool_t *scratch_pool)
{
#ifndef WIN32
- int result = system(apr_psprintf(scratch_pool,
- "diffstat -p0 '%s' 2> /dev/null",
- info->patch_abspath));
+ char *patch_abspath;
+ int result;
+
+ SVN_ERR(svn_client_shelf_get_patch_abspath(&patch_abspath, shelf_version,
+ scratch_pool));
+ result = system(apr_psprintf(scratch_pool,
+ "diffstat -p0 '%s' 2> /dev/null",
+ patch_abspath));
if (result == 0)
SVN_ERR(svn_cmdline_printf(scratch_pool, "\n"));
#endif
@@ -126,18 +131,18 @@ stats(svn_client_shelf_t *shelf,
svn_boolean_t with_logmsg,
apr_pool_t *scratch_pool)
{
- svn_client_shelf_version_info_t *info;
+ svn_client_shelf_version_t *shelf_version;
char *age_str;
char *version_str;
apr_hash_t *paths;
const char *paths_str = "";
char *info_str;
- SVN_ERR(svn_client_shelf_version_get_info(&info,
- shelf, version,
- scratch_pool, scratch_pool));
+ SVN_ERR(svn_client_shelf_version_open(&shelf_version,
+ shelf, version,
+ scratch_pool, scratch_pool));
- age_str = friendly_duration_str(time_now - info->mtime, scratch_pool);
+ age_str = friendly_duration_str(time_now - shelf_version->mtime, scratch_pool);
if (version == shelf->max_version)
version_str = apr_psprintf(scratch_pool,
_("version %d"), version);
@@ -146,8 +151,7 @@ stats(svn_client_shelf_t *shelf,
_("version %d of %d"),
version, shelf->max_version);
SVN_ERR(svn_client_shelf_get_paths(&paths,
- shelf, shelf->max_version,
- scratch_pool, scratch_pool));
+ shelf_version, scratch_pool, scratch_pool));
if (paths)
paths_str = apr_psprintf(scratch_pool,
_(", %d paths changed"), apr_hash_count(paths));
@@ -195,18 +199,18 @@ shelves_list(const char *local_abspath,
const svn_sort__item_t *item = &APR_ARRAY_IDX(list, i, svn_sort__item_t);
const char *name = item->key;
svn_client_shelf_t *shelf;
- svn_client_shelf_version_info_t *info;
+ svn_client_shelf_version_t *shelf_version;
SVN_ERR(svn_client_shelf_open(&shelf,
name, local_abspath, ctx, scratch_pool));
- SVN_ERR(svn_client_shelf_version_get_info(&info,
- shelf, shelf->max_version,
- scratch_pool, scratch_pool));
+ SVN_ERR(svn_client_shelf_version_open(&shelf_version,
+ shelf, shelf->max_version,
+ scratch_pool, scratch_pool));
SVN_ERR(stats(shelf, shelf->max_version, time_now,
with_logmsg, scratch_pool));
if (with_diffstat)
{
- SVN_ERR(show_diffstat(info, scratch_pool));
+ SVN_ERR(show_diffstat(shelf_version, scratch_pool));
}
SVN_ERR(svn_client_shelf_close(shelf, scratch_pool));
}
@@ -232,16 +236,16 @@ shelf_log(const char *name,
for (i = 1; i <= shelf->max_version; i++)
{
- svn_client_shelf_version_info_t *info;
+ svn_client_shelf_version_t *shelf_version;
- SVN_ERR(svn_client_shelf_version_get_info(&info,
- shelf, i,
- scratch_pool, scratch_pool));
+ SVN_ERR(svn_client_shelf_version_open(&shelf_version,
+ shelf, i,
+ scratch_pool, scratch_pool));
SVN_ERR(stats(shelf, i, time_now,
FALSE /*with_logmsg*/, scratch_pool));
if (with_diffstat)
{
- SVN_ERR(show_diffstat(info, scratch_pool));
+ SVN_ERR(show_diffstat(shelf_version, scratch_pool));
}
}
@@ -316,9 +320,14 @@ shelve(int *new_version_p,
if (!keep_local)
{
+ svn_client_shelf_version_t *shelf_version;
+
/* Reverse-apply the patch. This should be a safer way to remove those
changes from the WC than running a 'revert' operation. */
- SVN_ERR(svn_client_shelf_unapply(shelf, shelf->max_version,
+ SVN_ERR(svn_client_shelf_version_open(&shelf_version,
+ shelf, shelf->max_version,
+ scratch_pool, scratch_pool));
+ SVN_ERR(svn_client_shelf_unapply(shelf_version,
dry_run, scratch_pool));
}
@@ -409,8 +418,7 @@ modification_checker(void *baton,
/* Throw an error if any paths affected by SHELF:VERSION are currently
* modified in the WC. */
static svn_error_t *
-check_no_modified_paths(svn_client_shelf_t *shelf,
- int version,
+check_no_modified_paths(svn_client_shelf_version_t *shelf_version,
svn_boolean_t verbose,
svn_client_ctx_t *ctx,
apr_pool_t *scratch_pool)
@@ -425,13 +433,13 @@ check_no_modified_paths(svn_client_shelf
sb.modified = &any_modified;
sb.ctx = ctx;
- SVN_ERR(svn_client_shelf_get_paths(&paths,
- shelf, version,
+ SVN_ERR(svn_client_shelf_get_paths(&paths, shelf_version,
scratch_pool, scratch_pool));
for (hi = apr_hash_first(scratch_pool, paths); hi; hi = apr_hash_next(hi))
{
const char *path = apr_hash_this_key(hi);
- const char *abspath = svn_path_join(shelf->wc_root_abspath, path, scratch_pool);
+ const char *abspath = svn_path_join(shelf_version->shelf->wc_root_abspath,
+ path, scratch_pool);
sb.target_abspath = abspath;
sb.target_path = abspath;
@@ -477,6 +485,7 @@ shelf_restore(const char *name,
int version, old_version;
apr_time_t time_now = apr_time_now();
svn_client_shelf_t *shelf;
+ svn_client_shelf_version_t *shelf_version;
SVN_ERR(svn_client_shelf_open(&shelf, name, local_abspath,
ctx, scratch_pool));
@@ -505,9 +514,12 @@ shelf_restore(const char *name,
SVN_ERR(stats(shelf, version, time_now,
TRUE /*with_logmsg*/, scratch_pool));
}
- SVN_ERR(check_no_modified_paths(shelf, version, !quiet, ctx, scratch_pool));
+ SVN_ERR(svn_client_shelf_version_open(&shelf_version,
+ shelf, version,
+ scratch_pool, scratch_pool));
+ SVN_ERR(check_no_modified_paths(shelf_version, !quiet, ctx, scratch_pool));
- SVN_ERR(svn_client_shelf_apply(shelf, version,
+ SVN_ERR(svn_client_shelf_apply(shelf_version,
dry_run, scratch_pool));
if (! dry_run)
@@ -541,6 +553,7 @@ shelf_diff(const char *name,
{
int version;
svn_client_shelf_t *shelf;
+ svn_client_shelf_version_t *shelf_version;
svn_stream_t *stream;
SVN_ERR(svn_client_shelf_open(&shelf, name, local_abspath,
@@ -560,9 +573,12 @@ shelf_diff(const char *name,
{
version = shelf->max_version;
}
+ SVN_ERR(svn_client_shelf_version_open(&shelf_version,
+ shelf, version,
+ scratch_pool, scratch_pool));
SVN_ERR(svn_stream_for_stdout(&stream, scratch_pool));
- SVN_ERR(svn_client_shelf_export_patch(shelf, version, stream,
+ SVN_ERR(svn_client_shelf_export_patch(shelf_version, stream,
scratch_pool));
SVN_ERR(svn_stream_close(stream));