Skip to content

xargs: read -I input lines like GNU - #921

Merged
sylvestre merged 3 commits into
uutils:mainfrom
jayhemnani9910:xargs-replace-reads-lines
Oct 25, 2026
Merged

sylvestre merged 3 commits into
uutils:mainfrom
jayhemnani9910:xargs-replace-reads-lines

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Builds on #920: the first commit here is that PR, the second is this change.

With -I, the input is split at raw newlines, so the line goes in as it is: leading blanks stay, a blank line still runs the command, quotes and backslashes are kept literally, and -E is dropped. POSIX says unquoted blanks at the start of each line are ignored with -I, and GNU applies the usual quoting rules to the line:

$ printf '  a b  \n\n\t"q r" x\nEND\nlast\n' | xargs -E END -I{} echo '[{}]'
GNU 4.10:  [a b  ]
           [q r x]
main:      [  a b  ]
           [  ]
           [	"q r" x]
           [END]
           [last]

-I now uses the whitespace reader in a mode where blanks inside a line don't split it: each line is one argument, with quotes and backslashes handled as without -I, leading blanks and blank lines skipped, and -E applied. -I with -d or -0 is unchanged.

This is visible for find | xargs -I{}: a name with an unbalanced quote now fails with "Unterminated quote" (exit 1, as without -I and as GNU), and a backslash in a name is taken as an escape. -d '\n' or -0 keep raw names. One older difference shows up here too and is not changed: on a quote error uutils also drops the line read just before it (a\nb\nit's runs a only; GNU runs a and b).

New tests test_whitespace_delimited_reader_whole_lines and xargs_replace_reads_quoted_lines (the second fails on main). cargo test green, clippy clean. 17 -I/-i cases (with -E, -n1, -d,, -0, empty input, backslash-newline, '') give the same output as GNU 4.10, apart from the wording of the -I/-L conflict warning.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 06:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.65%. Comparing base (51f3499) to head (563c2e1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #921      +/-   ##
==========================================
+ Coverage   92.63%   92.65%   +0.01%     
==========================================
  Files          37       37              
  Lines        7818     7837      +19     
  Branches      392      393       +1     
==========================================
+ Hits         7242     7261      +19     
  Misses        435      435              
  Partials      141      141              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown

Commit 560f18d has test result changes:

GNU findutils testsuite:

Test results comparison:
  Current:   TOTAL: 495 / PASSED: 436 / FAILED: 58 / SKIPPED: 1
  Reference: TOTAL: 495 / PASSED: 426 / FAILED: 68 / SKIPPED: 1

Changes from main branch:
  TOTAL: +0
  PASSED: +10
  FAILED: -10

Test improvements (10):
  + E_-IARG
  + IARG
  + L2_2
  + idef
  + idef-s26
  + l1_2
  + space
  + space-I
  + space-r
  + sv-bug-18714

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 317 / PASSED: 277 / FAILED: 34 / SKIPPED: 6
  Reference: TOTAL: 316 / PASSED: 276 / FAILED: 34 / SKIPPED: 6

Changes from main branch:
  TOTAL: +1
  PASSED: +1
  FAILED: +0

@codspeed

codspeed Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 15 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 20 untouched benchmarks


Comparing jayhemnani9910:xargs-replace-reads-lines (563c2e1) with main (51f3499)

Open in CodSpeed

Copilot AI balanced review requested due to automatic review settings October 25, 2026 07:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

Copy link
Copy Markdown

Commit b333720 has test result changes:

GNU findutils testsuite:

Test results comparison:
  Current:   TOTAL: 495 / PASSED: 436 / FAILED: 58 / SKIPPED: 1
  Reference: TOTAL: 495 / PASSED: 426 / FAILED: 68 / SKIPPED: 1

Changes from main branch:
  TOTAL: +0
  PASSED: +10
  FAILED: -10

Test improvements (10):
  + E_-IARG
  + IARG
  + L2_2
  + idef
  + idef-s26
  + l1_2
  + space
  + space-I
  + space-r
  + sv-bug-18714

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 317 / PASSED: 277 / FAILED: 34 / SKIPPED: 6
  Reference: TOTAL: 316 / PASSED: 276 / FAILED: 34 / SKIPPED: 6

Changes from main branch:
  TOTAL: +1
  PASSED: +1
  FAILED: +0

Comment thread tests/test_xargs.rs
.no_stdout();
}

#[test]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test for the unbalanced quote case with -I too ("Unterminated quote", exit 1)
it is the visible change for find | xargs -I{}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added xargs_replace_unterminated_quote in 563c2e1: it's read with -I now fails with "Unterminated quote" and exit 1, and no command runs. It fails on main, where the line is passed through as is. Also rebased on main now that #920 is in.

-I split the input at raw newlines, so leading blanks stayed in the
argument, blank lines ran the command, quotes and backslashes were kept
literally and -E was ignored. Read each line with the usual quoting rules
instead, keeping blanks inside the line.
echo is not a portable way to see the arguments on Windows.
@jayhemnani9910
jayhemnani9910 force-pushed the xargs-replace-reads-lines branch from b333720 to 563c2e1 Compare October 25, 2026 10:20
Copilot AI balanced review requested due to automatic review settings October 25, 2026 10:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

Copy link
Copy Markdown

Commit 563c2e1 has test result changes:

GNU findutils testsuite:

Test results comparison:
  Current:   TOTAL: 495 / PASSED: 436 / FAILED: 58 / SKIPPED: 1
  Reference: TOTAL: 495 / PASSED: 431 / FAILED: 63 / SKIPPED: 1

Changes from main branch:
  TOTAL: +0
  PASSED: +5
  FAILED: -5

Test improvements (5):
  + E_-IARG
  + IARG
  + idef
  + idef-s26
  + space-I

@sylvestre
sylvestre merged commit 505421d into uutils:main Oct 25, 2026
34 checks passed
@jayhemnani9910
jayhemnani9910 deleted the xargs-replace-reads-lines branch November 13, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants