summaryrefslogtreecommitdiff
path: root/repo.SortByAge.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-25 23:06:44 -0500
committerJeff Carr <[email protected]>2025-10-25 23:06:44 -0500
commit18af5566eb10592f4308aec08c2f72808dab82aa (patch)
tree3523143da7613df499b791e9ba874eaddca1a132 /repo.SortByAge.go
parent868422cb5ec2f43bc861eeb8aad23f7c3387c940 (diff)
doesn't work
Diffstat (limited to 'repo.SortByAge.go')
-rw-r--r--repo.SortByAge.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/repo.SortByAge.go b/repo.SortByAge.go
new file mode 100644
index 0000000..458a9a0
--- /dev/null
+++ b/repo.SortByAge.go
@@ -0,0 +1,28 @@
+package gitpb
+
+import "sort"
+
+func (x *Repos) SortByAge() *RepoScanner {
+ // copy the pointers as fast as possible.
+ things := x.selectAllRepos()
+
+ // todo: try slices.SortFunc() instead to see what happens
+ sort.Sort(sortReposAge(things))
+ // slices.SortFunc(things, func(a, b *Repos) bool {
+ // return a.Namespace < b.Namespace // Sort by ??. let the compiler work it out??
+ // })
+ return newRepoScanner(things)
+}
+
+type sortReposAge []*Repo
+
+func (a sortReposAge) Len() int { return len(a) }
+
+// sorts in ? order
+func (r sortReposAge) Less(i, j int) bool {
+ if r[i].NewestAge() > r[j].NewestAge() {
+ return true
+ }
+ return false
+}
+func (a sortReposAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }