Skip to content

Commit

Permalink
Update main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
joesonw authored Nov 30, 2021
1 parent 2a5c38c commit 8a8b062
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package main

import (
"fmt"
"flag"
"fmt"
"go/parser"
"go/token"
"os"
"path/filepath"
"strings"

"github.com/go-git/go-billy/v5/memfs"
git "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/transport"
Expand All @@ -31,8 +31,23 @@ var (
)

func parseFromHash(repo *git.Repository, hash string) (*object.Tree, map[string]string) {
commit, err := repo.CommitObject(plumbing.NewHash(hash))
die(err)
commit, _ := repo.CommitObject(plumbing.NewHash(hash))
if commit == nil {
iter, err := repo.CommitObjects()
die(err)

for {
var err error
commit, err = iter.Next()
die(err)
if strings.HasPrefix(commit.Hash.String(), hash) {
break
}
}
}
if commit == nil {
die(fmt.Errorf("commit %s not found", hash))
}

tree, err := commit.Tree()
die(err)
Expand Down Expand Up @@ -109,11 +124,10 @@ func main() {

for _, file := range patches {
from, to := file.Files()
if from != nil {
if from != nil && to != nil {
rawChanges[from.Path()] = true
} else if from != nil {
rawChanges[from.Path()] = true
}
if to != nil {
rawChanges[to.Path()] = true
}
}

Expand Down

0 comments on commit 8a8b062

Please sign in to comment.