subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From julianf...@apache.org
Subject svn commit: r1682277 - /subversion/branches/move-tracking-2/subversion/libsvn_delta/element.c
Date Thu, 28 May 2015 16:52:26 GMT
Author: julianfoad
Date: Thu May 28 16:52:26 2015
New Revision: 1682277

URL: http://svn.apache.org/r1682277
Log:
On the 'move-tracking-2' branch: Add some assertions.

* subversion/libsvn_delta/element.c
  (payload_invariants): New.
  (svn_element_payload_dup,
   svn_element_payload_equal): Assert validity as a precondition.
  (svn_element_payload_create_ref,
   svn_element_payload_create_dir,
   svn_element_payload_create_file,
   svn_element_payload_create_symlink): Assert validity as a postcondition.

Modified:
    subversion/branches/move-tracking-2/subversion/libsvn_delta/element.c

Modified: subversion/branches/move-tracking-2/subversion/libsvn_delta/element.c
URL: http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/subversion/libsvn_delta/element.c?rev=1682277&r1=1682276&r2=1682277&view=diff
==============================================================================
--- subversion/branches/move-tracking-2/subversion/libsvn_delta/element.c (original)
+++ subversion/branches/move-tracking-2/subversion/libsvn_delta/element.c Thu May 28 16:52:26
2015
@@ -21,6 +21,7 @@
  * ====================================================================
  */
 
+#include <assert.h>
 #include <apr_pools.h>
 
 #include "svn_types.h"
@@ -66,12 +67,28 @@ svn_pathrev_equal(svn_pathrev_t *peg_pat
  * ===================================================================
  */
 
+/* Return true iff PAYLOAD satisfies all its invariants.
+ */
+static svn_boolean_t
+payload_invariants(const svn_element_payload_t *payload)
+{
+  /* If kind is unknown, it's a reference; otherwise it has content
+     specified and may also have a reference. */
+  if (payload->kind == svn_node_unknown)
+    return (payload->ref.relpath && SVN_IS_VALID_REVNUM(payload->ref.rev));
+  return ((payload->props)
+          && (payload->text || payload->kind != svn_node_file)
+          && (payload->target || payload->kind != svn_node_symlink));
+}
+
 svn_element_payload_t *
 svn_element_payload_dup(const svn_element_payload_t *old,
                         apr_pool_t *result_pool)
 {
   svn_element_payload_t *new_payload;
 
+  assert(! old || payload_invariants(old));
+
   if (old == NULL)
     return NULL;
 
@@ -94,6 +111,9 @@ svn_element_payload_equal(const svn_elem
 {
   apr_array_header_t *prop_diffs;
 
+  assert(! left || payload_invariants(left));
+  assert(! right || payload_invariants(right));
+
   if (!left && !right)
     {
       return TRUE;
@@ -153,6 +173,7 @@ svn_element_payload_create_ref(svn_pathr
 
   new_payload->kind = svn_node_unknown;
   new_payload->ref = svn_pathrev_dup(ref, result_pool);
+  assert(payload_invariants(new_payload));
   return new_payload;
 }
 
@@ -165,6 +186,7 @@ svn_element_payload_create_dir(apr_hash_
 
   new_payload->kind = svn_node_dir;
   new_payload->props = props ? svn_prop_hash_dup(props, result_pool) : NULL;
+  assert(payload_invariants(new_payload));
   return new_payload;
 }
 
@@ -181,6 +203,7 @@ svn_element_payload_create_file(apr_hash
   new_payload->kind = svn_node_file;
   new_payload->props = props ? svn_prop_hash_dup(props, result_pool) : NULL;
   new_payload->text = svn_stringbuf_dup(text, result_pool);
+  assert(payload_invariants(new_payload));
   return new_payload;
 }
 
@@ -197,6 +220,7 @@ svn_element_payload_create_symlink(apr_h
   new_payload->kind = svn_node_symlink;
   new_payload->props = props ? svn_prop_hash_dup(props, result_pool) : NULL;
   new_payload->target = apr_pstrdup(result_pool, target);
+  assert(payload_invariants(new_payload));
   return new_payload;
 }
 



Mime
View raw message