Compare commits
No commits in common. "master" and "v0.0.9" have entirely different histories.
7
Makefile
7
Makefile
|
@ -10,13 +10,6 @@ build: goimports
|
||||||
ldd going2git
|
ldd going2git
|
||||||
LD_LIBRARY_PATH=/opt/libgit2 ./going2git --refs --repo .
|
LD_LIBRARY_PATH=/opt/libgit2 ./going2git --refs --repo .
|
||||||
|
|
||||||
run:
|
|
||||||
LD_LIBRARY_PATH=/opt/libgit2 ./going2git --refs --repo .
|
|
||||||
|
|
||||||
build-libgit2-prep:
|
|
||||||
cd /opt/ && git clone https://github.com/libgit2/libgit2.git
|
|
||||||
apt build-dep libgit2
|
|
||||||
|
|
||||||
build-libgit2:
|
build-libgit2:
|
||||||
cd /opt/libgit2/ && cmake .
|
cd /opt/libgit2/ && cmake .
|
||||||
cd /opt/libgit2/ && cmake --build .
|
cd /opt/libgit2/ && cmake --build .
|
||||||
|
|
1
argv.go
1
argv.go
|
@ -14,7 +14,6 @@ type args struct {
|
||||||
RepoPath string `arg:"--repo" default:"./" help:"path to the .git repo"`
|
RepoPath string `arg:"--repo" default:"./" help:"path to the .git repo"`
|
||||||
Hostname string `arg:"--hostname" help:"hostname to use"`
|
Hostname string `arg:"--hostname" help:"hostname to use"`
|
||||||
Refs bool `arg:"--refs" help:"list the git ref hashes"`
|
Refs bool `arg:"--refs" help:"list the git ref hashes"`
|
||||||
Tag string `arg:"--tag" help:"what tag name to walk"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (args) Version() string {
|
func (args) Version() string {
|
||||||
|
|
6
main.go
6
main.go
|
@ -35,12 +35,6 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
walkTree(t)
|
walkTree(t)
|
||||||
|
|
||||||
showtags(repo)
|
|
||||||
// v0.0.8
|
|
||||||
if argv.Tag != "" {
|
|
||||||
printCommitsForTag(repo, argv.Tag)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// lists the files in the git repo
|
// lists the files in the git repo
|
||||||
|
|
2
refs.go
2
refs.go
|
@ -34,7 +34,7 @@ func walkRepo(repo *git.Repository) {
|
||||||
log.Info("done", err)
|
log.Info("done", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("walkRepo() ref =", ref.Name(), ref.SymbolicTarget(), ref.Shorthand())
|
log.Info("walkRepo() head", ref, err, "ref.Name =", ref.Name(), ref.SymbolicTarget(), ref.Shorthand())
|
||||||
// fmt.Printf("%+v\n", ref)
|
// fmt.Printf("%+v\n", ref)
|
||||||
// SymbolicTarget()
|
// SymbolicTarget()
|
||||||
}
|
}
|
||||||
|
|
99
showtags.go
99
showtags.go
|
@ -1,99 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"sort"
|
|
||||||
|
|
||||||
git "go.wit.com/lib/libgit2"
|
|
||||||
"go.wit.com/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func showtags(repo *git.Repository) {
|
|
||||||
// Map: commit OID -> list of tags pointing to it
|
|
||||||
tagMap := make(map[string][]string)
|
|
||||||
|
|
||||||
// Walk through all tag names
|
|
||||||
tags, err := repo.NewReferenceIteratorGlob("refs/tags/*")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to iterate tags: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
ref, err := tags.Next()
|
|
||||||
if err != nil {
|
|
||||||
break // Done iterating
|
|
||||||
}
|
|
||||||
|
|
||||||
name := ref.Shorthand()
|
|
||||||
target, err := repo.RevparseSingle(ref.Name())
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Skipping unresolved tag: %s", name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
commitOID := target.Id().String()
|
|
||||||
tagMap[commitOID] = append(tagMap[commitOID], name)
|
|
||||||
log.Info("tag:", commitOID, name, target)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Identify and delete duplicate tags
|
|
||||||
for commit, tagList := range tagMap {
|
|
||||||
if len(tagList) > 1 {
|
|
||||||
sort.Strings(tagList)
|
|
||||||
fmt.Printf("Commit %s has duplicates: %v\n", commit, tagList)
|
|
||||||
|
|
||||||
// Keep the first tag, delete the rest
|
|
||||||
for _, tag := range tagList[1:] {
|
|
||||||
refname := "refs/tags/" + tag
|
|
||||||
log.Info(refname)
|
|
||||||
/*
|
|
||||||
if err := repo.References.Remove(refname); err != nil {
|
|
||||||
log.Printf("Failed to delete tag %s: %v", tag, err)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Deleted tag: %s\n", tag)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func printCommitsForTag(repo *git.Repository, tagName string) error {
|
|
||||||
// Resolve tag reference
|
|
||||||
ref, err := repo.References.Lookup("refs/tags/" + tagName)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to find tag %s: %w", tagName, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve to commit object (may be annotated tag or direct commit)
|
|
||||||
obj, err := ref.Peel(git.ObjectCommit)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to peel tag %s to commit: %w", tagName, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
start, err := obj.AsCommit()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("peeled object is not a commit: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Walk the history
|
|
||||||
walker, err := repo.Walk()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create walker: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := walker.Push(start.Id()); err != nil {
|
|
||||||
return fmt.Errorf("failed to push start commit: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Commits for tag %s:\n", tagName)
|
|
||||||
err = walker.Iterate(func(c *git.Commit) bool {
|
|
||||||
fmt.Printf("%s %s\n", c.Id().String(), c.Summary())
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error during walk: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
Loading…
Reference in New Issue