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

Function finalizeDiff

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

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

Callers 1

ParseDiffTextFunction · 0.85

Calls 2

readWorkspaceFileForDiffFunction · 0.85
OutputMethod · 0.80

Tested by

no test coverage detected