changeset 11707:17142e516858

Fix an assertion failure.
author Bruno Haible <bruno@clisp.org>
date Sat, 04 Jul 2009 11:25:49 +0200
parents de9937c296ee
children f74cfe188f81
files ChangeLog lib/git-merge-changelog.c
diffstat 2 files changed, 43 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-07-04  Bruno Haible  <bruno@clisp.org>
+
+	Fix assertion.
+	* lib/git-merge-changelog.c (compute_mapping): In the case where file1
+	contains more exact copies of a given entry than file2, leave the extra
+	copies unpaired rather than aborting.
+	Reported by Eric Blake.
+
 2009-07-02  Bruno Haible  <bruno@clisp.org>
 
 	Speedup git-merge-changelog for git cherry-pick.
--- a/lib/git-merge-changelog.c
+++ b/lib/git-merge-changelog.c
@@ -510,37 +510,44 @@
 	  {
 	    j = n2 - 1 - j;
 	    /* Found an exact correspondence.  */
-	    ASSERT (index_mapping_reverse[j] < 0);
-	    index_mapping[i] = j;
-	    index_mapping_reverse[j] = i;
-	    /* Look for more occurrences of the same entry.  */
-	    {
-	      ssize_t curr_i = i;
-	      ssize_t curr_j = j;
+	    /* If index_mapping_reverse[j] >= 0, we have already seen other
+	       copies of this entry, and there were more occurrences of it in
+	       file1 than in file2.  In this case, do nothing.  */
+	    if (index_mapping_reverse[j] < 0)
+	      {
+		index_mapping[i] = j;
+		index_mapping_reverse[j] = i;
+		/* Look for more occurrences of the same entry.  Match them
+		   as long as they pair up.  Unpaired occurrences of the same
+		   entry are left without mapping.  */
+		{
+		  ssize_t curr_i = i;
+		  ssize_t curr_j = j;
 
-	      for (;;)
-		{
-		  ssize_t next_i;
-		  ssize_t next_j;
+		  for (;;)
+		    {
+		      ssize_t next_i;
+		      ssize_t next_j;
 
-		  next_i =
-		    gl_list_indexof_from (file1->entries_reversed, n1 - curr_i,
-					  entry);
-		  if (next_i < 0)
-		    break;
-		  next_j =
-		    gl_list_indexof_from (file2->entries_reversed, n2 - curr_j,
-					  entry);
-		  if (next_j < 0)
-		    break;
-		  curr_i = n1 - 1 - next_i;
-		  curr_j = n2 - 1 - next_j;
-		  ASSERT (index_mapping[curr_i] < 0);
-		  ASSERT (index_mapping_reverse[curr_j] < 0);
-		  index_mapping[curr_i] = curr_j;
-		  index_mapping_reverse[curr_j] = curr_i;
+		      next_i =
+			gl_list_indexof_from (file1->entries_reversed,
+					      n1 - curr_i, entry);
+		      if (next_i < 0)
+			break;
+		      next_j =
+			gl_list_indexof_from (file2->entries_reversed,
+					      n2 - curr_j, entry);
+		      if (next_j < 0)
+			break;
+		      curr_i = n1 - 1 - next_i;
+		      curr_j = n2 - 1 - next_j;
+		      ASSERT (index_mapping[curr_i] < 0);
+		      ASSERT (index_mapping_reverse[curr_j] < 0);
+		      index_mapping[curr_i] = curr_j;
+		      index_mapping_reverse[curr_j] = curr_i;
+		    }
 		}
-	    }
+	      }
 	  }
       }