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/23 13:50:58 UTC
svn commit: r1822006 - in /subversion/trunk/subversion: include/svn_client.h
libsvn_client/shelf.c svn/shelf-cmd.c
Author: julianfoad
Date: Tue Jan 23 13:50:57 2018
New Revision: 1822006
URL: http://svn.apache.org/viewvc?rev=1822006&view=rev
Log:
Shelving: consistently error on reading a nonexistent shelf.
* subversion/include/svn_client.h
(svn_client_shelf_open_existing): New.
* subversion/libsvn_client/shelf.c
(shelf_construct): New, factored out.
(svn_client_shelf_open_existing): New.
(svn_client_shelf_open): Use 'shelf_construct()'.
* subversion/svn/shelf-cmd.c
(shelves_list,
shelf_log,
shelf_restore,
shelf_diff): Use svn_client_shelf_open_existing().
Modified:
subversion/trunk/subversion/include/svn_client.h
subversion/trunk/subversion/libsvn_client/shelf.c
subversion/trunk/subversion/svn/shelf-cmd.c
Modified: subversion/trunk/subversion/include/svn_client.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_client.h?rev=1822006&r1=1822005&r2=1822006&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_client.h (original)
+++ subversion/trunk/subversion/include/svn_client.h Tue Jan 23 13:50:57 2018
@@ -6770,6 +6770,21 @@ svn_client_shelf_open(svn_client_shelf_t
svn_client_ctx_t *ctx,
apr_pool_t *result_pool);
+/** Open an existing shelf or error if it doesn't exist.
+ *
+ * The shelf should be closed after use by calling svn_client_shelf_close().
+ *
+ * @since New in 1.X.
+ * @warning EXPERIMENTAL.
+ */
+SVN_EXPERIMENTAL
+svn_error_t *
+svn_client_shelf_open_existing(svn_client_shelf_t **shelf_p,
+ const char *name,
+ const char *local_abspath,
+ svn_client_ctx_t *ctx,
+ apr_pool_t *result_pool);
+
/** Close @a shelf.
*
* If @a shelf is NULL, do nothing; otherwise @a shelf must be an open shelf.
Modified: subversion/trunk/subversion/libsvn_client/shelf.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/shelf.c?rev=1822006&r1=1822005&r2=1822006&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/shelf.c (original)
+++ subversion/trunk/subversion/libsvn_client/shelf.c Tue Jan 23 13:50:57 2018
@@ -393,12 +393,15 @@ write_patch(const char *patch_abspath,
return SVN_NO_ERROR;
}
-svn_error_t *
-svn_client_shelf_open(svn_client_shelf_t **shelf_p,
- const char *name,
- const char *local_abspath,
- svn_client_ctx_t *ctx,
- apr_pool_t *result_pool)
+/* Construct a shelf object representing an empty shelf: no versions,
+ * no revprops, no looking to see if such a shelf exists on disk.
+ */
+static svn_error_t *
+shelf_construct(svn_client_shelf_t **shelf_p,
+ const char *name,
+ const char *local_abspath,
+ svn_client_ctx_t *ctx,
+ apr_pool_t *result_pool)
{
svn_client_shelf_t *shelf = apr_palloc(result_pool, sizeof(*shelf));
char *shelves_dir;
@@ -414,14 +417,48 @@ svn_client_shelf_open(svn_client_shelf_t
shelf->pool = result_pool;
shelf->name = apr_pstrdup(result_pool, name);
- SVN_ERR(shelf_read_revprops(shelf, result_pool));
- SVN_ERR(shelf_read_current(shelf, result_pool));
+ shelf->revprops = apr_hash_make(result_pool);
+ shelf->max_version = 0;
*shelf_p = shelf;
return SVN_NO_ERROR;
}
svn_error_t *
+svn_client_shelf_open_existing(svn_client_shelf_t **shelf_p,
+ const char *name,
+ const char *local_abspath,
+ svn_client_ctx_t *ctx,
+ apr_pool_t *result_pool)
+{
+ SVN_ERR(shelf_construct(shelf_p, name,
+ local_abspath, ctx, result_pool));
+ SVN_ERR(shelf_read_revprops(*shelf_p, result_pool));
+ SVN_ERR(shelf_read_current(*shelf_p, result_pool));
+ if ((*shelf_p)->max_version <= 0)
+ {
+ return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
+ _("Shelf '%s' not found"),
+ name);
+ }
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_client_shelf_open(svn_client_shelf_t **shelf_p,
+ const char *name,
+ const char *local_abspath,
+ svn_client_ctx_t *ctx,
+ apr_pool_t *result_pool)
+{
+ SVN_ERR(shelf_construct(shelf_p, name,
+ local_abspath, ctx, result_pool));
+ SVN_ERR(shelf_read_revprops(*shelf_p, result_pool));
+ SVN_ERR(shelf_read_current(*shelf_p, result_pool));
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
svn_client_shelf_close(svn_client_shelf_t *shelf,
apr_pool_t *scratch_pool)
{
@@ -439,8 +476,8 @@ svn_client_shelf_delete(const char *name
int i;
char *abspath;
- SVN_ERR(svn_client_shelf_open(&shelf,
- name, local_abspath, ctx, scratch_pool));
+ SVN_ERR(svn_client_shelf_open_existing(&shelf, name,
+ local_abspath, ctx, scratch_pool));
/* Remove the patches. */
for (i = shelf->max_version; i > 0; i--)
Modified: subversion/trunk/subversion/svn/shelf-cmd.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/shelf-cmd.c?rev=1822006&r1=1822005&r2=1822006&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/shelf-cmd.c (original)
+++ subversion/trunk/subversion/svn/shelf-cmd.c Tue Jan 23 13:50:57 2018
@@ -206,8 +206,8 @@ shelves_list(const char *local_abspath,
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));
+ SVN_ERR(svn_client_shelf_open_existing(&shelf, name, local_abspath,
+ ctx, scratch_pool));
SVN_ERR(svn_client_shelf_version_open(&shelf_version,
shelf, shelf->max_version,
scratch_pool, scratch_pool));
@@ -236,8 +236,8 @@ shelf_log(const char *name,
svn_client_shelf_t *shelf;
int i;
- SVN_ERR(svn_client_shelf_open(&shelf, name, local_abspath,
- ctx, scratch_pool));
+ SVN_ERR(svn_client_shelf_open_existing(&shelf, name, local_abspath,
+ ctx, scratch_pool));
for (i = 1; i <= shelf->max_version; i++)
{
@@ -566,14 +566,8 @@ shelf_restore(const char *name,
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));
- if (shelf->max_version <= 0)
- {
- return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
- _("Shelf '%s' not found"),
- name);
- }
+ SVN_ERR(svn_client_shelf_open_existing(&shelf, name, local_abspath,
+ ctx, scratch_pool));
old_version = shelf->max_version;
if (arg)
@@ -636,14 +630,8 @@ shelf_diff(const char *name,
svn_client_shelf_version_t *shelf_version;
svn_stream_t *stream;
- SVN_ERR(svn_client_shelf_open(&shelf, name, local_abspath,
- ctx, scratch_pool));
- if (shelf->max_version <= 0)
- {
- return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
- _("Shelf '%s' not found"),
- name);
- }
+ SVN_ERR(svn_client_shelf_open_existing(&shelf, name, local_abspath,
+ ctx, scratch_pool));
if (arg)
{