@@ -233,72 +233,34 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int,
233
233
return numFiles , totalAdditions , totalDeletions , err
234
234
}
235
235
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
-
247
236
// 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 {
249
238
stderr := new (bytes.Buffer )
250
- err := NewCommand (repo .Ctx , "diff" , "-p" ).AddDynamicArguments (base + "..." + head ).
239
+ return NewCommand (repo .Ctx , "diff" , "-p" ).AddDynamicArguments (compareArg ).
251
240
Run (& RunOpts {
252
241
Dir : repo .Path ,
253
242
Stdout : w ,
254
243
Stderr : stderr ,
255
244
})
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
264
245
}
265
246
266
247
// 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
+ })
283
253
}
284
254
285
255
// 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 {
287
257
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 ).
289
259
Run (& RunOpts {
290
260
Dir : repo .Path ,
291
261
Stdout : w ,
292
262
Stderr : stderr ,
293
263
})
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
302
264
}
303
265
304
266
// 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
329
291
return split , err
330
292
}
331
293
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
-
347
294
// ReadPatchCommit will check if a diff patch exists and return stats
348
295
func (repo * Repository ) ReadPatchCommit (prID int64 ) (commitSHA string , err error ) {
349
296
// Migrated repositories download patches to "pulls" location
0 commit comments