Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Add GetFormatPatch receiver for a repository #103

Merged
merged 3 commits into from
Jan 5, 2018

Conversation

strk
Copy link
Member

@strk strk commented Jan 3, 2018

Includes test

@strk
Copy link
Member Author

strk commented Jan 3, 2018

I don't know why GetPatch returns a byte[], for simplicity I had GetFormatPatch return a string instead

@lafriks
Copy link
Member

lafriks commented Jan 3, 2018

Could diff contain binary data?

@strk
Copy link
Member Author

strk commented Jan 3, 2018

I guess so. Ok will add --binary switch and return binary. Will need to find out how to convert the byte[] to a string for comparison against Regexp in test

Also add missing test file
@strk
Copy link
Member Author

strk commented Jan 3, 2018

pushed binary output, and the test file which was previously missing

@lafriks
Copy link
Member

lafriks commented Jan 3, 2018

Also I think it would be better to use RunInDirPipeline and stream stdout io.Copy it later directly to response writer to not use so much memory for large diffs

@strk
Copy link
Member Author

strk commented Jan 3, 2018

yes, I like that better too, now if I'd knew how to do it :)
Same for GetDiff ... but we need a different name for the piping version, so not to break API

package git

import (
"testing"
Copy link
Member

Choose a reason for hiding this comment

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

maybe add an empty line here.

Copy link
Member Author

Choose a reason for hiding this comment

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

done with 9783381

@@ -73,3 +73,8 @@ func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch stri
func (repo *Repository) GetPatch(base, head string) ([]byte, error) {
return NewCommand("diff", "-p", "--binary", base, head).RunInDirBytes(repo.Path)
}

// GetFormatPatch generates and returns format-patch data between given revisions.
func (repo *Repository) GetFormatPatch(base, head string) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

For the gitea PR I'd implement a GetFormatPatchReader(base, head string) (io.ReadCloser, error) as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm out of time for today so what about merging this and then improve later ? I'm looking forward for your PR implementing the "Reader" version of both methods (GetPatchReader and GEtFormatPatchReader)

Copy link

Choose a reason for hiding this comment

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

Merging @strk PR would be much appreciated.

@lafriks lafriks merged commit b3e9f25 into go-gitea:master Jan 5, 2018
@strk strk deleted the GetFormatPatch branch January 5, 2018 18:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants