aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-04-10 14:03:00 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-04-11 04:37:12 +0200
commitaf4f25df56c74b05ae04cc6f2fcac38db1130249 (patch)
treeda276939908a9dc7b0ca2e0935b3f569aaba835e
parent9e0ae961aeb4969eb2756a961bc7721e4788fc21 (diff)
downloadgo-git-af4f25df56c74b05ae04cc6f2fcac38db1130249.tar.gz
plumbing: format, index stringer
-rw-r--r--plumbing/format/index/index.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/plumbing/format/index/index.go b/plumbing/format/index/index.go
index ee50efd..3675c4e 100644
--- a/plumbing/format/index/index.go
+++ b/plumbing/format/index/index.go
@@ -2,6 +2,7 @@ package index
import (
"errors"
+ "fmt"
"time"
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -47,6 +48,16 @@ type Index struct {
ResolveUndo *ResolveUndo
}
+// String is equivalent to `git ls-files --stage --debug`
+func (i *Index) String() string {
+ var o string
+ for _, e := range i.Entries {
+ o += e.String()
+ }
+
+ return o
+}
+
// 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 +89,18 @@ type Entry struct {
IntentToAdd bool
}
+func (e Entry) String() string {
+ var o string
+ o += fmt.Sprintf("%06o %s %d\t%s\n", e.Mode, e.Hash, e.Stage, e.Name)
+ o += fmt.Sprintf(" ctime: %d:%d\n", e.CreatedAt.Unix(), e.CreatedAt.Nanosecond())
+ o += fmt.Sprintf(" mtime: %d:%d\n", e.ModifiedAt.Unix(), e.ModifiedAt.Nanosecond())
+ o += fmt.Sprintf(" dev: %d\tino: %d\n", e.Dev, e.Inode)
+ o += fmt.Sprintf(" uid: %d\tgid: %d\n", e.UID, e.GID)
+ o += fmt.Sprintf(" size: %d\tflags: %x\n", e.Size, 0)
+
+ return o
+}
+
// 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 {