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

Function finalizeDiff

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

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

Callers 1

ParseDiffTextFunction · 0.85

Calls 2

readWorkspaceFileForDiffFunction · 0.85
OutputMethod · 0.80

Tested by

no test coverage detected