You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by cm...@apache.org on 2012/09/26 20:29:04 UTC

svn commit: r1390641 - /subversion/trunk/subversion/libsvn_repos/delta.c

Author: cmpilato
Date: Wed Sep 26 18:29:04 2012
New Revision: 1390641

URL: http://svn.apache.org/viewvc?rev=1390641&view=rev
Log:
Optimize a repos-layer bit of "are-the-contents-the-same" checking
which would previously would have resorted to a byte-for-byte
comparison of files when that could be avoid.

This optimation benefits, say, 'svn diff' between two branches where
there are files that have the same content not because they've not
been modified since their common ancestor, but because the
modifications they have had resulted in matching content (because one
has been sync-merged from the other, for example).

* subversion/libsvn_repos/delta.c
  (svn_repos__compare_files): Compare SHA1s when available, and
    consider the answer definitive.  (This code already compares MD5s,
    but we only give MD5s enough weight to say when things are
    different, not when they are the same.)

Modified:
    subversion/trunk/subversion/libsvn_repos/delta.c

Modified: subversion/trunk/subversion/libsvn_repos/delta.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/delta.c?rev=1390641&r1=1390640&r2=1390641&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/delta.c (original)
+++ subversion/trunk/subversion/libsvn_repos/delta.c Wed Sep 26 18:29:04 2012
@@ -629,12 +629,23 @@ svn_repos__compare_files(svn_boolean_t *
   if (!*changed_p)
     return SVN_NO_ERROR;
 
-  /* From this point on, assume things haven't changed. */
+  /* If the SHA1 checksums match for these things, we'll claim they
+     have the same contents.  (We don't give quite as much weight to
+     MD5 checksums.)  */
+  SVN_ERR(svn_fs_file_checksum(&checksum1, svn_checksum_sha1,
+                               root1, path1, FALSE, pool));
+  SVN_ERR(svn_fs_file_checksum(&checksum2, svn_checksum_sha1,
+                               root2, path2, FALSE, pool));
+  if (checksum1 && checksum2)
+    {
+      *changed_p = !svn_checksum_match(checksum1, checksum2);
+      return SVN_NO_ERROR;
+    }
+
+  /* From this point on, our default answer is "Nothing's changed". */
   *changed_p = FALSE;
 
-  /* So, things have changed.  But we need to know if the two sets of
-     file contents are actually different.  If they have differing
-     sizes, then we know they differ. */
+  /* Different filesizes means the contents are different. */
   SVN_ERR(svn_fs_file_length(&size1, root1, path1, pool));
   SVN_ERR(svn_fs_file_length(&size2, root2, path2, pool));
   if (size1 != size2)
@@ -643,8 +654,7 @@ svn_repos__compare_files(svn_boolean_t *
       return SVN_NO_ERROR;
     }
 
-  /* Same sizes, huh?  Well, if their checksums differ, we know they
-     differ. */
+  /* Different MD5 checksums means the contents are different. */
   SVN_ERR(svn_fs_file_checksum(&checksum1, svn_checksum_md5, root1, path1,
                                FALSE, pool));
   SVN_ERR(svn_fs_file_checksum(&checksum2, svn_checksum_md5, root2, path2,
@@ -655,13 +665,11 @@ svn_repos__compare_files(svn_boolean_t *
       return SVN_NO_ERROR;
     }
 
-  /* Same sizes, same checksums.  Chances are reallllly good that they
-     don't differ, but to be absolute sure, we need to compare bytes. */
+  /* And finally, different contents means the ... uh ... contents are
+     different. */
   SVN_ERR(svn_fs_file_contents(&stream1, root1, path1, pool));
   SVN_ERR(svn_fs_file_contents(&stream2, root2, path2, pool));
-
   SVN_ERR(svn_stream_contents_same2(&same, stream1, stream2, pool));
-
   *changed_p = !same;
 
   return SVN_NO_ERROR;