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 2010/06/25 14:36:54 UTC

svn commit: r957921 - in /subversion/trunk/subversion: libsvn_wc/workqueue.c libsvn_wc/workqueue.h tests/libsvn_wc/pristine-store-test.c

Author: julianfoad
Date: Fri Jun 25 12:36:53 2010
New Revision: 957921

URL: http://svn.apache.org/viewvc?rev=957921&view=rev
Log:
Add a new work queue item that will fetch a pristine text and translate it
to working-copy form and write it to a specified new file.

* subversion/libsvn_wc/workqueue.c
  (OP_PRISTINE_GET_TRANSLATED): New macro.
  (pristine_get_translated, run_pristine_get_translated,
   svn_wc__wq_build_pristine_get_translated): New functions.
  (dispatch_table): Add OP_PRISTINE_GET_TRANSLATED.

* subversion/libsvn_wc/workqueue.h
  (svn_wc__wq_build_pristine_get_translated): New function.

* subversion/tests/libsvn_wc/pristine-store-test.c
  (pristine_get_translated): New test.
  (test_funcs): Add the new test.

Modified:
    subversion/trunk/subversion/libsvn_wc/workqueue.c
    subversion/trunk/subversion/libsvn_wc/workqueue.h
    subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c

Modified: subversion/trunk/subversion/libsvn_wc/workqueue.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/workqueue.c?rev=957921&r1=957920&r2=957921&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/workqueue.c (original)
+++ subversion/trunk/subversion/libsvn_wc/workqueue.c Fri Jun 25 12:36:53 2010
@@ -65,6 +65,7 @@
 #define OP_RECORD_FILEINFO "record-fileinfo"
 #define OP_TMP_SET_TEXT_CONFLICT_MARKERS "tmp-set-text-conflict-markers"
 #define OP_TMP_SET_PROPERTY_CONFLICT_MARKER "tmp-set-property-conflict-marker"
+#define OP_PRISTINE_GET_TRANSLATED "pristine-get-translated"
 
 /* For work queue debugging. Generates output about its operation.  */
 /* #define DEBUG_WORK_QUEUE */
@@ -2360,6 +2361,93 @@ svn_wc__wq_tmp_build_set_property_confli
 
 /* ------------------------------------------------------------------------ */
 
