Closed Bug 1709704 Opened 5 years ago Closed 5 years ago

Phabricator fails to create a diff if one of the files in the list of changes is empty

Categories

(Conduit :: Phabricator, defect)

Production
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: vringar, Assigned: vringar)

References

(Regression)

Details

Attachments

(1 external file)

When calling conduit.create_diff() as part of moz-phab submit with a set of changes that contain an empty file, the https://phabricator.services.mozilla.com/api/differential.creatediff endpoint returns the following error:

{
'result':None,
'error_code':'RuntimeException',
'error_info':'array_walk_recursive() expects parameter 1 to be array, null given'
}

Digging in further into the empty file we find that:

{
'metadata': {},
'oldPath': None,
'currentPath': 'dom/callmonitor/tests/test_actors_child.js',
'awayPaths': [],
'oldProperties': {},
'newProperties': {'unix:filemode': '100644'},
'commitHash': 'b261cdce7563d40d349ae0442d2c2eaef5a7389b',
'type': 1,
'fileType': 1,
'hunks': [
    {'oldOffset': 0,
     'oldLength': 0,
     'newOffset': 1,
     'newLength': 0,
     'addLines': 0,
     'delLines': 0,
     'isMissingOldNewline': True,
     'isMissingNewNewline': True,
     'corpus': '\\ No newline at end of file\n'
    }
]
}

The one thing that's curious to me here is that 'newOffset': 1 when it really can't be because there is no line 1 in an empty file.

This was regressed by https://phabricator.services.mozilla.com/D106943 as the call to create_hunk_lines with the defaulted parameter check_eof=True returns the list ['\\ No newline at end of file\n'] which then results in a hunk being generated.

You stated in Matrix that

it should be hunks:[]

As far as I can see there are two options

  1. Skip creating hunks in _parse_diff_change if an empty file is being added.
  2. Modify create_hunk_lines to return [], None when given called with body="",prefix="+"

@Kwan I think 2. is the right approach as sefeng appears to have been working with mercurial when they encountered this bug so just modifying the git code path (aka _parse_diff_change) wouldn't fix that error.

Flags: needinfo?(moz-ian)
Assignee: nobody → szabka
Status: NEW → ASSIGNED
Regressed by: 1695847
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Flags: needinfo?(moz-ian)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: