@@ -233,72 +233,34 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int,
233233 return numFiles , totalAdditions , totalDeletions , err
234234}
235235
236- // GetDiffOrPatch generates either diff or formatted patch data between given revisions
237- func (repo * Repository ) GetDiffOrPatch (base , head string , w io.Writer , patch , binary bool ) error {
238- if patch {
239- return repo .GetPatch (base , head , w )
240- }
241- if binary {
242- return repo .GetDiffBinary (base , head , w )
243- }
244- return repo .GetDiff (base , head , w )
245- }
246-
247236// GetDiff generates and returns patch data between given revisions, optimized for human readability
248- func (repo * Repository ) GetDiff (base , head string , w io.Writer ) error {
237+ func (repo * Repository ) GetDiff (compareArg string , w io.Writer ) error {
249238 stderr := new (bytes.Buffer )
250- err := NewCommand (repo .Ctx , "diff" , "-p" ).AddDynamicArguments (base + "..." + head ).
239+ return NewCommand (repo .Ctx , "diff" , "-p" ).AddDynamicArguments (compareArg ).
251240 Run (& RunOpts {
252241 Dir : repo .Path ,
253242 Stdout : w ,
254243 Stderr : stderr ,
255244 })
256- if err != nil && bytes .Contains (stderr .Bytes (), []byte ("no merge base" )) {
257- return NewCommand (repo .Ctx , "diff" , "-p" ).AddDynamicArguments (base , head ).
258- Run (& RunOpts {
259- Dir : repo .Path ,
260- Stdout : w ,
261- })
262- }
263- return err
264245}
265246
266247// GetDiffBinary generates and returns patch data between given revisions, including binary diffs.
267- func (repo * Repository ) GetDiffBinary (base , head string , w io.Writer ) error {
268- stderr := new (bytes.Buffer )
269- err := NewCommand (repo .Ctx , "diff" , "-p" , "--binary" , "--histogram" ).AddDynamicArguments (base + "..." + head ).
270- Run (& RunOpts {
271- Dir : repo .Path ,
272- Stdout : w ,
273- Stderr : stderr ,
274- })
275- if err != nil && bytes .Contains (stderr .Bytes (), []byte ("no merge base" )) {
276- return NewCommand (repo .Ctx , "diff" , "-p" , "--binary" , "--histogram" ).AddDynamicArguments (base , head ).
277- Run (& RunOpts {
278- Dir : repo .Path ,
279- Stdout : w ,
280- })
281- }
282- return err
248+ func (repo * Repository ) GetDiffBinary (compareArg string , w io.Writer ) error {
249+ return NewCommand (repo .Ctx , "diff" , "-p" , "--binary" , "--histogram" ).AddDynamicArguments (compareArg ).Run (& RunOpts {
250+ Dir : repo .Path ,
251+ Stdout : w ,
252+ })
283253}
284254
285255// GetPatch generates and returns format-patch data between given revisions, able to be used with `git apply`
286- func (repo * Repository ) GetPatch (base , head string , w io.Writer ) error {
256+ func (repo * Repository ) GetPatch (compareArg string , w io.Writer ) error {
287257 stderr := new (bytes.Buffer )
288- err := NewCommand (repo .Ctx , "format-patch" , "--binary" , "--stdout" ).AddDynamicArguments (base + "..." + head ).
258+ return NewCommand (repo .Ctx , "format-patch" , "--binary" , "--stdout" ).AddDynamicArguments (compareArg ).
289259 Run (& RunOpts {
290260 Dir : repo .Path ,
291261 Stdout : w ,
292262 Stderr : stderr ,
293263 })
294- if err != nil && bytes .Contains (stderr .Bytes (), []byte ("no merge base" )) {
295- return NewCommand (repo .Ctx , "format-patch" , "--binary" , "--stdout" ).AddDynamicArguments (base , head ).
296- Run (& RunOpts {
297- Dir : repo .Path ,
298- Stdout : w ,
299- })
300- }
301- return err
302264}
303265
304266// GetFilesChangedBetween returns a list of all files that have been changed between the given commits
@@ -329,21 +291,6 @@ func (repo *Repository) GetFilesChangedBetween(base, head string) ([]string, err
329291 return split , err
330292}
331293
332- // GetDiffFromMergeBase generates and return patch data from merge base to head
333- func (repo * Repository ) GetDiffFromMergeBase (base , head string , w io.Writer ) error {
334- stderr := new (bytes.Buffer )
335- err := NewCommand (repo .Ctx , "diff" , "-p" , "--binary" ).AddDynamicArguments (base + "..." + head ).
336- Run (& RunOpts {
337- Dir : repo .Path ,
338- Stdout : w ,
339- Stderr : stderr ,
340- })
341- if err != nil && bytes .Contains (stderr .Bytes (), []byte ("no merge base" )) {
342- return repo .GetDiffBinary (base , head , w )
343- }
344- return err
345- }
346-
347294// ReadPatchCommit will check if a diff patch exists and return stats
348295func (repo * Repository ) ReadPatchCommit (prID int64 ) (commitSHA string , err error ) {
349296 // Migrated repositories download patches to "pulls" location
0 commit comments