]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Prevent ArcanistBundle from generating patches with overlapping hunks
authorepriestley <git@epriestley.com>
Mon, 7 Nov 2011 01:48:43 +0000 (17:48 -0800)
committerepriestley <git@epriestley.com>
Mon, 7 Nov 2011 01:52:21 +0000 (17:52 -0800)
Summary: We currently may generate patches which have hunks that include overlapping context. Git was okay with this until at least 1.7.3.4, but started rejecting these patches some time later.

We already attempt to detect and prevent this condition, we just don't do a very good job of it. Fix the check so that we avoid generating overlapping hunks.

Test Plan:

  - Cleanly applied troublesome patches under Git 1.7.7.2.
  - Used "arc export --git" to verify patches generate without overlapping sections.
  - Locally changed $context to 2 and 1, verified patch behavior was reasonable.

Reviewers: kdeggelman, bizrad6, jonathanhester, jungejason, nh, tuomaspelkonen, aran

CC:

Differential Revision: 1084

src/parser/bundle/ArcanistBundle.php

index 10320ec3263cdc443fc37f940fb2bf841b97dbf7..5f997ca6d70247c4d07431c26aed64e0db6978b8 100644 (file)
@@ -301,7 +301,14 @@ class ArcanistBundle {
       $last_change = $jj;
       for (; $jj < $n; ++$jj) {
         if ($lines[$jj][0] == ' ') {
-          if ($jj - $last_change > $context) {
+          // NOTE: We must use "context * 2" or we may generate overlapping
+          // hunks. For instance, if we have "context = 3" and four unchanged
+          // lines between hunks, we'll include unchanged lines 1, 2, 3 in
+          // the first hunk and 2, 3, and 4 in the second hunk -- that is, lines
+          // 2 and 3 will appear twice in the patch. Some time after 1.7.3.4,
+          // Git stopped cleanly applying patches with overlapping hunks, so be
+          // careful to avoid generating them.
+          if ($jj - $last_change > ($context * 2)) {
             break;
           }
         } else {