tempfile: do not delete tempfile on failed close

When close_tempfile() fails, we delete the tempfile and
reset the fields of the tempfile struct. This makes it
easier for callers to return without cleaning up, but it
also makes this common pattern:

  if (close_tempfile(tempfile))
	return error_errno("error closing %s", tempfile->filename.buf);

wrong, because the "filename" field has been reset after the
failed close. And it's not easy to fix, as in many cases we
don't have another copy of the filename (e.g., if it was
created via one of the mks_tempfile functions, and we just
have the original template string).

Let's drop the feature that a failed close automatically
deletes the file. This puts the burden on the caller to do
the deletion themselves, but this isn't that big a deal.
Callers which do:

  if (write(...) || close_tempfile(...)) {
	delete_tempfile(...);
	return -1;
  }

already had to call delete when the write() failed, and so
aren't affected. Likewise, any caller which just calls die()
in the error path is OK; we'll delete the tempfile during
the atexit handler.

Because this patch changes the semantics of close_tempfile()
without changing its signature, all callers need to be
manually checked and converted to the new scheme. This patch
covers all in-tree callers, but there may be others for
not-yet-merged topics. To catch these, we rename the
function to close_tempfile_gently(), which will attract
compile-time attention to new callers. (Technically the
original could be considered "gentle" already in that it
didn't die() on errors, but this one is even more so).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 files changed
tree: fb867abaa9885a795b7cc34ff870211ac522302f
  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. outgoing/
  14. perl/
  15. po/
  16. ppc/
  17. refs/
  18. sha1dc/
  19. t/
  20. templates/
  21. vcs-svn/
  22. xdiff/
  23. .gitattributes
  24. .gitignore
  25. .gitmodules
  26. .mailmap
  27. .travis.yml
  28. abspath.c
  29. aclocal.m4
  30. advice.c
  31. advice.h
  32. alias.c
  33. alloc.c
  34. apply.c
  35. apply.h
  36. archive-tar.c
  37. archive-zip.c
  38. archive.c
  39. archive.h
  40. argv-array.c
  41. argv-array.h
  42. attr.c
  43. attr.h
  44. base85.c
  45. bisect.c
  46. bisect.h
  47. blame.c
  48. blame.h
  49. blob.c
  50. blob.h
  51. branch.c
  52. branch.h
  53. builtin.h
  54. bulk-checkin.c
  55. bulk-checkin.h
  56. bundle.c
  57. bundle.h
  58. cache-tree.c
  59. cache-tree.h
  60. cache.h
  61. check-builtins.sh
  62. check-racy.c
  63. check_bindir
  64. color.c
  65. color.h
  66. column.c
  67. column.h
  68. combine-diff.c
  69. command-list.txt
  70. commit-slab.h
  71. commit.c
  72. commit.h
  73. common-main.c
  74. config.c
  75. config.h
  76. config.mak.in
  77. config.mak.uname
  78. configure.ac
  79. connect.c
  80. connect.h
  81. connected.c
  82. connected.h
  83. convert.c
  84. convert.h
  85. copy.c
  86. COPYING
  87. credential-cache--daemon.c
  88. credential-cache.c
  89. credential-store.c
  90. credential.c
  91. credential.h
  92. csum-file.c
  93. csum-file.h
  94. ctype.c
  95. daemon.c
  96. date.c
  97. decorate.c
  98. decorate.h
  99. delta.h
  100. diff-delta.c
  101. diff-lib.c
  102. diff-no-index.c
  103. diff.c
  104. diff.h
  105. diffcore-break.c
  106. diffcore-delta.c
  107. diffcore-order.c
  108. diffcore-pickaxe.c
  109. diffcore-rename.c
  110. diffcore.h
  111. dir-iterator.c
  112. dir-iterator.h
  113. dir.c
  114. dir.h
  115. editor.c
  116. entry.c
  117. environment.c
  118. exec_cmd.c
  119. exec_cmd.h
  120. fast-import.c
  121. fetch-pack.c
  122. fetch-pack.h
  123. fmt-merge-msg.h
  124. fsck.c
  125. fsck.h
  126. generate-cmdlist.sh
  127. gettext.c
  128. gettext.h
  129. git-add--interactive.perl
  130. git-archimport.perl
  131. git-bisect.sh
  132. git-compat-util.h
  133. git-cvsexportcommit.perl
  134. git-cvsimport.perl
  135. git-cvsserver.perl
  136. git-difftool--helper.sh
  137. git-filter-branch.sh
  138. git-instaweb.sh
  139. git-merge-octopus.sh
  140. git-merge-one-file.sh
  141. git-merge-resolve.sh
  142. git-mergetool--lib.sh
  143. git-mergetool.sh
  144. git-p4.py
  145. git-parse-remote.sh
  146. git-quiltimport.sh
  147. git-rebase--am.sh
  148. git-rebase--interactive.sh
  149. git-rebase--merge.sh
  150. git-rebase.sh
  151. git-remote-testgit.sh
  152. git-request-pull.sh
  153. git-send-email.perl
  154. git-sh-i18n.sh
  155. git-sh-setup.sh
  156. git-stash.sh
  157. git-submodule.sh
  158. git-svn.perl
  159. GIT-VERSION-GEN
  160. git-web--browse.sh
  161. git.c
  162. git.rc
  163. gpg-interface.c
  164. gpg-interface.h
  165. graph.c
  166. graph.h
  167. grep.c
  168. grep.h
  169. hash.h
  170. hashmap.c
  171. hashmap.h
  172. help.c
  173. help.h
  174. hex.c
  175. http-backend.c
  176. http-fetch.c
  177. http-push.c
  178. http-walker.c
  179. http.c
  180. http.h
  181. ident.c
  182. imap-send.c
  183. INSTALL
  184. iterator.h
  185. khash.h
  186. kwset.c
  187. kwset.h
  188. levenshtein.c
  189. levenshtein.h
  190. LGPL-2.1
  191. line-log.c
  192. line-log.h
  193. line-range.c
  194. line-range.h
  195. list-objects.c
  196. list-objects.h
  197. list.h
  198. ll-merge.c
  199. ll-merge.h
  200. lockfile.c
  201. lockfile.h
  202. log-tree.c
  203. log-tree.h
  204. mailinfo.c
  205. mailinfo.h
  206. mailmap.c
  207. mailmap.h
  208. Makefile
  209. match-trees.c
  210. merge-blobs.c
  211. merge-blobs.h
  212. merge-recursive.c
  213. merge-recursive.h
  214. merge.c
  215. mergesort.c
  216. mergesort.h
  217. mru.c
  218. mru.h
  219. name-hash.c
  220. notes-cache.c
  221. notes-cache.h
  222. notes-merge.c
  223. notes-merge.h
  224. notes-utils.c
  225. notes-utils.h
  226. notes.c
  227. notes.h
  228. object.c
  229. object.h
  230. oidset.c
  231. oidset.h
  232. pack-bitmap-write.c
  233. pack-bitmap.c
  234. pack-bitmap.h
  235. pack-check.c
  236. pack-objects.c
  237. pack-objects.h
  238. pack-revindex.c
  239. pack-revindex.h
  240. pack-write.c
  241. pack.h
  242. packfile.c
  243. packfile.h
  244. pager.c
  245. parse-options-cb.c
  246. parse-options.c
  247. parse-options.h
  248. patch-delta.c
  249. patch-ids.c
  250. patch-ids.h
  251. path.c
  252. path.h
  253. pathspec.c
  254. pathspec.h
  255. pkt-line.c
  256. pkt-line.h
  257. preload-index.c
  258. pretty.c
  259. prio-queue.c
  260. prio-queue.h
  261. progress.c
  262. progress.h
  263. prompt.c
  264. prompt.h
  265. quote.c
  266. quote.h
  267. reachable.c
  268. reachable.h
  269. read-cache.c
  270. README.md
  271. ref-filter.c
  272. ref-filter.h
  273. reflog-walk.c
  274. reflog-walk.h
  275. refs.c
  276. refs.h
  277. remote-curl.c
  278. remote-testsvn.c
  279. remote.c
  280. remote.h
  281. replace_object.c
  282. repository.c
  283. repository.h
  284. rerere.c
  285. rerere.h
  286. resolve-undo.c
  287. resolve-undo.h
  288. revision.c
  289. revision.h
  290. run-command.c
  291. run-command.h
  292. send-pack.c
  293. send-pack.h
  294. sequencer.c
  295. sequencer.h
  296. server-info.c
  297. setup.c
  298. sh-i18n--envsubst.c
  299. sha1-array.c
  300. sha1-array.h
  301. sha1-lookup.c
  302. sha1-lookup.h
  303. sha1_file.c
  304. sha1_name.c
  305. sha1dc_git.c
  306. sha1dc_git.h
  307. shallow.c
  308. shell.c
  309. shortlog.h
  310. show-index.c
  311. sideband.c
  312. sideband.h
  313. sigchain.c
  314. sigchain.h
  315. split-index.c
  316. split-index.h
  317. strbuf.c
  318. strbuf.h
  319. streaming.c
  320. streaming.h
  321. string-list.c
  322. string-list.h
  323. sub-process.c
  324. sub-process.h
  325. submodule-config.c
  326. submodule-config.h
  327. submodule.c
  328. submodule.h
  329. symlinks.c
  330. tag.c
  331. tag.h
  332. tar.h
  333. tempfile.c
  334. tempfile.h
  335. thread-utils.c
  336. thread-utils.h
  337. tmp-objdir.c
  338. tmp-objdir.h
  339. trace.c
  340. trace.h
  341. trailer.c
  342. trailer.h
  343. transport-helper.c
  344. transport.c
  345. transport.h
  346. tree-diff.c
  347. tree-walk.c
  348. tree-walk.h
  349. tree.c
  350. tree.h
  351. unicode_width.h
  352. unimplemented.sh
  353. unix-socket.c
  354. unix-socket.h
  355. unpack-trees.c
  356. unpack-trees.h
  357. upload-pack.c
  358. url.c
  359. url.h
  360. urlmatch.c
  361. urlmatch.h
  362. usage.c
  363. userdiff.c
  364. userdiff.h
  365. utf8.c
  366. utf8.h
  367. varint.c
  368. varint.h
  369. version.c
  370. version.h
  371. versioncmp.c
  372. walker.c
  373. walker.h
  374. wildmatch.c
  375. wildmatch.h
  376. worktree.c
  377. worktree.h
  378. wrap-for-bin.sh
  379. wrapper.c
  380. write_or_die.c
  381. ws.c
  382. wt-status.c
  383. wt-status.h
  384. xdiff-interface.c
  385. xdiff-interface.h
  386. zlib.c
README.md

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-.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://public-inbox.org/git/, http://marc.info/?l=git and other archival sites.

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