MCPcopy Create free account
hub / github.com/cli/cli / changedFilesNames

Function changedFilesNames

pkg/cmd/pr/diff/diff.go:322–356  ·  view source on GitHub ↗
(w io.Writer, r io.Reader)

Source from the content-addressed store, hash-verified

320}
321
322func changedFilesNames(w io.Writer, r io.Reader) error {
323 diff, err := io.ReadAll(r)
324 if err != nil {
325 return err
326 }
327
328 // This is kind of a gnarly regex. We're looking lines of the format:
329 // diff --git a/9114-triage b/9114-triage
330 // diff --git "a/hello-\360\237\230\200-world" "b/hello-\360\237\230\200-world"
331 //
332 // From these lines we would look to extract:
333 // 9114-triage
334 // "hello-\360\237\230\200-world"
335 //
336 // Note that the b/ is removed but in the second case the preceding quote remains.
337 // This is important for how git handles filenames that would be quoted with core.quotePath.
338 // https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath
339 //
340 // Thus we capture the quote if it exists, and everything that follows the b/
341 // We then concatenate those two capture groups together which for the examples above would be:
342 // `` + 9114-triage
343 // `"`` + hello-\360\237\230\200-world"
344 //
345 // Where I'm using the `` to indicate a string to avoid confusion with the " character.
346 matches := diffHeaderRegexp.FindAllStringSubmatch(string(diff), -1)
347
348 for _, val := range matches {
349 name := strings.TrimSpace(val[1] + val[2])
350 if _, err := w.Write([]byte(name + "\n")); err != nil {
351 return err
352 }
353 }
354
355 return nil
356}
357
358func sanitizedReader(r io.Reader) io.Reader {
359 return transform.NewReader(r, &asciisanitizer.Sanitizer{})

Callers 2

diffRunFunction · 0.85
Test_changedFileNamesFunction · 0.85

Calls 1

WriteMethod · 0.65

Tested by 1

Test_changedFileNamesFunction · 0.68