Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .benchspotter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/recall/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4,511 changes: 4,511 additions & 0 deletions .benchspotter/sessions/01a1208c-0b84-756b-ae17-41dad78c5d66/escape.txt

Large diffs are not rendered by default.

777 changes: 777 additions & 0 deletions .benchspotter/sessions/01a1208c-0b84-756b-ae17-41dad78c5d66/inline.txt

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "baseline",
"benchs": [
"BenchmarkConfig",
"BenchmarkEnv/Load",
"BenchmarkEnv/LoadProtected",
"BenchmarkEnv/UpdateFile",
"BenchmarkEnv/UpdateFileUnchanged",
"BenchmarkParse",
"BenchmarkFile"
],
"git_commit": "74c4f677f7d380f117dd4e27dccad1b7bc042184",
"machine": {
"goos": "linux",
"goarch": "amd64",
"num_cpu": 12,
"physical_cores": 6,
"threads_per_core": 2,
"cpu": "AMD Ryzen 5 3600 6-Core Processor",
"cache_l1d": 32768,
"cache_l2": 524288,
"cache_l3": 16777216
},
"go_version": "go1.27.1"
}

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "probes",
"benchs": [
"BenchmarkProbe"
],
"git_commit": "74c4f677f7d380f117dd4e27dccad1b7bc042184",
"machine": {
"goos": "linux",
"goarch": "amd64",
"num_cpu": 12,
"physical_cores": 6,
"threads_per_core": 2,
"cpu": "AMD Ryzen 5 3600 6-Core Processor",
"cache_l1d": 32768,
"cache_l2": 524288,
"cache_l3": 16777216
},
"go_version": "go1.27.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
goos: linux
goarch: amd64
pkg: github.com/git-bug/gitconfig
cpu: AMD Ryzen 5 3600 6-Core Processor

