1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 06:42:41 +01:00

Prevent ArcanistBundle from generating patches with overlapping hunks

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
This commit is contained in:
epriestley 2011-11-06 17:48:43 -08:00
parent 42b69af59b
commit cc3641e633

View 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 {