diff options
author | Sunny <me@darkowlzz.space> | 2017-11-24 19:19:44 +0530 |
---|---|---|
committer | Sunny <me@darkowlzz.space> | 2017-11-24 19:19:44 +0530 |
commit | 850b9f81c2f025d8a75c4728520553504e3a425c (patch) | |
tree | 6bbeaef3ca37822e1171c16aefe52e6e96f89a94 /plumbing/object/tag.go | |
parent | d92d437af0fb23865c79e45b4acd3d7544593260 (diff) | |
download | go-git-850b9f81c2f025d8a75c4728520553504e3a425c.tar.gz |
plumbing: object/tag, add PGPSignature support
Diffstat (limited to 'plumbing/object/tag.go')
-rw-r--r-- | plumbing/object/tag.go | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/plumbing/object/tag.go b/plumbing/object/tag.go index d8b71a0..6295205 100644 --- a/plumbing/object/tag.go +++ b/plumbing/object/tag.go @@ -6,6 +6,7 @@ import ( "fmt" "io" stdioutil "io/ioutil" + "strings" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/storer" @@ -30,6 +31,8 @@ type Tag struct { Tagger Signature // Message is an arbitrary text message. Message string + // PGPSignature is the PGP signature of the tag. + PGPSignature string // TargetType is the object type of the target. TargetType plumbing.ObjectType // Target is the hash of the target object. @@ -124,7 +127,36 @@ func (t *Tag) Decode(o plumbing.EncodedObject) (err error) { if err != nil { return err } - t.Message = string(data) + + var pgpsig bool + // Check if data contains PGP signature. + if bytes.Contains(data, []byte(beginpgp)) { + // Split the lines at newline. + messageAndSig := bytes.Split(data, []byte("\n")) + + for _, l := range messageAndSig { + if pgpsig { + if bytes.Contains(l, []byte(endpgp)) { + t.PGPSignature += endpgp + "\n" + pgpsig = false + } else { + t.PGPSignature += string(l) + "\n" + } + continue + } + + // Check if it's the beginning of a PGP signature. + if bytes.Contains(l, []byte(beginpgp)) { + t.PGPSignature += beginpgp + "\n" + pgpsig = true + continue + } + + t.Message += string(l) + "\n" + } + } else { + t.Message = string(data) + } return nil } @@ -156,6 +188,16 @@ func (t *Tag) Encode(o plumbing.EncodedObject) error { return err } + if t.PGPSignature != "" { + // Split all the signature lines and write with a newline at the end. + lines := strings.Split(t.PGPSignature, "\n") + for _, line := range lines { + if _, err = fmt.Fprintf(w, "%s\n", line); err != nil { + return err + } + } + } + return err } |