aboutsummaryrefslogtreecommitdiffstats
path: root/commit.go
diff options
context:
space:
mode:
Diffstat (limited to 'commit.go')
-rw-r--r--commit.go38
1 files changed, 36 insertions, 2 deletions
diff --git a/commit.go b/commit.go
index 4a4fe25..f102796 100644
--- a/commit.go
+++ b/commit.go
@@ -97,8 +97,8 @@ func (c *Commit) Decode(o core.Object) (err error) {
return err
}
- line = bytes.TrimSpace(line)
if !message {
+ line = bytes.TrimSpace(line)
if len(line) == 0 {
message = true
continue
@@ -116,7 +116,7 @@ func (c *Commit) Decode(o core.Object) (err error) {
c.Committer.Decode(split[1])
}
} else {
- c.Message += string(line) + "\n"
+ c.Message += string(line)
}
if err == io.EOF {
@@ -137,6 +137,40 @@ func (c *Commit) History() ([]*Commit, error) {
return commits, err
}
+// Encode transforms a Commit into a core.Object.
+func (b *Commit) Encode(o core.Object) error {
+ o.SetType(core.CommitObject)
+ w, err := o.Writer()
+ if err != nil {
+ return err
+ }
+ defer checkClose(w, &err)
+ if _, err = fmt.Fprintf(w, "tree %s\n", b.tree.String()); err != nil {
+ return err
+ }
+ for _, parent := range b.parents {
+ if _, err = fmt.Fprintf(w, "parent %s\n", parent.String()); err != nil {
+ return err
+ }
+ }
+ if _, err = fmt.Fprint(w, "author "); err != nil {
+ return err
+ }
+ if err = b.Author.Encode(w); err != nil {
+ return err
+ }
+ if _, err = fmt.Fprint(w, "\ncommitter "); err != nil {
+ return err
+ }
+ if err = b.Committer.Encode(w); err != nil {
+ return err
+ }
+ if _, err = fmt.Fprintf(w, "\n\n%s", b.Message); err != nil {
+ return err
+ }
+ return err
+}
+
func (c *Commit) String() string {
return fmt.Sprintf(
"%s %s\nAuthor: %s\nDate: %s\n",