MCPcopy Create free account
hub / github.com/alibaba/open-code-review / finalizeDiff

Function finalizeDiff

internal/diff/parser.go:117–147  ·  view source on GitHub ↗

finalizeDiff reads the new file content. When ref is non-empty it uses git show to read the file at that ref; otherwise it reads from disk.

(ctx context.Context, d *model.Diff, repoDir string, ref string, runner *gitcmd.Runner)

Source from the content-addressed store, hash-verified

115// finalizeDiff reads the new file content. When ref is non-empty it uses
116// git show to read the file at that ref; otherwise it reads from disk.
117func finalizeDiff(ctx context.Context, d *model.Diff, repoDir string, ref string, runner *gitcmd.Runner) {
118 if d.IsDeleted || d.NewPath == "/dev/null" {
119 d.NewPath = "/dev/null"
120 return
121 }
122 if ref != "" {
123 args := []string{"-c", "core.quotepath=false", "show", "--end-of-options", ref + ":" + d.NewPath}
124 var output []byte
125 var err error
126 if runner != nil {
127 output, err = runner.Output(ctx, repoDir, args...)
128 } else {
129 cmd := exec.CommandContext(ctx, "git", args...)
130 cmd.Dir = repoDir
131 output, err = cmd.Output()
132 }
133 if err != nil {
134 fmt.Fprintf(os.Stderr, "[ocr] WARNING: cannot read file %s at ref %s: %v\n",
135 d.NewPath, ref, err)
136 return
137 }
138 d.NewFileContent = string(output)
139 return
140 }
141 content, err := readWorkspaceFileForDiff(repoDir, d.NewPath)
142 if err != nil {
143 fmt.Fprintf(os.Stderr, "[ocr] WARNING: cannot read file %s for review: %v\n", d.NewPath, err)
144 return
145 }
146 d.NewFileContent = string(content)
147}

Callers 1

ParseDiffTextFunction · 0.85

Calls 2

readWorkspaceFileForDiffFunction · 0.85
OutputMethod · 0.80

Tested by

no test coverage detected