You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

patch.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package diff
  2. import (
  3. "github.com/go-git/go-git/v5/plumbing"
  4. "github.com/go-git/go-git/v5/plumbing/filemode"
  5. )
  6. // Operation defines the operation of a diff item.
  7. type Operation int
  8. const (
  9. // Equal item represents a equals diff.
  10. Equal Operation = iota
  11. // Add item represents an insert diff.
  12. Add
  13. // Delete item represents a delete diff.
  14. Delete
  15. )
  16. // Patch represents a collection of steps to transform several files.
  17. type Patch interface {
  18. // FilePatches returns a slice of patches per file.
  19. FilePatches() []FilePatch
  20. // Message returns an optional message that can be at the top of the
  21. // Patch representation.
  22. Message() string
  23. }
  24. // FilePatch represents the necessary steps to transform one file to another.
  25. type FilePatch interface {
  26. // IsBinary returns true if this patch is representing a binary file.
  27. IsBinary() bool
  28. // Files returns the from and to Files, with all the necessary metadata to
  29. // about them. If the patch creates a new file, "from" will be nil.
  30. // If the patch deletes a file, "to" will be nil.
  31. Files() (from, to File)
  32. // Chunks returns a slice of ordered changes to transform "from" File to
  33. // "to" File. If the file is a binary one, Chunks will be empty.
  34. Chunks() []Chunk
  35. }
  36. // File contains all the file metadata necessary to print some patch formats.
  37. type File interface {
  38. // Hash returns the File Hash.
  39. Hash() plumbing.Hash
  40. // Mode returns the FileMode.
  41. Mode() filemode.FileMode
  42. // Path returns the complete Path to the file, including the filename.
  43. Path() string
  44. }
  45. // Chunk represents a portion of a file transformation to another.
  46. type Chunk interface {
  47. // Content contains the portion of the file.
  48. Content() string
  49. // Type contains the Operation to do with this Chunk.
  50. Type() Operation
  51. }