prefix_filename: return newly allocated string

The prefix_filename() function returns a pointer to static
storage, which makes it easy to use dangerously. We already
fixed one buggy caller in hash-object recently, and the
calls in apply.c are suspicious (I didn't dig in enough to
confirm that there is a bug, but we call the function once
in apply_all_patches() and then again indirectly from
parse_chunk()).

Let's make it harder to get wrong by allocating the return
value. For simplicity, we'll do this even when the prefix is
empty (and we could just return the original file pointer).
That will cause us to allocate sometimes when we wouldn't
otherwise need to, but this function isn't called in
performance critical code-paths (and it already _might_
allocate on any given call, so a caller that cares about
performance is questionable anyway).

The downside is that the callers need to remember to free()
the result to avoid leaking. Most of them already used
xstrdup() on the result, so we know they are OK. The
remainder have been converted to use free() as appropriate.

I considered retaining a prefix_filename_unsafe() for cases
where we know the static lifetime is OK (and handling the
cleanup is awkward). This is only a handful of cases,
though, and it's not worth the mental energy in worrying
about whether the "unsafe" variant is OK to use in any
situation.

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