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/04/09 17:17:07 UTC

svn commit: r932459 - in /subversion/trunk/subversion/libsvn_wc: entries.c wc-queries.sql wc_db.c wc_db.h

Author: julianfoad
Date: Fri Apr  9 15:17:06 2010
New Revision: 932459

URL: http://svn.apache.org/viewvc?rev=932459&view=rev
Log:
Adapt read_entries_new() to always return the MD5 checksum of the pristine
text, now that (with #ifdef SVN_EXPERIMENTAL) the checksum stored in the
BASE_NODE table will be a SHA-1 checksum.

* subversion/libsvn_wc/entries.c
  (read_entries_new): If the database yields a SHA-1 checksum, look up the
    equivalent MD-5 in the pristine store and put that in the entry.

* subversion/libsvn_wc/wc_db.c,
  subversion/libsvn_wc/wc_db.h
  (svn_wc__db_get_pristine_md5): New function.

* subversion/libsvn_wc/wc-queries.sql
  (STMT_SELECT_PRISTINE_MD5_CHECKSUM): New query statement.

Modified:
    subversion/trunk/subversion/libsvn_wc/entries.c
    subversion/trunk/subversion/libsvn_wc/wc-queries.sql
    subversion/trunk/subversion/libsvn_wc/wc_db.c
    subversion/trunk/subversion/libsvn_wc/wc_db.h

Modified: subversion/trunk/subversion/libsvn_wc/entries.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/entries.c?rev=932459&r1=932458&r2=932459&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/entries.c (original)
+++ subversion/trunk/subversion/libsvn_wc/entries.c Fri Apr  9 15:17:06 2010
@@ -1059,7 +1059,18 @@ read_entries_new(apr_hash_t **result_ent
                                                  result_pool);
 
       if (checksum)
-        entry->checksum = svn_checksum_to_cstring(checksum, result_pool);
+        {
+#ifdef SVN_EXPERIMENTAL
+          /* If we get a SHA-1, as expected in WC-NG, convert it to MD-5. */
+          if (checksum->kind == svn_checksum_sha1)
+            SVN_ERR(svn_wc__db_get_pristine_md5(&checksum, db,
+                                                entry_abspath, checksum,
+                                                scratch_pool, scratch_pool));
+#endif
+
+          SVN_ERR_ASSERT(checksum->kind == svn_checksum_md5);
+          entry->checksum = svn_checksum_to_cstring(checksum, result_pool);
+        }
 
       if (conflicted)
         {

Modified: subversion/trunk/subversion/libsvn_wc/wc-queries.sql
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc-queries.sql?rev=932459&r1=932458&r2=932459&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc-queries.sql (original)
+++ subversion/trunk/subversion/libsvn_wc/wc-queries.sql Fri Apr  9 15:17:06 2010
@@ -271,6 +271,11 @@ DELETE FROM WORK_QUEUE WHERE id = ?1;
 INSERT OR IGNORE INTO PRISTINE (checksum, md5_checksum, size, refcount)
 VALUES (?1, ?2, ?3, 1);
 
+-- STMT_SELECT_PRISTINE_MD5_CHECKSUM
+SELECT md5_checksum
+FROM pristine
+WHERE checksum = ?1
+
 -- STMT_SELECT_ACTUAL_CONFLICT_VICTIMS
 SELECT local_relpath
 FROM actual_node

Modified: subversion/trunk/subversion/libsvn_wc/wc_db.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db.c?rev=932459&r1=932458&r2=932459&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.c (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db.c Fri Apr  9 15:17:06 2010
@@ -7197,3 +7197,42 @@ svn_wc__db_temp_set_base_checksum(svn_wc
 
   return SVN_NO_ERROR;
 }
+
+svn_error_t *
+svn_wc__db_get_pristine_md5(const svn_checksum_t **md5_checksum,
+                            svn_wc__db_t *db,
+                            const char *wri_abspath,
+                            const svn_checksum_t *sha1_checksum,
+                            apr_pool_t *result_pool,
+                            apr_pool_t *scratch_pool)
+{
+  svn_wc__db_pdh_t *pdh;
+  const char *local_relpath;
+  svn_sqlite__stmt_t *stmt;
+  svn_boolean_t have_row;
+
+  SVN_ERR_ASSERT(svn_dirent_is_absolute(wri_abspath));
+  SVN_ERR_ASSERT(sha1_checksum->kind == svn_checksum_sha1);
+  VERIFY_CHECKSUM_KIND(sha1_checksum);
+
+  SVN_ERR(parse_local_abspath(&pdh, &local_relpath, db, wri_abspath,
+                              svn_sqlite__mode_readonly,
+                              scratch_pool, scratch_pool));
+  VERIFY_USABLE_PDH(pdh);
+
+  SVN_ERR(svn_sqlite__get_statement(&stmt, pdh->wcroot->sdb,
+                                    STMT_SELECT_PRISTINE_MD5_CHECKSUM));
+  SVN_ERR(svn_sqlite__bind_checksum(stmt, 1, sha1_checksum, scratch_pool));
+  SVN_ERR(svn_sqlite__step(&have_row, stmt));
+  if (!have_row)
+    {
+      *md5_checksum = NULL;  /* ### that's not what we want. Report an error
+                                instead. */
+      return svn_error_return(svn_sqlite__reset(stmt));
+    }
+
+  SVN_ERR(svn_sqlite__column_checksum(md5_checksum, stmt, 0, scratch_pool));
+
+  SVN_ERR_ASSERT((*md5_checksum)->kind == svn_checksum_md5);
+  return SVN_NO_ERROR;
+}

Modified: subversion/trunk/subversion/libsvn_wc/wc_db.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db.h?rev=932459&r1=932458&r2=932459&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.h (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db.h Fri Apr  9 15:17:06 2010
@@ -2142,6 +2142,18 @@ svn_wc__db_temp_set_base_checksum(svn_wc
                                   const svn_checksum_t *new_sha1_checksum,
                                   apr_pool_t *scratch_pool);
 
+
+/* Set *PRISTINE_MD5_CHECKSUM to the MD-5 checksum of a pristine text
+   identified by its SHA-1 checksum PRISTINE_SHA1_CHECKSUM. Return an error
+   if the pristine text does not exist or its MD5 checksum is not found. */
+svn_error_t *
+svn_wc__db_get_pristine_md5(const svn_checksum_t **pristine_md5_checksum,
+                            svn_wc__db_t *db,
+                            const char *wri_abspath,
+                            const svn_checksum_t *pristine_sha1_checksum,
+                            apr_pool_t *result_pool,
+                            apr_pool_t *scratch_pool);
+
 /* @} */
 
 



Re: svn commit: r932459 - in /subversion/trunk/subversion/libsvn_wc: entries.c wc-queries.sql wc_db.c wc_db.h

Posted by Julian Foad <ju...@wandisco.com>.
Greg Stein wrote:
> On Fri, Apr 9, 2010 at 11:17,  <ju...@apache.org> wrote:
> >...
> > +++ subversion/trunk/subversion/libsvn_wc/entries.c Fri Apr  9 15:17:06 2010
> > @@ -1059,7 +1059,18 @@ read_entries_new(apr_hash_t **result_ent
> >                                                  result_pool);
> >
> >       if (checksum)
> > -        entry->checksum = svn_checksum_to_cstring(checksum, result_pool);
> > +        {
> > +#ifdef SVN_EXPERIMENTAL
> 
> No need to make this SVN_EXPERIMENTAL. With "normal" trunk, a SHA-1
> will never be returned, so no big deal.

True.  I wrapped it to group it with the code that sets it, rather than
because it can't be executed.  This code is still in flux.  Maybe it's
better to avoid ifdef'd-out code as much as possible, but for now I'll
leave that particular bit.

> > +++ subversion/trunk/subversion/libsvn_wc/wc_db.c Fri Apr  9 15:17:06 2010
> > +svn_error_t *
> > +svn_wc__db_get_pristine_md5(const svn_checksum_t **md5_checksum,
> > +                            svn_wc__db_t *db,
> > +                            const char *wri_abspath,
> > +                            const svn_checksum_t *sha1_checksum,
> > +                            apr_pool_t *result_pool,
> > +                            apr_pool_t *scratch_pool)
> > +{
[...]
> > +  SVN_ERR(svn_sqlite__column_checksum(md5_checksum, stmt, 0, scratch_pool));
> > +
> > +  SVN_ERR_ASSERT((*md5_checksum)->kind == svn_checksum_md5);
> > +  return SVN_NO_ERROR;
> 
> Reset the statement!

Ah yes. r933272.

And, re. r932361, Greg Stein wrote: 
> > +svn_error_t *
> > +svn_wc__db_temp_set_base_checksum(svn_wc__db_t *db,
> > +                                  const char *local_abspath,
> > +                                  const svn_checksum_t *new_sha1_checksum,
> > +                                  apr_pool_t *scratch_pool)
> > +{
[...]
> > +  SVN_ERR(svn_sqlite__bind_text(stmt, 3, new_sha1_digest));
> > +  SVN_ERR(svn_sqlite__step_done(stmt));
> > +
> > +  return SVN_NO_ERROR;
> 
> Maybe use svn_sqlite__update() and ensure that 1 row was affected? And
> if not, return SVN_ERR_WC_PATH_NOT_FOUND.

OK, done.  (At first I thought that's what _step_done did. Still a SQL
newbie.)

By doing this, I found a serious mistake in my call to this function:
the BASE_NODE doesn't exist at the time when I call it, in some or all
cases, so it's not recording it.  Will investigate.

- Julian


Re: svn commit: r932459 - in /subversion/trunk/subversion/libsvn_wc: entries.c wc-queries.sql wc_db.c wc_db.h

Posted by Greg Stein <gs...@gmail.com>.
On Fri, Apr 9, 2010 at 11:17,  <ju...@apache.org> wrote:
>...
> +++ subversion/trunk/subversion/libsvn_wc/entries.c Fri Apr  9 15:17:06 2010
> @@ -1059,7 +1059,18 @@ read_entries_new(apr_hash_t **result_ent
>                                                  result_pool);
>
>       if (checksum)
> -        entry->checksum = svn_checksum_to_cstring(checksum, result_pool);
> +        {
> +#ifdef SVN_EXPERIMENTAL

No need to make this SVN_EXPERIMENTAL. With "normal" trunk, a SHA-1
will never be returned, so no big deal.

>...
> +++ subversion/trunk/subversion/libsvn_wc/wc_db.c Fri Apr  9 15:17:06 2010
> @@ -7197,3 +7197,42 @@ svn_wc__db_temp_set_base_checksum(svn_wc
>
>   return SVN_NO_ERROR;
>  }
> +
> +svn_error_t *
> +svn_wc__db_get_pristine_md5(const svn_checksum_t **md5_checksum,
> +                            svn_wc__db_t *db,
> +                            const char *wri_abspath,
> +                            const svn_checksum_t *sha1_checksum,
> +                            apr_pool_t *result_pool,
> +                            apr_pool_t *scratch_pool)
> +{
> +  svn_wc__db_pdh_t *pdh;
> +  const char *local_relpath;
> +  svn_sqlite__stmt_t *stmt;
> +  svn_boolean_t have_row;
> +
> +  SVN_ERR_ASSERT(svn_dirent_is_absolute(wri_abspath));
> +  SVN_ERR_ASSERT(sha1_checksum->kind == svn_checksum_sha1);
> +  VERIFY_CHECKSUM_KIND(sha1_checksum);
> +
> +  SVN_ERR(parse_local_abspath(&pdh, &local_relpath, db, wri_abspath,
> +                              svn_sqlite__mode_readonly,
> +                              scratch_pool, scratch_pool));
> +  VERIFY_USABLE_PDH(pdh);
> +
> +  SVN_ERR(svn_sqlite__get_statement(&stmt, pdh->wcroot->sdb,
> +                                    STMT_SELECT_PRISTINE_MD5_CHECKSUM));
> +  SVN_ERR(svn_sqlite__bind_checksum(stmt, 1, sha1_checksum, scratch_pool));
> +  SVN_ERR(svn_sqlite__step(&have_row, stmt));
> +  if (!have_row)
> +    {
> +      *md5_checksum = NULL;  /* ### that's not what we want. Report an error
> +                                instead. */
> +      return svn_error_return(svn_sqlite__reset(stmt));
> +    }
> +
> +  SVN_ERR(svn_sqlite__column_checksum(md5_checksum, stmt, 0, scratch_pool));
> +
> +  SVN_ERR_ASSERT((*md5_checksum)->kind == svn_checksum_md5);
> +  return SVN_NO_ERROR;

Reset the statement!

>...

Cheers,
-g