Skip to content

Commit

Permalink
replace isIndexDiffWithTree with DiffWithTree method (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 24, 2023
1 parent d862592 commit edc88c8
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,6 @@ func commit(rootGoitPath string, index *store.Index, head *store.Head, conf *sto
return nil
}

func isIndexDifferentFromTree(index *store.Index, tree *object.Tree) (bool, error) {
rootName := ""
gotEntries, err := store.GetEntriesFromTree(rootName, tree.Children)
if err != nil {
return false, err
}

if len(gotEntries) != int(index.EntryNum) {
return true, nil
}
for i := 0; i < len(gotEntries); i++ {
if string(gotEntries[i].Path) != string(index.Entries[i].Path) {
return true, nil
}
if !gotEntries[i].Hash.Compare(index.Entries[i].Hash) {
return true, nil
}
}
return false, nil
}

func isCommitNecessary(rootGoitPath string, index *store.Index, commitObj *object.Commit) (bool, error) {
// get tree object
treeObject, err := object.GetObject(rootGoitPath, commitObj.Tree)
Expand All @@ -133,12 +112,12 @@ func isCommitNecessary(rootGoitPath string, index *store.Index, commitObj *objec
}

// compare index with tree
isDiff, err := isIndexDifferentFromTree(index, tree)
diffEntries, err := index.DiffWithTree(tree)
if err != nil {
return false, fmt.Errorf("fail to compare index with tree: %w", err)
}

return isDiff, nil
return len(diffEntries) != 0, nil
}

// commitCmd represents the commit command
Expand Down

0 comments on commit edc88c8

Please sign in to comment.