+/* OP_PRISTINE_GET_TRANSLATED  */
+
+/* Create (or overwrite) the file NEW_ABSPATH with the pristine text
+   identified by PRISTINE_SHA1, translated into working-copy form
+   according to the versioned properties of VERSIONED_ABSPATH. */
+static svn_error_t *
+pristine_get_translated(svn_wc__db_t *db,
+                        const char *versioned_abspath,
+                        const char *new_abspath,
+                        const svn_checksum_t *pristine_sha1,
+                        svn_cancel_func_t cancel_func,
+                        void *cancel_baton,
+                        apr_pool_t *scratch_pool)
+{
+  svn_stream_t *src_stream, *dst_stream;
+
+  SVN_ERR(svn_wc__db_pristine_read(&src_stream, db, versioned_abspath,
+                                   pristine_sha1,
+                                   scratch_pool, scratch_pool));
+  SVN_ERR(svn_wc__internal_translated_stream(&dst_stream, db, new_abspath,
+                                             versioned_abspath,
+                                             SVN_WC_TRANSLATE_FROM_NF,
+                                             scratch_pool, scratch_pool));
+  SVN_ERR(svn_stream_copy3(src_stream, dst_stream,
+                           cancel_func, cancel_baton, scratch_pool));
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+run_pristine_get_translated(svn_wc__db_t *db,
+                            const svn_skel_t *work_item,
+                            svn_cancel_func_t cancel_func,
+                            void *cancel_baton,
+                            apr_pool_t *scratch_pool)
+{
+  const svn_skel_t *arg1 = work_item->children->next;
+  const char *versioned_abspath;
+  const char *new_abspath;
+  const svn_checksum_t *pristine_sha1;
+
+  versioned_abspath = apr_pstrmemdup(scratch_pool, arg1->data, arg1->len);
+  new_abspath = apr_pstrmemdup(scratch_pool, arg1->next->data,
+                               arg1->next->len);
+  {
+    const char *data = apr_pstrmemdup(scratch_pool,
+                                      arg1->next->next->data,
+                                      arg1->next->next->len);
+    SVN_ERR(svn_checksum_deserialize(&pristine_sha1, data,
+                                     scratch_pool, scratch_pool));
+  }
+
+  SVN_ERR(pristine_get_translated(db, versioned_abspath, new_abspath,
+                                  pristine_sha1,
+                                  cancel_func, cancel_baton, scratch_pool));
+
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_wc__wq_build_pristine_get_translated(svn_skel_t **work_item,
+                                         svn_wc__db_t *db,
+                                         const char *versioned_abspath,
+                                         const char *new_abspath,
+                                         const svn_checksum_t *pristine_sha1,
+                                         apr_pool_t *result_pool,
+                                         apr_pool_t *scratch_pool)
+{
+  *work_item = svn_skel__make_empty_list(result_pool);
+
+  svn_skel__prepend_str(pristine_sha1
+                          ? svn_checksum_serialize(pristine_sha1,
+                                                   scratch_pool, scratch_pool)
+                          : "",
+                        *work_item, scratch_pool);
+  svn_skel__prepend_str(apr_pstrdup(result_pool, new_abspath),
+                        *work_item, result_pool);
+  svn_skel__prepend_str(apr_pstrdup(result_pool, versioned_abspath),
+                        *work_item, result_pool);
+  svn_skel__prepend_str(OP_PRISTINE_GET_TRANSLATED, *work_item, result_pool);
+
+  return SVN_NO_ERROR;
+}
+
+
+/* ------------------------------------------------------------------------ */
+
 static const struct work_item_dispatch dispatch_table[] = {
   { OP_REVERT, run_revert },
   { OP_PREPARE_REVERT_FILES, run_prepare_revert_files },
@@ -2376,6 +2464,7 @@ static const struct work_item_dispatch d
   { OP_RECORD_FILEINFO, run_record_fileinfo },
   { OP_TMP_SET_TEXT_CONFLICT_MARKERS, run_set_text_conflict_markers },
   { OP_TMP_SET_PROPERTY_CONFLICT_MARKER, run_set_property_conflict_marker },
+  { OP_PRISTINE_GET_TRANSLATED, run_pristine_get_translated },
 
 /* See props.h  */
 #ifdef SVN__SUPPORT_BASE_MERGE

Modified: subversion/trunk/subversion/libsvn_wc/workqueue.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/workqueue.h?rev=957921&r1=957920&r2=957921&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/workqueue.h (original)
+++ subversion/trunk/subversion/libsvn_wc/workqueue.h Fri Jun 25 12:36:53 2010
@@ -254,6 +254,20 @@ svn_wc__wq_tmp_build_set_property_confli
                                                   apr_pool_t *result_pool,
                                                   apr_pool_t *scratch_pool);
 
+/* Set *WORK_ITEM to a new work item that will create the file NEW_ABSPATH
+ * with the pristine text identified by PRISTINE_SHA1, translated into
+ * working-copy form according to the versioned properties of
+ * VERSIONED_ABSPATH that are current when the work item is executed.  The
+ * work item will overwrite NEW_ABSPATH if that already exists. */
+svn_error_t *
+svn_wc__wq_build_pristine_get_translated(svn_skel_t **work_item,
+                                         svn_wc__db_t *db,
+                                         const char *versioned_abspath,
+                                         const char *new_abspath,
+                                         const svn_checksum_t *pristine_sha1,
+                                         apr_pool_t *result_pool,
+                                         apr_pool_t *scratch_pool);
+
 svn_error_t *
 svn_wc__wq_add_deletion_postcommit(svn_wc__db_t *db,
                                    const char *local_abspath,

Modified: subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c?rev=957921&r1=957920&r2=957921&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c Fri Jun 25 12:36:53 2010
@@ -43,6 +43,7 @@
 #include "../../libsvn_wc/wc.h"
 #include "../../libsvn_wc/wc_db.h"
 #include "../../libsvn_wc/wc-queries.h"
+#include "../../libsvn_wc/workqueue.h"
 
 #include "private/svn_wc_private.h"
 
@@ -226,11 +227,106 @@ pristine_write_read(const svn_test_opts_
   return SVN_NO_ERROR;
 }
 
+/* Test the WQ item for getting and translating a text. */
+static svn_error_t *
+pristine_get_translated(const svn_test_opts_t *opts,
+                        apr_pool_t *pool)
+{
+  svn_wc__db_t *db;
+  const char *repos_url;
+  const char *wc_abspath, *versioned_abspath, *new_abspath;
+  const char data[] = "Blah at r$Rev$\n";
+  const char expected_data[] = "Blah at r$Rev: -1 $\n";
+  svn_checksum_t *data_sha1, *data_md5;
+
+  SVN_ERR(create_repos_and_wc(&repos_url, &wc_abspath, &db,
+                              "pristine_get_translated", opts, pool));
+
+  versioned_abspath = svn_dirent_join(wc_abspath, "foo", pool);
+  new_abspath = svn_dirent_join(wc_abspath, "foo.fetched", pool);
+
+  /* Create VERSIONED_ABSPATH, whose metadata will be used for the
+     translation. Set some properties on it. */
+  {
+    svn_wc_context_t *wc_ctx;
+
+    SVN_ERR(svn_wc__context_create_with_db(&wc_ctx, NULL, db, pool));
+    SVN_ERR(svn_io_file_create(versioned_abspath, data, pool));
+    SVN_ERR(svn_wc_add4(wc_ctx, versioned_abspath, svn_depth_empty,
+                        NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL,
+                        pool));
+    SVN_ERR(svn_wc_prop_set4(wc_ctx, versioned_abspath,
+                             "svn:keywords", svn_string_create("Rev", pool),
+                             FALSE, NULL, NULL, pool));
+  }
+
+  /* Store a pristine text, and set DATA_SHA1 and DATA_MD5. */
+  {
+    const char *pristine_tmp_dir;
+    const char *pristine_tmp_abspath;
+    svn_stream_t *pristine_tmp_stream;
+    svn_string_t *data_string = svn_string_create(data, pool);
+    svn_stream_t *data_stream = svn_stream_from_string(data_string, pool);
+
+    SVN_ERR(svn_wc__db_pristine_get_tempdir(&pristine_tmp_dir, db,
+                                            wc_abspath, pool, pool));
+    SVN_ERR(svn_stream_open_unique(&pristine_tmp_stream, &pristine_tmp_abspath,
+                                   pristine_tmp_dir, svn_io_file_del_none,
+                                   pool, pool));
+
+    data_stream = svn_stream_checksummed2(data_stream, &data_sha1, NULL,
+                                          svn_checksum_sha1, TRUE, pool);
+    data_stream = svn_stream_checksummed2(data_stream, &data_md5, NULL,
+                                          svn_checksum_md5, TRUE, pool);
+    SVN_ERR(svn_stream_copy3(data_stream, pristine_tmp_stream, NULL, NULL,
+                             pool));
+
+    SVN_ERR(svn_wc__db_pristine_install(db, pristine_tmp_abspath,
+                                        data_sha1, data_md5, pool));
+  }
+
+  /* Run a work item to read and translate the text into NEW_ABSPATH. */
+  {
+    svn_skel_t *work_item;
+
+    SVN_ERR(svn_wc__wq_build_pristine_get_translated(&work_item,
+                                                     db, versioned_abspath,
+                                                     new_abspath, data_sha1,
+                                                     pool, pool));
+    SVN_ERR(svn_wc__db_wq_add(db, versioned_abspath, work_item, pool));
+
+    SVN_ERR(svn_wc__wq_run(db, wc_abspath, NULL, NULL, pool));
+  }
+
+  /* Check that NEW_ABSPATH has been created with the translated text. */
+  {
+    apr_file_t *file;
+    char buf[1000];
+    apr_size_t bytes_read;
+    svn_error_t *err;
+
+    SVN_ERR(svn_io_file_open(&file, new_abspath,
+                             APR_FOPEN_READ, APR_FPROT_OS_DEFAULT, pool));
+    err = svn_io_file_read_full(file, buf, sizeof(buf), &bytes_read, pool);
+    if (err && APR_STATUS_IS_EOF(err->apr_err))
+      svn_error_clear(err);
+    else
+      SVN_ERR(err);
+
+    SVN_TEST_ASSERT(bytes_read == strlen(expected_data));
+    SVN_TEST_ASSERT(strncmp(buf, expected_data, bytes_read) == 0);
+  }
+
+  return SVN_NO_ERROR;
+}
+
 
 struct svn_test_descriptor_t test_funcs[] =
   {
     SVN_TEST_NULL,
     SVN_TEST_OPTS_PASS(pristine_write_read,
                        "pristine_write_read"),
+    SVN_TEST_OPTS_PASS(pristine_get_translated,
+                       "pristine_get_translated"),
     SVN_TEST_NULL
   };



Re: svn commit: r957921 - in /subversion/trunk/subversion: libsvn_wc/workqueue.c libsvn_wc/workqueue.h tests/libsvn_wc/pristine-store-test.c

Posted by Julian Foad <ju...@wandisco.com>.
On Sat, 2010-06-26 at 08:59 +0100, Julian Foad wrote:
> On Fri, 2010-06-25, Greg Stein wrote:
> > On Fri, Jun 25, 2010 at 08:36,  <ju...@apache.org> wrote:
> > >...
> > > +++ subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c Fri Jun 25 12:36:53 2010
> > >...
> > > +  /* Store a pristine text, and set DATA_SHA1 and DATA_MD5. */
> > > +  {
> > > +    const char *pristine_tmp_dir;
> > > +    const char *pristine_tmp_abspath;
> > > +    svn_stream_t *pristine_tmp_stream;
> > > +    svn_string_t *data_string = svn_string_create(data, pool);
> > > +    svn_stream_t *data_stream = svn_stream_from_string(data_string, pool);
> > > +
> > > +    SVN_ERR(svn_wc__db_pristine_get_tempdir(&pristine_tmp_dir, db,
> > > +                                            wc_abspath, pool, pool));
> > > +    SVN_ERR(svn_stream_open_unique(&pristine_tmp_stream, &pristine_tmp_abspath,
> > > +                                   pristine_tmp_dir, svn_io_file_del_none,
> > > +                                   pool, pool));
> > > +
> > > +    data_stream = svn_stream_checksummed2(data_stream, &data_sha1, NULL,
> > > +                                          svn_checksum_sha1, TRUE, pool);
> > > +    data_stream = svn_stream_checksummed2(data_stream, &data_md5, NULL,
> > > +                                          svn_checksum_md5, TRUE, pool);
> > > +    SVN_ERR(svn_stream_copy3(data_stream, pristine_tmp_stream, NULL, NULL,
> > > +                             pool));
> > 
> > You could just use svn_stream_write(..., data, ...) rather than copying streams.
> > 
> > >...
> > > +  /* Check that NEW_ABSPATH has been created with the translated text. */
> > > +  {
> > > +    apr_file_t *file;
> > > +    char buf[1000];
> > > +    apr_size_t bytes_read;
> > > +    svn_error_t *err;
> > > +
> > > +    SVN_ERR(svn_io_file_open(&file, new_abspath,
> > > +                             APR_FOPEN_READ, APR_FPROT_OS_DEFAULT, pool));
> > > +    err = svn_io_file_read_full(file, buf, sizeof(buf), &bytes_read, pool);
> > > +    if (err && APR_STATUS_IS_EOF(err->apr_err))
> > > +      svn_error_clear(err);
> > > +    else
> > > +      SVN_ERR(err);
> > 
> > There is a stream/file function that sucks an entire file into an
> > svn_string_t or somesuch. That would be much easier to use/understand.
> 
> I'll try those suggestions later.  Thanks.

Simplified in r959321, using svn_stream_printf() for the former and
svn_stream_contents_same2() for the latter.

Thanks.
- Julian


Re: svn commit: r957921 - in /subversion/trunk/subversion: libsvn_wc/workqueue.c libsvn_wc/workqueue.h tests/libsvn_wc/pristine-store-test.c

Posted by Julian Foad <ju...@wandisco.com>.
On Fri, 2010-06-25, Greg Stein wrote:
> On Fri, Jun 25, 2010 at 08:36,  <ju...@apache.org> wrote:
> >...
> > +++ subversion/trunk/subversion/libsvn_wc/workqueue.c Fri Jun 25 12:36:53 2010
> >...
> > +svn_error_t *
> > +svn_wc__wq_build_pristine_get_translated(svn_skel_t **work_item,
> > +                                         svn_wc__db_t *db,
> > +                                         const char *versioned_abspath,
> > +                                         const char *new_abspath,
> > +                                         const svn_checksum_t *pristine_sha1,
> > +                                         apr_pool_t *result_pool,
> > +                                         apr_pool_t *scratch_pool)
> > +{
> > +  *work_item = svn_skel__make_empty_list(result_pool);
> > +
> > +  svn_skel__prepend_str(pristine_sha1
> > +                          ? svn_checksum_serialize(pristine_sha1,
> > +                                                   scratch_pool, scratch_pool)
> > +                          : "",
> 
> Why is PRISTINE_SHA1 allowed to be NULL? You certainly don't
> deserialize it properly in the code above.
> 
> And the serialization should go into result_pool.

Oops, both copy-paste errors.

r958198.

Thanks for catching.

> >...
> > +++ subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c Fri Jun 25 12:36:53 2010
> >...
> > +  /* Store a pristine text, and set DATA_SHA1 and DATA_MD5. */
> > +  {
> > +    const char *pristine_tmp_dir;
> > +    const char *pristine_tmp_abspath;
> > +    svn_stream_t *pristine_tmp_stream;
> > +    svn_string_t *data_string = svn_string_create(data, pool);
> > +    svn_stream_t *data_stream = svn_stream_from_string(data_string, pool);
> > +
> > +    SVN_ERR(svn_wc__db_pristine_get_tempdir(&pristine_tmp_dir, db,
> > +                                            wc_abspath, pool, pool));
> > +    SVN_ERR(svn_stream_open_unique(&pristine_tmp_stream, &pristine_tmp_abspath,
> > +                                   pristine_tmp_dir, svn_io_file_del_none,
> > +                                   pool, pool));
> > +
> > +    data_stream = svn_stream_checksummed2(data_stream, &data_sha1, NULL,
> > +                                          svn_checksum_sha1, TRUE, pool);
> > +    data_stream = svn_stream_checksummed2(data_stream, &data_md5, NULL,
> > +                                          svn_checksum_md5, TRUE, pool);
> > +    SVN_ERR(svn_stream_copy3(data_stream, pristine_tmp_stream, NULL, NULL,
> > +                             pool));
> 
> You could just use svn_stream_write(..., data, ...) rather than copying streams.
> 
> >...
> > +  /* Check that NEW_ABSPATH has been created with the translated text. */
> > +  {
> > +    apr_file_t *file;
> > +    char buf[1000];
> > +    apr_size_t bytes_read;
> > +    svn_error_t *err;
> > +
> > +    SVN_ERR(svn_io_file_open(&file, new_abspath,
> > +                             APR_FOPEN_READ, APR_FPROT_OS_DEFAULT, pool));
> > +    err = svn_io_file_read_full(file, buf, sizeof(buf), &bytes_read, pool);
> > +    if (err && APR_STATUS_IS_EOF(err->apr_err))
> > +      svn_error_clear(err);
> > +    else
> > +      SVN_ERR(err);
> 
> There is a stream/file function that sucks an entire file into an
> svn_string_t or somesuch. That would be much easier to use/understand.

I'll try those suggestions later.  Thanks.

- Julian


Re: svn commit: r957921 - in /subversion/trunk/subversion: libsvn_wc/workqueue.c libsvn_wc/workqueue.h tests/libsvn_wc/pristine-store-test.c

Posted by Greg Stein <gs...@gmail.com>.
On Fri, Jun 25, 2010 at 08:36,  <ju...@apache.org> wrote:
>...
> +++ subversion/trunk/subversion/libsvn_wc/workqueue.c Fri Jun 25 12:36:53 2010
>...
> +svn_error_t *
> +svn_wc__wq_build_pristine_get_translated(svn_skel_t **work_item,
> +                                         svn_wc__db_t *db,
> +                                         const char *versioned_abspath,
> +                                         const char *new_abspath,
> +                                         const svn_checksum_t *pristine_sha1,
> +                                         apr_pool_t *result_pool,
> +                                         apr_pool_t *scratch_pool)
> +{
> +  *work_item = svn_skel__make_empty_list(result_pool);
> +
> +  svn_skel__prepend_str(pristine_sha1
> +                          ? svn_checksum_serialize(pristine_sha1,
> +                                                   scratch_pool, scratch_pool)
> +                          : "",

Why is PRISTINE_SHA1 allowed to be NULL? You certainly don't
deserialize it properly in the code above.

And the serialization should go into result_pool.

>...
> +++ subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c Fri Jun 25 12:36:53 2010
>...
> +  /* Store a pristine text, and set DATA_SHA1 and DATA_MD5. */
> +  {
> +    const char *pristine_tmp_dir;
> +    const char *pristine_tmp_abspath;
> +    svn_stream_t *pristine_tmp_stream;
> +    svn_string_t *data_string = svn_string_create(data, pool);
> +    svn_stream_t *data_stream = svn_stream_from_string(data_string, pool);
> +
> +    SVN_ERR(svn_wc__db_pristine_get_tempdir(&pristine_tmp_dir, db,
> +                                            wc_abspath, pool, pool));
> +    SVN_ERR(svn_stream_open_unique(&pristine_tmp_stream, &pristine_tmp_abspath,
> +                                   pristine_tmp_dir, svn_io_file_del_none,
> +                                   pool, pool));
> +
> +    data_stream = svn_stream_checksummed2(data_stream, &data_sha1, NULL,
> +                                          svn_checksum_sha1, TRUE, pool);
> +    data_stream = svn_stream_checksummed2(data_stream, &data_md5, NULL,
> +                                          svn_checksum_md5, TRUE, pool);
> +    SVN_ERR(svn_stream_copy3(data_stream, pristine_tmp_stream, NULL, NULL,
> +                             pool));

You could just use svn_stream_write(..., data, ...) rather than copying streams.

>...
> +  /* Check that NEW_ABSPATH has been created with the translated text. */
> +  {
> +    apr_file_t *file;
> +    char buf[1000];
> +    apr_size_t bytes_read;
> +    svn_error_t *err;
> +
> +    SVN_ERR(svn_io_file_open(&file, new_abspath,
> +                             APR_FOPEN_READ, APR_FPROT_OS_DEFAULT, pool));
> +    err = svn_io_file_read_full(file, buf, sizeof(buf), &bytes_read, pool);
> +    if (err && APR_STATUS_IS_EOF(err->apr_err))
> +      svn_error_clear(err);
> +    else
> +      SVN_ERR(err);

There is a stream/file function that sucks an entire file into an
svn_string_t or somesuch. That would be much easier to use/understand.

>...

Cheers,
-g