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

Function finalizeDiff

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

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

Callers 1

ParseDiffTextFunction · 0.85

Calls 2

readWorkspaceFileForDiffFunction · 0.85
OutputMethod · 0.80

Tested by

no test coverage detected