HomePhabricator

Parse git renames with inconsistent quoting or custom prefixes

Description

Parse git renames with inconsistent quoting or custom prefixes

Summary:
The previous parser failed when only one of the old/new filenames was
quoted, as with a rename of a Unicode filename to a non-Unicode
filename, or vice versa. It also incorrectly parsed custom prefixes,
even going to far as to encode this logic in the tests: a diff of
"src/file dst/file" which is not a rename should not be recorded as
changing "src/file", but rather "file".

Switch to using the "rename from" / "rename to" as the source of truth
for old and current filenames when complex renames are done. This
matches the logic that git itself uses to parse patches; the contents
of the diff --git line are merely viewed as a simplest-case
prediction, with renames handled later should it not match.

The diff parser already had logic to parse "rename from" / "rename to"
lines and extract their information. As such, this diff consists
primarily of removing logic from the splitGitDiffPaths method, and
allowing it to quietly fail.

This resolves two ambiguity mentioned in comments and tests: in
renaming "old file old" to "file", as well as the renaming of
"old file with spaces" to "new file with spaces" when neither are
quoted.

Test Plan:
arc unit. Many of the existing test cases no longer
applied to the splitGitDiffPaths method; they were moved into a new
test method which also supplies values for "rename from" and "rename
to" lines.

As noted in the summary, this alters one of the expected values of an
existing test. Specifically, the following diff is a file addition of
file with custom prefixes, and not the addition of "dst/file":

diff --git src/file dst/file
new file mode 100644
index 0000000..1269488
--- /dev/null
+++ dst/file
@@ -0,0 +1 @@
+data

Reviewers: epriestley, Blessed Reviewers

Reviewed By: epriestley, Blessed Reviewers

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D16405

Details

Provenance
alexmvAuthored on Aug 16 2016, 8:38 PM
alexmvPushed on Aug 17 2016, 12:45 AM
Reviewer
Blessed Reviewers
Differential Revision
D16405: Parse git renames with inconsistent quoting or custom prefixes
Parents
rARCee6357386d0b: Correctly parse file renames and copies from `git diff --raw`
Branches
Unknown
Tags
Unknown
Build Status
Buildable 13333
Build 17102: Run Core Tests