diff options
author | Alex Goodman <wagoodman@gmail.com> | 2018-10-31 00:11:35 -0400 |
---|---|---|
committer | Alex Goodman <wagoodman@gmail.com> | 2018-10-31 00:11:43 -0400 |
commit | f3f2ec9a8c09ab379e8afe2a9e34efbd04060681 (patch) | |
tree | 075246d8770f5c26cca9e543f9279862a69d9f3e /filetree/node.go | |
parent | f40600e877e135ac1f119680b9d77fab5f71cc87 (diff) |
correct nested diff colors and dir sizing (fixes #45)
Diffstat (limited to 'filetree/node.go')
-rw-r--r-- | filetree/node.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/filetree/node.go b/filetree/node.go index 95cc854..233692a 100644 --- a/filetree/node.go +++ b/filetree/node.go @@ -147,18 +147,19 @@ func (node *FileNode) MetadataString() string { var sizeBytes int64 - if node.Data.FileInfo.TarHeader.FileInfo().IsDir() { - + if node.IsLeaf() { + sizeBytes = node.Data.FileInfo.TarHeader.FileInfo().Size() + } else { sizer := func(curNode *FileNode) error { - if curNode.Data.DiffType != Removed { + // don't include file sizes of children that have been removed (unless the node in question is a removed dir, + // then show the accumulated size of removed files) + if curNode.Data.DiffType != Removed || node.Data.DiffType == Removed { sizeBytes += curNode.Data.FileInfo.TarHeader.FileInfo().Size() } return nil } node.VisitDepthChildFirst(sizer, nil) - } else { - sizeBytes = node.Data.FileInfo.TarHeader.FileInfo().Size() } size := humanize.Bytes(uint64(sizeBytes)) @@ -254,7 +255,7 @@ func (node *FileNode) Path() string { } node.path = "/" + strings.Join(path, "/") } - return node.path + return strings.Replace(node.path, "//", "/", -1) } // deriveDiffType determines a DiffType to the current FileNode. Note: the DiffType of a node is always the DiffType of |