MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / execCommitFileDiff

Function execCommitFileDiff

Source/3rdParty/Wa/Source/internal/gitjobs/gitrun.go:946–988  ·  view source on GitHub ↗
(repo *git.Repository, commitHash, path string)

Source from the content-addressed store, hash-verified

944}
945
946func execCommitFileDiff(repo *git.Repository, commitHash, path string) (map[string]any, error) {
947 commit, err := repo.CommitObject(plumbing.NewHash(commitHash))
948 if err != nil {
949 return nil, err
950 }
951 var parent *object.Commit
952 parentIter := commit.Parents()
953 parent, err = parentIter.Next()
954 if errors.Is(err, plumbing.ErrObjectNotFound) {
955 err = io.EOF
956 }
957 if err != nil && err != io.EOF {
958 return nil, err
959 }
960 oldBytes := []byte{}
961 if parent != nil {
962 oldBytes, err = readCommitFile(parent, path)
963 if err != nil && !errors.Is(err, object.ErrFileNotFound) {
964 return nil, err
965 }
966 }
967 newBytes, err := readCommitFile(commit, path)
968 if err != nil && !errors.Is(err, object.ErrFileNotFound) {
969 return nil, err
970 }
971 if isProbablyBinary(oldBytes) || isProbablyBinary(newBytes) {
972 return map[string]any{"path": path, "commit": commitHash, "mode": "binary", "binary": true, "oldSize": len(oldBytes), "newSize": len(newBytes)}, nil
973 }
974 if len(oldBytes)+len(newBytes) > maxPreviewDiffBytes {
975 return map[string]any{"path": path, "commit": commitHash, "mode": "large", "message": "File is too large to preview"}, nil
976 }
977 mode := "diff"
978 if string(oldBytes) == string(newBytes) {
979 mode = "empty"
980 }
981 return map[string]any{
982 "path": path,
983 "commit": commitHash,
984 "mode": mode,
985 "oldText": string(oldBytes),
986 "newText": string(newBytes),
987 }, nil
988}
989
990func execAdd(repoPath string, cmd gitCommand) (map[string]any, error) {
991 _, worktree, err := openWorktree(repoPath)

Callers 1

execDiffFunction · 0.85

Calls 5

readCommitFileFunction · 0.85
isProbablyBinaryFunction · 0.85
stringFunction · 0.85
NextMethod · 0.80
IsMethod · 0.45

Tested by

no test coverage detected