aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-04-12 15:18:41 +0200
committerGitHub <noreply@github.com>2017-04-12 15:18:41 +0200
commit932ced9f55f556de02610425cfa161c35c6a758b (patch)
tree9b5dd9ad1665fad8424dfbdc5bd93b531f714b09 /plumbing/format
parent9b45f468c61a0756dd19d09b64c2b1a88cc99ec5 (diff)
parent5bcf802213e801c4d52102612f007defa5d0397f (diff)
downloadgo-git-932ced9f55f556de02610425cfa161c35c6a758b.tar.gz
Merge pull request #339 from mcuadros/status
worktree, status and reset implementation based on merkletrie
Diffstat (limited to 'plumbing/format')
-rw-r--r--plumbing/format/index/index.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/plumbing/format/index/index.go b/plumbing/format/index/index.go
index ee50efd..61e7d66 100644
--- a/plumbing/format/index/index.go
+++ b/plumbing/format/index/index.go
@@ -2,8 +2,11 @@ package index
import (
"errors"
+ "fmt"
"time"
+ "bytes"
+
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
)
@@ -47,6 +50,16 @@ type Index struct {
ResolveUndo *ResolveUndo
}
+// String is equivalent to `git ls-files --stage --debug`
+func (i *Index) String() string {
+ buf := bytes.NewBuffer(nil)
+ for _, e := range i.Entries {
+ buf.WriteString(e.String())
+ }
+
+ return buf.String()
+}
+
// Entry represents a single file (or stage of a file) in the cache. An entry
// represents exactly one stage of a file. If a file path is unmerged then
// multiple Entry instances may appear for the same path name.
@@ -78,6 +91,19 @@ type Entry struct {
IntentToAdd bool
}
+func (e Entry) String() string {
+ buf := bytes.NewBuffer(nil)
+
+ fmt.Fprintf(buf, "%06o %s %d\t%s\n", e.Mode, e.Hash, e.Stage, e.Name)
+ fmt.Fprintf(buf, " ctime: %d:%d\n", e.CreatedAt.Unix(), e.CreatedAt.Nanosecond())
+ fmt.Fprintf(buf, " mtime: %d:%d\n", e.ModifiedAt.Unix(), e.ModifiedAt.Nanosecond())
+ fmt.Fprintf(buf, " dev: %d\tino: %d\n", e.Dev, e.Inode)
+ fmt.Fprintf(buf, " uid: %d\tgid: %d\n", e.UID, e.GID)
+ fmt.Fprintf(buf, " size: %d\tflags: %x\n", e.Size, 0)
+
+ return buf.String()
+}
+
// Tree contains pre-computed hashes for trees that can be derived from the
// index. It helps speed up tree object generation from index for a new commit.
type Tree struct {