<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/123921>123921</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [ClangFormat] Print paths with null (git)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          createyourpersonalaccount
      </td>
    </tr>
</table>

<pre>
    I use `clang-format` in my git pre-commit hook to format my diffs:

```sh
git clang-format --staged \
  | tail -n +2 \
  | xargs git add
```

*This is not a secure git hook due to tricky filenames.*

The issue with `git clang-format --staged` is that it lacks an option to print the affected paths with nulls, hence it is non-composable in the shell, see e.g. <https://dwheeler.com/essays/filenames-in-shell.html>.

The way to fix this is to provide an option like `-z` (xargs has `-0`, find has `-z`, etc) that will make the affected paths be printed with null bytes at their end. Then the above command could be changed to:

```sh
git clang-format --staged -z \
  | xargs -0 git add
```

and there would not be any issues with the parsing of the filenames by xargs.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUlM-OozgQxp_GuZRAYEK6c-DQk9lIe9tDv0BhCuyNsZFddIZ--pVNtrtnNXNYyVIUU3---tUnY4xmckSdaL-J9vsBV9Y-dCoQMm1-DQuF6B1aVMqvjg-9H7buT1gjgThVyqKbitGHGVmcKjAO5g0mw7AEKpSfZ8Ogvb8Be9jDUsBgxjGK5kVU-Zyq_UQtqpeU_LUsFEVknGgA0V5E9QIgni7AaCwUDoT8Jn_68APDFLMCHIavxR-95MurNhFMBOcZECKpNVBOyDqHlZJWDkbdNhiNJYczxVLIh9pXTWBiXAnuhnWC8FvFmUgE1shgGCyqWwR04Bc23qU2SzCOgTUBjiMppgEWZB332m61Ngp5AU1OUSqRZbsEdvERe0uJeEqPmqxNoZEIqJxKEM1FMy8Zs7wKeR3umshSKJWfhbxSjLhFIa8fMxbGFblOqXm2ovmj_Jz4jlteofkB_OCX5fs3M9CXmay5ZWMU72l4IZ_3fWiM-TYvQl5gNG74uHx_XBIrIc87rruxFma80a_g9LSDo-GTE_QbUwTMNE0AckMJr5p2PNj7N4LkR3QDKL_aIVVRGl1yFvv_bcbi_Re2K6rfOy81Zk2B4J7bJ_v1Cd222-mx86R2wRCNm8CP-e_HgqDf9kblYeia4dyc8UBd_dQ8tce6ObcH3ZFSYzW0qlWNUq0aaxyxJ6xHrE7nU1UdTCcr2Va1lHUlm7otnyt8epanI-JRNe25F8eKZjS2tPZtLn2YDlleV8vmLOuDxZ5s_Pe5CF2KKvp1iuJYWRM5fuaxYZsflksieN0fifY7_JVN_x-fJ69MhoU8H9Zgu5-tOxnWa_8wbqr_-CmW4P8mxUJed4ZCXh863zr5TwAAAP__9PaTew">