Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to structured object representation of patch data #62

Merged
merged 6 commits into from
Aug 4, 2015

Conversation

bittrance
Copy link
Contributor

This PR does two things: 1) gives control over the context size of patches, and 2) adds a method that allows retrieving a patch in the shape of an object with a list of hunks. E.g.:

diff.structuredPatch(
  'oldfile', 'newfile',
  'line2\nline3\nline4\n', 'line2\nline3\nline5',
  'header1', 'header2'
)

{
  oldFileName: 'oldfile', newFileName: 'newfile',
  oldHeader: 'header1', newHeader: 'header2',
  hunks: [{
    oldStart: 1, oldLines: 3, newStart: 1, newLines: 3,
    lines: [' line2', ' line3', '-line4', '+line5', '\\ No newline at end of file'],
  }]
}

If it looks acceptable, I'll patch documentation et cetera.

var oldRangeStart = 0, newRangeStart = 0, curRange = [],
oldLine = 1, newLine = 1;
oldLine = 1, newLine = 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formatting was intentional. Style is to chain vars with , and to double indent when newlines are used to line up the var names.

@kpdecker
Copy link
Owner

This generally looks good outside of a few style concerns and a few cases where I'm not sure what the exact behavior is. Once we get those fixed up, I'm glad to merge.

@bittrance
Copy link
Contributor Author

Whitespace adjustments done.
Hunklines var removed in favour of curRange.

@bittrance
Copy link
Contributor Author

Documentation added.

kpdecker added a commit that referenced this pull request Aug 4, 2015
Allow access to structured object representation of patch data
@kpdecker kpdecker merged commit 9047d42 into kpdecker:master Aug 4, 2015
@kpdecker
Copy link
Owner

kpdecker commented Aug 4, 2015

Thanks!

@kpdecker
Copy link
Owner

kpdecker commented Aug 7, 2015

Released in 2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants