]> khamidou — GitHub mirrors - arcanist.git/commit
Split paths on "diff --git" lines correctly in more cases
authorepriestley <git@epriestley.com>
Thu, 25 Oct 2012 21:46:44 +0000 (14:46 -0700)
committerepriestley <git@epriestley.com>
Thu, 25 Oct 2012 21:46:44 +0000 (14:46 -0700)
commit6be5cfd104b5977513e2062b8a1e461bfadb2fdd
tree46fd93eb734eb0d486208554bedf97a3b6ed764e
parentb8ead97637191a490dac5d16eacd5e09bafdfc30
Split paths on "diff --git" lines correctly in more cases

Summary:
See T1973. In T1675, we addressed parsing of diffs with `--no-prefix` or custom `--src-prefix` and `--dst-prefix` flags. However, this inadvetently broke diffing of files with spaces in their names, which Git does not quote. They look like this normally:

  diff --git a/old file b/new file

Prior to D3744, we accidentally got this right by looking for the `a/` and `b/`. However, we no longer do, and instead produce nonsense results.

This problem is difficult because for files with spaces, `git diff --no-prefix` may generate an ambiguous line like:

  diff --git a b c d e f g

From this line, we have no way to deterine if this moves "a" to "b c d e f g", or "a b c d" to "e f g", or anything in between. In some diffs we have more information later on, but in some cases we do not, e.g. for binary diffs without `--binary`.

Try to get this right in as many cases as possible:

  - If there are quotes, we can unambiguously get it right. This only happens for filenames with quotes or unicode characters, however.
  - If there is exactly one space, we can unambiguously get it right.
  - Interpret the common case of `a/<anything> b/<anything>` in the most-likely-correct way again.
  - Interpret the rare case of `<anything> <that same thing>` in the most-likely-correct way.
  - Complain about any `a b c d e f g` garbage.

Test Plan: Ran unit tests. Created a diff of a file called "File With Spaces".

Reviewers: vrana, btrahan

Reviewed By: btrahan

CC: aran, ReturnZero
Maniphest Tasks: T1973

Differential Revision: https://secure.phabricator.com/D3818
src/parser/ArcanistDiffParser.php
src/parser/__tests__/ArcanistDiffParserTestCase.php