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

Function finalizeDiff

internal/diff/parser.go:189–222  ·  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

187// finalizeDiff reads the new file content. When ref is non-empty it uses
188// git show to read the file at that ref; otherwise it reads from disk.
189func finalizeDiff(ctx context.Context, d *model.Diff, repoDir string, ref string, runner *gitcmd.Runner) {
190 if d.IsDeleted || d.NewPath == "/dev/null" {
191 d.NewPath = "/dev/null"
192 return
193 }
194 if d.IsBinary {
195 return
196 }
197 if ref != "" {
198 args := []string{"-c", "core.quotepath=false", "show", "--end-of-options", ref + ":" + d.NewPath}
199 var output []byte
200 var err error
201 if runner != nil {
202 output, err = runner.Output(ctx, repoDir, args...)
203 } else {
204 cmd := exec.CommandContext(ctx, "git", args...)
205 cmd.Dir = repoDir
206 output, err = cmd.Output()
207 }
208 if err != nil {
209 fmt.Fprintf(os.Stderr, "[ocr] WARNING: cannot read file %s at ref %s: %v\n",
210 d.NewPath, ref, err)
211 return
212 }
213 d.NewFileContent = string(output)
214 return
215 }
216 content, err := readWorkspaceFileForDiff(repoDir, d.NewPath)
217 if err != nil {
218 fmt.Fprintf(os.Stderr, "[ocr] WARNING: cannot read file %s for review: %v\n", d.NewPath, err)
219 return
220 }
221 d.NewFileContent = string(content)
222}

Callers 1

ParseDiffTextFunction · 0.85

Calls 2

readWorkspaceFileForDiffFunction · 0.85
OutputMethod · 0.80

Tested by

no test coverage detected