Skip to content

Commit 1e05b25

Browse files
committed
Don't include the root tree in MaxPathDepth
It is more natural to define the length of a relative path `foo/bar/baz.txt` as 3 rather than 4, so tweak the code to do so.
1 parent 27d083c commit 1e05b25

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Processing references: 539
132132
| | | |
133133
| Biggest checkouts | | |
134134
| * Number of directories [6] | 4.38 k | ** |
135-
| * Maximum path depth [7] | 14 | * |
135+
| * Maximum path depth [7] | 13 | * |
136136
| * Maximum path length [8] | 134 B | * |
137137
| * Number of files [9] | 62.3 k | * |
138138
| * Total size of files [9] | 747 MiB | |

git_sizer_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func TestBomb(t *testing.T) {
190190

191191
assert.Equal(counts.Count32(1), h.ReferenceCount, "reference count")
192192

193-
assert.Equal(counts.Count32(11), h.MaxPathDepth, "max path depth")
193+
assert.Equal(counts.Count32(10), h.MaxPathDepth, "max path depth")
194194
assert.Equal("refs/heads/master^{tree}", h.MaxPathDepthTree.Path(), "max path depth tree")
195195
assert.Equal(counts.Count32(29), h.MaxPathLength, "max path length")
196196
assert.Equal("refs/heads/master^{tree}", h.MaxPathLengthTree.Path(), "max path length tree")
@@ -272,10 +272,11 @@ func TestFromSubdir(t *testing.T) {
272272

273273
repo2, err := git.NewRepository(filepath.Join(path, "subdir"))
274274
require.NoError(t, err, "creating Repository object in subdirectory")
275-
_, err = sizes.ScanRepositoryUsingGraph(
275+
h, err := sizes.ScanRepositoryUsingGraph(
276276
repo2, git.AllReferencesFilter, sizes.NameStyleNone, false,
277277
)
278278
require.NoError(t, err, "scanning repository")
279+
assert.Equal(t, counts.Count32(2), h.MaxPathDepth, "max path depth")
279280
}
280281

281282
func TestSubmodule(t *testing.T) {

sizes/graph.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,6 @@ func (r *treeRecord) initialize(g *Graph, oid git.OID, tree *git.Tree) error {
609609

610610
func (r *treeRecord) maybeFinalize(g *Graph) {
611611
if r.pending == 0 {
612-
// Add one for this tree itself:
613-
r.size.MaxPathDepth.Increment(1)
614-
615612
g.finalizeTreeSize(r.oid, r.size, r.objectSize, r.entryCount)
616613
for _, listener := range r.listeners {
617614
listener(r.size)

sizes/sizes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type BlobSize struct {
1717

1818
type TreeSize struct {
1919
// The maximum depth of trees and blobs starting at this object
20-
// (including this object).
20+
// (not including this object).
2121
MaxPathDepth counts.Count32 `json:"max_path_depth"`
2222

2323
// The maximum length of any path relative to this object, in
@@ -41,7 +41,7 @@ type TreeSize struct {
4141
}
4242

4343
func (s *TreeSize) addDescendent(filename string, s2 TreeSize) {
44-
s.MaxPathDepth.AdjustMaxIfNecessary(s2.MaxPathDepth)
44+
s.MaxPathDepth.AdjustMaxIfNecessary(s2.MaxPathDepth.Plus(1))
4545
if s2.MaxPathLength > 0 {
4646
s.MaxPathLength.AdjustMaxIfNecessary(
4747
(counts.NewCount32(uint64(len(filename))) + 1).Plus(s2.MaxPathLength),
@@ -164,7 +164,7 @@ type HistorySize struct {
164164
// attribute is maximized separately).
165165

166166
// The maximum depth of trees and blobs starting at this object
167-
// (including this object).
167+
// (not including this object).
168168
MaxPathDepth counts.Count32 `json:"max_path_depth"`
169169

170170
// The tree with the maximum path depth.

0 commit comments

Comments
 (0)