cocci: make "coccicheck" rule incremental

Optimize the very slow "coccicheck" target to take advantage of
incremental rebuilding, and fix outstanding dependency problems with
the existing rule.

The rule is now faster both on the initial run as we can make better
use of GNU make's parallelism than the old ad-hoc combination of
make's parallelism combined with $(SPATCH_BATCH_SIZE) and/or the
"--jobs" argument to "spatch(1)".

It also makes us *much* faster when incrementally building, it's now
viable to "make coccicheck" as topic branches are merged down.

The rule didn't use FORCE (or its equivalents) before, so a:

	make coccicheck
	make coccicheck

Would report nothing to do on the second iteration. But all of our
patch output depended on all $(COCCI_SOURCES) files, therefore e.g.:

    make -W grep.c coccicheck

Would do a full re-run, i.e. a a change in a single file would force
us to do a full re-run.

The reason for this (not the initial rationale, but my analysis) is:

* Since we create a single "*.cocci.patch+" we don't know where to
  pick up where we left off, or how to incrementally merge e.g. a
  "grep.c" change with an existing *.cocci.patch.

* We've been carrying forward the dependency on the *.c files since
  63f0a758a06 (add coccicheck make target, 2016-09-15) the rule was
  initially added as a sort of poor man's dependency discovery.

  As we don't include other *.c files depending on other *.c files
  has always been broken, as could be trivially demonstrated
  e.g. with:

       make coccicheck
       make -W strbuf.h coccicheck

  However, depending on the corresponding *.c files has been doing
  something, namely that *if* an API change modified both *.c and *.h
  files we'd catch the change to the *.h we care about via the *.c
  being changed.

  For API changes that happened only via *.h files we'd do the wrong
  thing before this change, but e.g. for function additions (not
  "static inline" ones) catch the *.h change by proxy.

Now we'll instead:

 * Create a <RULE>/<FILE> pair in the .build directory, E.g. for
   swap.cocci and grep.c we'll create
   .build/contrib/coccinelle/swap.cocci.patch/grep.c.

   That file is the diff we'll apply for that <RULE>-<FILE>
   combination, if there's no changes to me made (the common case)
   it'll be an empty file.

 * Our generated *.patch
   file (e.g. contrib/coccinelle/swap.cocci.patch) is now a simple "cat
   $^" of all of all of the <RULE>/<FILE> files for a given <RULE>.

   In the case discussed above of "grep.c" being changed we'll do the
   full "cat" every time, so they resulting *.cocci.patch will always
   be correct and up-to-date, even if it's "incrementally updated".

   See 1cc0425a27c (Makefile: have "make pot" not "reset --hard",
   2022-05-26) for another recent rule that used that technique.

As before we'll:

 * End up generating a contrib/coccinelle/swap.cocci.patch, if we
   "fail" by creating a non-empty patch we'll still exit with a zero
   exit code.

   Arguably we should move to a more Makefile-native way of doing
   this, i.e. fail early, and if we want all of the "failed" changes
   we can use "make -k", but as the current
   "ci/run-static-analysis.sh" expects us to behave this way let's
   keep the existing behavior of exhaustively discovering all cocci
   changes, and only failing if spatch itself errors out.

Further implementation details & notes:

 * Before this change running "make coccicheck" would by default end
   up pegging just one CPU at the very end for a while, usually as
   we'd finish whichever *.cocci rule was the most expensive.

   This could be mitigated by combining "make -jN" with
   SPATCH_BATCH_SIZE, see 960154b9c17 (coccicheck: optionally batch
   spatch invocations, 2019-05-06).

   There will be cases where getting rid of "SPATCH_BATCH_SIZE" makes
   things worse, but a from-scratch "make coccicheck" with the default
   of SPATCH_BATCH_SIZE=1 (and tweaking it doesn't make a difference)
   is faster (~3m36s v.s. ~3m56s) with this approach, as we can feed
   the CPU more work in a less staggered way.

 * Getting rid of "SPATCH_BATCH_SIZE" particularly helps in cases
   where the default of 1 yields parallelism under "make coccicheck",
   but then running e.g.:

       make -W contrib/coccinelle/swap.cocci coccicheck

   I.e. before that would use only one CPU core, until the user
   remembered to adjust "SPATCH_BATCH_SIZE" differently than the
   setting that makes sense when doing a non-incremental run of "make
   coccicheck".

 * Before the "make coccicheck" rule would have to clean
   "contrib/coccinelle/*.cocci.patch*", since we'd create "*+" and
   "*.log" files there. Now those are created in
   .build/contrib/coccinelle/, which is covered by the "cocciclean" rule
   already.

Outstanding issues & future work:

 * We could get rid of "--all-includes" in favor of manually
   specifying a list of includes to give to "spatch(1)".

   As noted upthread of [1] a naïve removal of "--all-includes" will
   result in broken *.cocci patches, but if we know the exhaustive
   list of includes via COMPUTE_HEADER_DEPENDENCIES we don't need to
   re-scan for them, we could grab the headers to include from the
   .depend.d/<file>.o.d and supply them with the "--include" option to
   spatch(1).q

1. https://lore.kernel.org/git/87ft18tcog.fsf@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
3 files changed
tree: c501328fd566e7d6eb504bb40ee10be9c765f792
  1. .github/
  2. block-sha1/
  3. builtin/
  4. ci/
  5. compat/
  6. contrib/
  7. Documentation/
  8. ewah/
  9. git-gui/
  10. gitk-git/
  11. gitweb/
  12. mergetools/
  13. negotiator/
  14. perl/
  15. po/
  16. ppc/
  17. refs/
  18. reftable/
  19. sha1dc/
  20. sha256/
  21. t/
  22. templates/
  23. trace2/
  24. xdiff/
  25. .cirrus.yml
  26. .clang-format
  27. .editorconfig
  28. .gitattributes
  29. .gitignore
  30. .gitmodules
  31. .mailmap
  32. .tsan-suppressions
  33. abspath.c
  34. aclocal.m4
  35. add-interactive.c
  36. add-interactive.h
  37. add-patch.c
  38. advice.c
  39. advice.h
  40. alias.c
  41. alias.h
  42. alloc.c
  43. alloc.h
  44. apply.c
  45. apply.h
  46. archive-tar.c
  47. archive-zip.c
  48. archive.c
  49. archive.h
  50. attr.c
  51. attr.h
  52. banned.h
  53. base85.c
  54. bisect.c
  55. bisect.h
  56. blame.c
  57. blame.h
  58. blob.c
  59. blob.h
  60. bloom.c
  61. bloom.h
  62. branch.c
  63. branch.h
  64. builtin.h
  65. bulk-checkin.c
  66. bulk-checkin.h
  67. bundle.c
  68. bundle.h
  69. cache-tree.c
  70. cache-tree.h
  71. cache.h
  72. cbtree.c
  73. cbtree.h
  74. chdir-notify.c
  75. chdir-notify.h
  76. check-builtins.sh
  77. checkout.c
  78. checkout.h
  79. chunk-format.c
  80. chunk-format.h
  81. CODE_OF_CONDUCT.md
  82. color.c
  83. color.h
  84. column.c
  85. column.h
  86. combine-diff.c
  87. command-list.txt
  88. commit-graph.c
  89. commit-graph.h
  90. commit-reach.c
  91. commit-reach.h
  92. commit-slab-decl.h
  93. commit-slab-impl.h
  94. commit-slab.h
  95. commit.c
  96. commit.h
  97. common-main.c
  98. config.c
  99. config.h
  100. config.mak.dev
  101. config.mak.in
  102. config.mak.uname
  103. configure.ac
  104. connect.c
  105. connect.h
  106. connected.c
  107. connected.h
  108. convert.c
  109. convert.h
  110. copy.c
  111. COPYING
  112. credential.c
  113. credential.h
  114. csum-file.c
  115. csum-file.h
  116. ctype.c
  117. daemon.c
  118. date.c
  119. date.h
  120. decorate.c
  121. decorate.h
  122. delta-islands.c
  123. delta-islands.h
  124. delta.h
  125. detect-compiler
  126. diagnose.c
  127. diagnose.h
  128. diff-delta.c
  129. diff-lib.c
  130. diff-merges.c
  131. diff-merges.h
  132. diff-no-index.c
  133. diff.c
  134. diff.h
  135. diffcore-break.c
  136. diffcore-delta.c
  137. diffcore-order.c
  138. diffcore-pickaxe.c
  139. diffcore-rename.c
  140. diffcore-rotate.c
  141. diffcore.h
  142. dir-iterator.c
  143. dir-iterator.h
  144. dir.c
  145. dir.h
  146. editor.c
  147. entry.c
  148. entry.h
  149. environment.c
  150. environment.h
  151. exec-cmd.c
  152. exec-cmd.h
  153. fetch-negotiator.c
  154. fetch-negotiator.h
  155. fetch-pack.c
  156. fetch-pack.h
  157. fmt-merge-msg.c
  158. fmt-merge-msg.h
  159. fsck.c
  160. fsck.h
  161. fsmonitor--daemon.h
  162. fsmonitor-ipc.c
  163. fsmonitor-ipc.h
  164. fsmonitor-settings.c
  165. fsmonitor-settings.h
  166. fsmonitor.c
  167. fsmonitor.h
  168. fuzz-commit-graph.c
  169. fuzz-pack-headers.c
  170. fuzz-pack-idx.c
  171. generate-cmdlist.sh
  172. generate-configlist.sh
  173. generate-hooklist.sh
  174. gettext.c
  175. gettext.h
  176. git-add--interactive.perl
  177. git-archimport.perl
  178. git-bisect.sh
  179. git-compat-util.h
  180. git-curl-compat.h
  181. git-cvsexportcommit.perl
  182. git-cvsimport.perl
  183. git-cvsserver.perl
  184. git-difftool--helper.sh
  185. git-filter-branch.sh
  186. git-instaweb.sh
  187. git-merge-octopus.sh
  188. git-merge-one-file.sh
  189. git-merge-resolve.sh
  190. git-mergetool--lib.sh
  191. git-mergetool.sh
  192. git-p4.py
  193. git-quiltimport.sh
  194. git-request-pull.sh
  195. git-send-email.perl
  196. git-sh-i18n.sh
  197. git-sh-setup.sh
  198. git-submodule.sh
  199. git-svn.perl
  200. GIT-VERSION-GEN
  201. git-web--browse.sh
  202. git.c
  203. git.rc
  204. gpg-interface.c
  205. gpg-interface.h
  206. graph.c
  207. graph.h
  208. grep.c
  209. grep.h
  210. hash-lookup.c
  211. hash-lookup.h
  212. hash.h
  213. hashmap.c
  214. hashmap.h
  215. help.c
  216. help.h
  217. hex.c
  218. hook.c
  219. hook.h
  220. http-backend.c
  221. http-fetch.c
  222. http-push.c
  223. http-walker.c
  224. http.c
  225. http.h
  226. ident.c
  227. imap-send.c
  228. INSTALL
  229. iterator.h
  230. json-writer.c
  231. json-writer.h
  232. khash.h
  233. kwset.c
  234. kwset.h
  235. levenshtein.c
  236. levenshtein.h
  237. LGPL-2.1
  238. line-log.c
  239. line-log.h
  240. line-range.c
  241. line-range.h
  242. linear-assignment.c
  243. linear-assignment.h
  244. list-objects-filter-options.c
  245. list-objects-filter-options.h
  246. list-objects-filter.c
  247. list-objects-filter.h
  248. list-objects.c
  249. list-objects.h
  250. list.h
  251. ll-merge.c
  252. ll-merge.h
  253. lockfile.c
  254. lockfile.h
  255. log-tree.c
  256. log-tree.h
  257. ls-refs.c
  258. ls-refs.h
  259. mailinfo.c
  260. mailinfo.h
  261. mailmap.c
  262. mailmap.h
  263. Makefile
  264. match-trees.c
  265. mem-pool.c
  266. mem-pool.h
  267. merge-blobs.c
  268. merge-blobs.h
  269. merge-ort-wrappers.c
  270. merge-ort-wrappers.h
  271. merge-ort.c
  272. merge-ort.h
  273. merge-recursive.c
  274. merge-recursive.h
  275. merge.c
  276. mergesort.h
  277. midx.c
  278. midx.h
  279. name-hash.c
  280. notes-cache.c
  281. notes-cache.h
  282. notes-merge.c
  283. notes-merge.h
  284. notes-utils.c
  285. notes-utils.h
  286. notes.c
  287. notes.h
  288. object-file.c
  289. object-name.c
  290. object-store.h
  291. object.c
  292. object.h
  293. oid-array.c
  294. oid-array.h
  295. oidmap.c
  296. oidmap.h
  297. oidset.c
  298. oidset.h
  299. oidtree.c
  300. oidtree.h
  301. pack-bitmap-write.c
  302. pack-bitmap.c
  303. pack-bitmap.h
  304. pack-check.c
  305. pack-mtimes.c
  306. pack-mtimes.h
  307. pack-objects.c
  308. pack-objects.h
  309. pack-revindex.c
  310. pack-revindex.h
  311. pack-write.c
  312. pack.h
  313. packfile.c
  314. packfile.h
  315. pager.c
  316. parallel-checkout.c
  317. parallel-checkout.h
  318. parse-options-cb.c
  319. parse-options.c
  320. parse-options.h
  321. patch-delta.c
  322. patch-ids.c
  323. patch-ids.h
  324. path.c
  325. path.h
  326. pathspec.c
  327. pathspec.h
  328. pkt-line.c
  329. pkt-line.h
  330. preload-index.c
  331. pretty.c
  332. pretty.h
  333. prio-queue.c
  334. prio-queue.h
  335. progress.c
  336. progress.h
  337. promisor-remote.c
  338. promisor-remote.h
  339. prompt.c
  340. prompt.h
  341. protocol-caps.c
  342. protocol-caps.h
  343. protocol.c
  344. protocol.h
  345. prune-packed.c
  346. prune-packed.h
  347. quote.c
  348. quote.h
  349. range-diff.c
  350. range-diff.h
  351. reachable.c
  352. reachable.h
  353. read-cache.c
  354. README.md
  355. rebase-interactive.c
  356. rebase-interactive.h
  357. rebase.c
  358. rebase.h
  359. ref-filter.c
  360. ref-filter.h
  361. reflog-walk.c
  362. reflog-walk.h
  363. reflog.c
  364. reflog.h
  365. refs.c
  366. refs.h
  367. refspec.c
  368. refspec.h
  369. remote-curl.c
  370. remote.c
  371. remote.h
  372. replace-object.c
  373. replace-object.h
  374. repo-settings.c
  375. repository.c
  376. repository.h
  377. rerere.c
  378. rerere.h
  379. reset.c
  380. reset.h
  381. resolve-undo.c
  382. resolve-undo.h
  383. revision.c
  384. revision.h
  385. run-command.c
  386. run-command.h
  387. SECURITY.md
  388. send-pack.c
  389. send-pack.h
  390. sequencer.c
  391. sequencer.h
  392. serve.c
  393. serve.h
  394. server-info.c
  395. setup.c
  396. sh-i18n--envsubst.c
  397. sha1dc_git.c
  398. sha1dc_git.h
  399. shallow.c
  400. shallow.h
  401. shared.mak
  402. shell.c
  403. shortlog.h
  404. sideband.c
  405. sideband.h
  406. sigchain.c
  407. sigchain.h
  408. simple-ipc.h
  409. sparse-index.c
  410. sparse-index.h
  411. split-index.c
  412. split-index.h
  413. stable-qsort.c
  414. strbuf.c
  415. strbuf.h
  416. streaming.c
  417. streaming.h
  418. string-list.c
  419. string-list.h
  420. strmap.c
  421. strmap.h
  422. strvec.c
  423. strvec.h
  424. sub-process.c
  425. sub-process.h
  426. submodule-config.c
  427. submodule-config.h
  428. submodule.c
  429. submodule.h
  430. symlinks.c
  431. tag.c
  432. tag.h
  433. tar.h
  434. tempfile.c
  435. tempfile.h
  436. thread-utils.c
  437. thread-utils.h
  438. tmp-objdir.c
  439. tmp-objdir.h
  440. trace.c
  441. trace.h
  442. trace2.c
  443. trace2.h
  444. trailer.c
  445. trailer.h
  446. transport-helper.c
  447. transport-internal.h
  448. transport.c
  449. transport.h
  450. tree-diff.c
  451. tree-walk.c
  452. tree-walk.h
  453. tree.c
  454. tree.h
  455. unicode-width.h
  456. unimplemented.sh
  457. unix-socket.c
  458. unix-socket.h
  459. unix-stream-server.c
  460. unix-stream-server.h
  461. unpack-trees.c
  462. unpack-trees.h
  463. upload-pack.c
  464. upload-pack.h
  465. url.c
  466. url.h
  467. urlmatch.c
  468. urlmatch.h
  469. usage.c
  470. userdiff.c
  471. userdiff.h
  472. utf8.c
  473. utf8.h
  474. varint.c
  475. varint.h
  476. version.c
  477. version.h
  478. versioncmp.c
  479. walker.c
  480. walker.h
  481. wildmatch.c
  482. wildmatch.h
  483. worktree.c
  484. worktree.h
  485. wrap-for-bin.sh
  486. wrapper.c
  487. write-or-die.c
  488. ws.c
  489. wt-status.c
  490. wt-status.h
  491. xdiff-interface.c
  492. xdiff-interface.h
  493. zlib.c
README.md

Build status

Git - fast, scalable, distributed revision control system

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Git is an Open Source project covered by the GNU General Public License version 2 (some parts of it are under different licenses, compatible with the GPLv2). It was originally written by Linus Torvalds with help of a group of hackers around the net.

Please read the file INSTALL for installation instructions.

Many Git online resources are accessible from https://git-scm.com/ including full documentation and Git related tools.

See Documentation/gittutorial.txt to get started, then see Documentation/giteveryday.txt for a useful minimum set of commands, and Documentation/git-<commandname>.txt for documentation of each command. If git has been correctly installed, then the tutorial can also be read with man gittutorial or git help tutorial, and the documentation of each command with man git-<commandname> or git help <commandname>.

CVS users may also want to read Documentation/gitcvs-migration.txt (man gitcvs-migration or git help cvs-migration if git is installed).

The user discussion and development of Git take place on the Git mailing list -- everyone is welcome to post bug reports, feature requests, comments and patches to git@vger.kernel.org (read Documentation/SubmittingPatches for instructions on patch submission and Documentation/CodingGuidelines).

Those wishing to help with error message, usage and informational message string translations (localization l10) should see po/README.md (a po file is a Portable Object file that holds the translations).

To subscribe to the list, send an email with just “subscribe git” in the body to majordomo@vger.kernel.org (not the Git list). The mailing list archives are available at https://lore.kernel.org/git/, http://marc.info/?l=git and other archival sites.

Issues which are security relevant should be disclosed privately to the Git Security mailing list git-security@googlegroups.com.

The maintainer frequently sends the “What's cooking” reports that list the current status of various development topics to the mailing list. The discussion following them give a good reference for project status, development direction and remaining tasks.

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • “global information tracker”: you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • “goddamn idiotic truckload of sh*t”: when it breaks