wt-status: introduce wt_status_state_free_buffers()

When we have a `struct wt_status_state`, we manually free its `branch`,
`onto` and `detached_from`, or sometimes just one or two of them.
Provide a function `wt_status_state_free_buffers()` which does the
freeing.

The callers are still aware of these fields, e.g., they check whether
`branch` was populated or not. But this way, they don't need to know
about *all* of them, and if `struct wt_status_state` gets more fields,
they will not need to learn to free them.

Users of `struct wt_status` (which contains a `wt_status_state`) already
have `wt_status_collect_free_buffers()` (corresponding to
`wt_status_collect()`) which we can also teach to use this new helper.

Finally, note that we're currently leaving dangling pointers behind.
Some callers work on a stack-allocated struct, where this is obviously
ok. But for the users of `run_status()` in builtin/commit.c, there are
ample opportunities for someone to mistakenly use those dangling
pointers. We seem to be ok for now, but it's a use-after-free waiting to
happen. Let's leave NULL-pointers behind instead.

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