BenchmarkProbe/UnsetAllSections/n=256-12 1214 986139 ns/op 222858 B/op 52 allocs/op
BenchmarkProbe/UnsetAllSections/n=256-12 1204 990883 ns/op 222849 B/op 52 allocs/op
BenchmarkProbe/UnsetAllSections/n=256-12 1213 1.010632e+06 ns/op 222849 B/op 52 allocs/op
BenchmarkProbe/UnsetAllFlat/n=256-12 2242 526884 ns/op 168832 B/op 52 allocs/op
BenchmarkProbe/UnsetAllFlat/n=256-12 2242 518990 ns/op 168832 B/op 52 allocs/op
BenchmarkProbe/UnsetAllFlat/n=256-12 2272 523023 ns/op 168832 B/op 52 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=256-12 19441 61817 ns/op 160481 B/op 57 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=256-12 19671 60646 ns/op 160480 B/op 57 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=256-12 19303 61461 ns/op 160480 B/op 57 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=256-12 17032 71112 ns/op 168393 B/op 303 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=256-12 16491 72511 ns/op 168393 B/op 303 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=256-12 16771 71676 ns/op 168393 B/op 303 allocs/op
BenchmarkProbe/RemoveSectionSections/n=256-12 15346 78806 ns/op 213305 B/op 48 allocs/op
BenchmarkProbe/RemoveSectionSections/n=256-12 15358 78362 ns/op 213304 B/op 48 allocs/op
BenchmarkProbe/RemoveSectionSections/n=256-12 15223 78671 ns/op 213304 B/op 48 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=256-12 738 1.632159e+06 ns/op 684595 B/op 5954 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=256-12 724 1.64687e+06 ns/op 684595 B/op 5954 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=256-12 730 1.642532e+06 ns/op 684594 B/op 5954 allocs/op
BenchmarkProbe/UnsetAllSections/n=1024-12 76 1.573481e+07 ns/op 1.014829e+06 B/op 66 allocs/op
BenchmarkProbe/UnsetAllSections/n=1024-12 75 1.5914246e+07 ns/op 1.01483e+06 B/op 66 allocs/op
BenchmarkProbe/UnsetAllSections/n=1024-12 76 1.5651015e+07 ns/op 1.01483e+06 B/op 66 allocs/op
BenchmarkProbe/UnsetAllFlat/n=1024-12 140 8.511731e+06 ns/op 982063 B/op 67 allocs/op
BenchmarkProbe/UnsetAllFlat/n=1024-12 141 8.474946e+06 ns/op 982062 B/op 67 allocs/op
BenchmarkProbe/UnsetAllFlat/n=1024-12 138 8.596572e+06 ns/op 982061 B/op 67 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=1024-12 4036 288188 ns/op 946276 B/op 70 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=1024-12 4200 287403 ns/op 946275 B/op 70 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=1024-12 4214 290750 ns/op 946276 B/op 70 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=1024-12 2360 505646 ns/op 1.982294e+06 B/op 1079 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=1024-12 2403 486532 ns/op 1.982296e+06 B/op 1079 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=1024-12 2577 492874 ns/op 1.982295e+06 B/op 1079 allocs/op
BenchmarkProbe/RemoveSectionSections/n=1024-12 3654 340132 ns/op 977854 B/op 60 allocs/op
BenchmarkProbe/RemoveSectionSections/n=1024-12 3583 348576 ns/op 977853 B/op 60 allocs/op
BenchmarkProbe/RemoveSectionSections/n=1024-12 3486 345554 ns/op 977854 B/op 60 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=1024-12 180 6.586774e+06 ns/op 2.81671e+06 B/op 23631 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=1024-12 183 6.480406e+06 ns/op 2.816709e+06 B/op 23631 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=1024-12 183 6.524314e+06 ns/op 2.816715e+06 B/op 23631 allocs/op
BenchmarkProbe/UnsetAllSections/n=4096-12 4 2.86652704e+08 ns/op 4.161488e+06 B/op 92 allocs/op
BenchmarkProbe/UnsetAllSections/n=4096-12 4 2.96065105e+08 ns/op 4.161488e+06 B/op 92 allocs/op
BenchmarkProbe/UnsetAllSections/n=4096-12 4 2.90395055e+08 ns/op 4.161544e+06 B/op 93 allocs/op
BenchmarkProbe/UnsetAllFlat/n=4096-12 8 1.39637449e+08 ns/op 3.92391e+06 B/op 93 allocs/op
BenchmarkProbe/UnsetAllFlat/n=4096-12 8 1.3865881e+08 ns/op 3.923896e+06 B/op 93 allocs/op
BenchmarkProbe/UnsetAllFlat/n=4096-12 8 1.38232921e+08 ns/op 3.923938e+06 B/op 93 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=4096-12 694 1.74319e+06 ns/op 3.777282e+06 B/op 84 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=4096-12 596 1.923503e+06 ns/op 3.777278e+06 B/op 84 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=4096-12 637 1.852339e+06 ns/op 3.777276e+06 B/op 84 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=4096-12 230 5.192618e+06 ns/op 2.8214256e+07 B/op 4164 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=4096-12 230 5.140154e+06 ns/op 2.8214258e+07 B/op 4164 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=4096-12 230 5.269271e+06 ns/op 2.8214286e+07 B/op 4164 allocs/op
BenchmarkProbe/RemoveSectionSections/n=4096-12 525 2.310713e+06 ns/op 4.01364e+06 B/op 74 allocs/op
BenchmarkProbe/RemoveSectionSections/n=4096-12 546 2.299224e+06 ns/op 4.013644e+06 B/op 74 allocs/op
BenchmarkProbe/RemoveSectionSections/n=4096-12 538 2.278819e+06 ns/op 4.013644e+06 B/op 74 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=4096-12 42 2.7449247e+07 ns/op 1.1423055e+07 B/op 94301 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=4096-12 42 2.7776282e+07 ns/op 1.1423061e+07 B/op 94301 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=4096-12 43 2.7625295e+07 ns/op 1.1423066e+07 B/op 94301 allocs/op
Binary file not shown.
144 changes: 144 additions & 0 deletions .benchspotter/sessions/01a120a2-f2e8-7ce8-a8ac-b6a8bebf1cbb/git.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
diff --git a/edit.go b/edit.go
index 75c1521..3862ece 100644
--- a/edit.go
+++ b/edit.go
@@ -311,10 +311,6 @@ func (f *File) entryLineEnd(i int) int {
// after the previous header or a BOM (the rest of its line becomes a
// newline), and ends at the next header, its indentation included.
func (f *File) unsetEntries(idx []int) []splice {
- removed := make(map[int]bool, len(idx))
- for _, i := range idx {
- removed[i] = true
- }
// Comments at the end of a removed entry's line play no part.
trailing := make(map[int]bool)
for _, i := range idx {
@@ -324,10 +320,21 @@ func (f *File) unsetEntries(idx []int) []splice {
}
}
}
+ // comments[j] counts the comments of items[:j] that play a part.
+ comments := make([]int, len(f.items)+1)
+ for j, it := range f.items {
+ comments[j+1] = comments[j]
+ if it.kind == itemComment && !trailing[j] {
+ comments[j+1]++
+ }
+ }

- var splices []splice
- for _, i := range idx {
- splices = append(splices, f.unsetEntry(i, removed, trailing))
+ // From the last entry back, so that a forward scan reaching a removed
+ // entry can stop where that entry's own scan did.
+ forward := make(map[int]int, len(idx))
+ splices := make([]splice, len(idx))
+ for n := len(idx) - 1; n >= 0; n-- {
+ splices[n] = f.unsetEntry(idx[n], forward, comments)
}

// Merge the regions that overlap: a region may hold other entries.
@@ -343,7 +350,11 @@ func (f *File) unsetEntries(idx []int) []splice {
return merged
}

-func (f *File) unsetEntry(i int, removed, trailing map[int]bool) splice {
+// unsetEntry returns the splice that removes the entry at i. forward holds
+// where the forward scan of each removed entry after i stopped; the scan of
+// i is added to it. comments counts the comments that play a part, as
+// unsetEntries computes it.
+func (f *File) unsetEntry(i int, forward map[int]int, comments []int) splice {
sec := f.items[i].sec
sameHeader := func(it item) bool { return it.kind == itemHeader && f.secOf(it) == f.secs[sec] }

@@ -360,11 +371,17 @@ func (f *File) unsetEntry(i int, removed, trailing map[int]bool) splice {
}
fw := i + 1
for ; fw < len(f.items); fw++ {
+ if end, ok := forward[fw]; ok {
+ // A removed entry: the scan goes on as its own did.
+ fw = end
+ break
+ }
it := f.items[fw]
- if it.kind == itemEntry && !removed[fw] || it.kind == itemHeader && !sameHeader(it) {
+ if it.kind == itemEntry || it.kind == itemHeader && !sameHeader(it) {
break
}
}
+ forward[i] = fw
if !headers || fw < len(f.items) && f.items[fw].kind == itemEntry {
return f.removeEntry(i)
}
@@ -385,10 +402,10 @@ func (f *File) unsetEntry(i int, removed, trailing map[int]bool) splice {
if fw < len(f.items) {
end = f.items[fw].start
}
- for j, it := range f.items {
- if it.kind == itemComment && it.start >= start && it.end <= end && !trailing[j] {
- return f.removeEntry(i)
- }
+ // The region is items[from:fw]: start and end are item boundaries.
+ from, _ := slices.BinarySearchFunc(f.items, start, func(it item, start int) int { return it.start - start })
+ if comments[fw]-comments[from] > 0 {
+ return f.removeEntry(i)
}
return splice{start, end, text}
}
@@ -505,18 +522,19 @@ func (f *File) renameSection(name string, sk, to sectionKey, header string) erro
if n := f.newlineAfter(h); n >= 0 {
end = n + 1
}
- text := header + "\n"
+ var text strings.Builder
+ text.WriteString(header + "\n")
if rest < end && f.items[rest].kind != itemNewline {
- text += "\t"
+ text.WriteByte('\t')
for _, it := range f.items[rest:end] {
if it.kind == itemHeader && f.secOf(it) == sk {
- text += header
+ text.WriteString(header)
} else {
- text += string(f.data[it.start:it.end])
+ text.Write(f.data[it.start:it.end])
}
}
}
- splices = append(splices, splice{f.ownStart(h), f.lineEnd(h), text})
+ splices = append(splices, splice{f.ownStart(h), f.lineEnd(h), text.String()})
done = end - 1
}
return f.apply(name, splices, func(before, after []flatEntry) bool {
diff --git a/load.go b/load.go
index ac7a002..0d2b65e 100644
--- a/load.go
+++ b/load.go
@@ -175,6 +175,9 @@ type loader struct {

branch string
branchRead bool
+
+ realGitDir string // with '/', "" if it cannot be resolved
+ realDirRead bool
}

func (e Env) newLoader() (*loader, error) {
@@ -353,10 +356,14 @@ func (l *loader) gitdir(pattern, from string, fold bool) (bool, error) {
if globMatch(pattern, dir, fold) {
return true, nil
}
- if real, err := filepath.EvalSymlinks(l.repo.gitDir); err == nil {
- if real := filepath.ToSlash(real); real != dir {
- return globMatch(pattern, real, fold), nil
+ if !l.realDirRead {
+ if real, err := filepath.EvalSymlinks(l.repo.gitDir); err == nil {
+ l.realGitDir = filepath.ToSlash(real)
}
+ l.realDirRead = true
+ }
+ if l.realGitDir != "" && l.realGitDir != dir {
+ return globMatch(pattern, l.realGitDir, fold), nil
}
return false, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "probes-fixed",
"benchs": [
"BenchmarkProbe"
],
"git_commit": "74c4f677f7d380f117dd4e27dccad1b7bc042184",
"machine": {
"goos": "linux",
"goarch": "amd64",
"num_cpu": 12,
"physical_cores": 6,
"threads_per_core": 2,
"cpu": "AMD Ryzen 5 3600 6-Core Processor",
"cache_l1d": 32768,
"cache_l2": 524288,
"cache_l3": 16777216
},
"go_version": "go1.27.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
goos: linux
goarch: amd64
pkg: github.com/git-bug/gitconfig
cpu: AMD Ryzen 5 3600 6-Core Processor

BenchmarkProbe/UnsetAllSections/n=256-12 8848 126797 ns/op 224195 B/op 46 allocs/op
BenchmarkProbe/UnsetAllSections/n=256-12 9118 128210 ns/op 224192 B/op 46 allocs/op
BenchmarkProbe/UnsetAllSections/n=256-12 9129 128586 ns/op 224192 B/op 46 allocs/op
BenchmarkProbe/UnsetAllFlat/n=256-12 15631 76657 ns/op 165824 B/op 46 allocs/op
BenchmarkProbe/UnsetAllFlat/n=256-12 15644 77720 ns/op 165824 B/op 46 allocs/op
BenchmarkProbe/UnsetAllFlat/n=256-12 15744 75660 ns/op 165824 B/op 46 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=256-12 19417 62517 ns/op 160480 B/op 57 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=256-12 19240 61979 ns/op 160480 B/op 57 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=256-12 19669 61454 ns/op 160480 B/op 57 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=256-12 24957 46795 ns/op 63696 B/op 50 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=256-12 25459 46907 ns/op 63696 B/op 50 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=256-12 26306 45686 ns/op 63696 B/op 50 allocs/op
BenchmarkProbe/RemoveSectionSections/n=256-12 15030 80256 ns/op 213304 B/op 48 allocs/op
BenchmarkProbe/RemoveSectionSections/n=256-12 14792 80997 ns/op 213304 B/op 48 allocs/op
BenchmarkProbe/RemoveSectionSections/n=256-12 15039 80380 ns/op 213304 B/op 48 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=256-12 3999 292125 ns/op 470418 B/op 3149 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=256-12 4120 291655 ns/op 470418 B/op 3149 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=256-12 4045 299015 ns/op 470417 B/op 3149 allocs/op
BenchmarkProbe/UnsetAllSections/n=1024-12 2222 533993 ns/op 977389 B/op 57 allocs/op
BenchmarkProbe/UnsetAllSections/n=1024-12 2323 541567 ns/op 977390 B/op 57 allocs/op
BenchmarkProbe/UnsetAllSections/n=1024-12 2140 561709 ns/op 977391 B/op 57 allocs/op
BenchmarkProbe/UnsetAllFlat/n=1024-12 3334 341217 ns/op 922733 B/op 58 allocs/op
BenchmarkProbe/UnsetAllFlat/n=1024-12 3610 342554 ns/op 922732 B/op 58 allocs/op
BenchmarkProbe/UnsetAllFlat/n=1024-12 3540 346555 ns/op 922733 B/op 58 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=1024-12 4158 307842 ns/op 946276 B/op 70 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=1024-12 4003 318898 ns/op 946276 B/op 70 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=1024-12 4124 309992 ns/op 946278 B/op 70 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=1024-12 6123 179341 ns/op 306129 B/op 62 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=1024-12 6516 179272 ns/op 306129 B/op 62 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=1024-12 6736 179813 ns/op 306129 B/op 62 allocs/op
BenchmarkProbe/RemoveSectionSections/n=1024-12 3250 377700 ns/op 977854 B/op 60 allocs/op
BenchmarkProbe/RemoveSectionSections/n=1024-12 3145 374978 ns/op 977855 B/op 60 allocs/op
BenchmarkProbe/RemoveSectionSections/n=1024-12 3189 366536 ns/op 977853 B/op 60 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=1024-12 1074 1.136291e+06 ns/op 1.957399e+06 B/op 12378 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=1024-12 1044 1.174265e+06 ns/op 1.9574e+06 B/op 12378 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=1024-12 1011 1.195348e+06 ns/op 1.9574e+06 B/op 12378 allocs/op
BenchmarkProbe/UnsetAllSections/n=4096-12 416 2.928603e+06 ns/op 4.042093e+06 B/op 80 allocs/op
BenchmarkProbe/UnsetAllSections/n=4096-12 394 3.150212e+06 ns/op 4.042095e+06 B/op 80 allocs/op
BenchmarkProbe/UnsetAllSections/n=4096-12 382 3.067227e+06 ns/op 4.042092e+06 B/op 80 allocs/op
BenchmarkProbe/UnsetAllFlat/n=4096-12 618 1.86093e+06 ns/op 3.73899e+06 B/op 81 allocs/op
BenchmarkProbe/UnsetAllFlat/n=4096-12 662 1.841739e+06 ns/op 3.73899e+06 B/op 81 allocs/op
BenchmarkProbe/UnsetAllFlat/n=4096-12 650 1.870803e+06 ns/op 3.73899e+06 B/op 81 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=4096-12 736 1.624229e+06 ns/op 3.777274e+06 B/op 84 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=4096-12 722 1.625224e+06 ns/op 3.777273e+06 B/op 84 allocs/op
BenchmarkProbe/ReplaceAllFlat/n=4096-12 733 1.625364e+06 ns/op 3.777274e+06 B/op 84 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=4096-12 1546 779117 ns/op 1.594459e+06 B/op 79 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=4096-12 1620 756191 ns/op 1.594459e+06 B/op 79 allocs/op
BenchmarkProbe/RenameSectionOneLine/n=4096-12 1562 757840 ns/op 1.594459e+06 B/op 79 allocs/op
BenchmarkProbe/RemoveSectionSections/n=4096-12 549 2.265801e+06 ns/op 4.013646e+06 B/op 74 allocs/op
BenchmarkProbe/RemoveSectionSections/n=4096-12 516 2.31401e+06 ns/op 4.013645e+06 B/op 74 allocs/op
BenchmarkProbe/RemoveSectionSections/n=4096-12 534 2.275376e+06 ns/op 4.013646e+06 B/op 74 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=4096-12 206 5.824772e+06 ns/op 7.983289e+06 B/op 49256 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=4096-12 200 5.966529e+06 ns/op 7.983288e+06 B/op 49256 allocs/op
BenchmarkProbe/LoadIncludeIfGitdir/n=4096-12 200 5.946946e+06 ns/op 7.983294e+06 B/op 49256 allocs/op
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading