link_alt_odb_entry: handle normalize_path errors

When we add a new alternate to the list, we try to normalize
out any redundant "..", etc. However, we do not look at the
return value of normalize_path_copy(), and will happily
continue with a path that could not be normalized. Worse,
the normalizing process is done in-place, so we are left
with whatever half-finished working state the normalizing
function was in.

Fortunately, this cannot cause us to read past the end of
our buffer, as that working state will always leave the
NUL from the original path in place. And we do tend to
notice problems when we check is_directory() on the path.
But you can see the nonsense that we feed to is_directory
with an entry like:

  this/../../is/../../way/../../too/../../deep/../../to/../../resolve

in your objects/info/alternates, which yields:

  error: object directory
  /to/e/deep/too/way//ects/this/../../is/../../way/../../too/../../deep/../../to/../../resolve
  does not exist; check .git/objects/info/alternates.

We can easily fix this just by checking the return value.
But that makes it hard to generate a good error message,
since we're normalizing in-place and our input value has
been overwritten by cruft.

Instead, let's provide a strbuf helper that does an in-place
normalize, but restores the original contents on error. This
uses a second buffer under the hood, which is slightly less
efficient, but this is not a performance-critical code path.

The strbuf helper can also properly set the "len" parameter
of the strbuf before returning. Just doing:

  normalize_path_copy(buf.buf, buf.buf);

will shorten the string, but leave buf.len at the original
length. That may be confusing to later code which uses the
strbuf.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 files changed
tree: 033496a3a221c61b1aceaf76133110dd3d908518
  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-difftool.perl
  131. git-filter-branch.sh
  132. git-instaweb.sh
  133. git-merge-octopus.sh
  134. git-merge-one-file.sh
  135. git-merge-resolve.sh
  136. git-mergetool--lib.sh
  137. git-mergetool.sh
  138. git-p4.py
  139. git-parse-remote.sh
  140. git-quiltimport.sh
  141. git-rebase--am.sh
  142. git-rebase--interactive.sh
  143. git-rebase--merge.sh
  144. git-rebase.sh
  145. git-relink.perl
  146. git-remote-testgit.sh
  147. git-request-pull.sh
  148. git-send-email.perl
  149. git-sh-i18n.sh
  150. git-sh-setup.sh
  151. git-stash.sh
  152. git-submodule.sh
  153. git-svn.perl
  154. GIT-VERSION-GEN
  155. git-web--browse.sh
  156. git.c
  157. git.rc
  158. gpg-interface.c
  159. gpg-interface.h
  160. graph.c
  161. graph.h
  162. grep.c
  163. grep.h
  164. hashmap.c
  165. hashmap.h
  166. help.c
  167. help.h
  168. hex.c
  169. http-backend.c
  170. http-fetch.c
  171. http-push.c
  172. http-walker.c
  173. http.c
  174. http.h
  175. ident.c
  176. imap-send.c
  177. INSTALL
  178. iterator.h
  179. khash.h
  180. kwset.c
  181. kwset.h
  182. levenshtein.c
  183. levenshtein.h
  184. LGPL-2.1
  185. line-log.c
  186. line-log.h
  187. line-range.c
  188. line-range.h
  189. list-objects.c
  190. list-objects.h
  191. list.h
  192. ll-merge.c
  193. ll-merge.h
  194. lockfile.c
  195. lockfile.h
  196. log-tree.c
  197. log-tree.h
  198. mailinfo.c
  199. mailinfo.h
  200. mailmap.c
  201. mailmap.h
  202. Makefile
  203. match-trees.c
  204. merge-blobs.c
  205. merge-blobs.h
  206. merge-recursive.c
  207. merge-recursive.h
  208. merge.c
  209. mergesort.c
  210. mergesort.h
  211. mru.c
  212. mru.h
  213. name-hash.c
  214. notes-cache.c
  215. notes-cache.h
  216. notes-merge.c
  217. notes-merge.h
  218. notes-utils.c
  219. notes-utils.h
  220. notes.c
  221. notes.h
  222. object.c
  223. object.h
  224. pack-bitmap-write.c
  225. pack-bitmap.c
  226. pack-bitmap.h
  227. pack-check.c
  228. pack-objects.c
  229. pack-objects.h
  230. pack-revindex.c
  231. pack-revindex.h
  232. pack-write.c
  233. pack.h
  234. pager.c
  235. parse-options-cb.c
  236. parse-options.c
  237. parse-options.h
  238. patch-delta.c
  239. patch-ids.c
  240. patch-ids.h
  241. path.c
  242. pathspec.c
  243. pathspec.h
  244. pkt-line.c
  245. pkt-line.h
  246. preload-index.c
  247. pretty.c
  248. prio-queue.c
  249. prio-queue.h
  250. progress.c
  251. progress.h
  252. prompt.c
  253. prompt.h
  254. quote.c
  255. quote.h
  256. reachable.c
  257. reachable.h
  258. read-cache.c
  259. README.md
  260. ref-filter.c
  261. ref-filter.h
  262. reflog-walk.c
  263. reflog-walk.h
  264. refs.c
  265. refs.h
  266. remote-curl.c
  267. remote-testsvn.c
  268. remote.c
  269. remote.h
  270. replace_object.c
  271. rerere.c
  272. rerere.h
  273. resolve-undo.c
  274. resolve-undo.h
  275. revision.c
  276. revision.h
  277. run-command.c
  278. run-command.h
  279. send-pack.c
  280. send-pack.h
  281. sequencer.c
  282. sequencer.h
  283. server-info.c
  284. setup.c
  285. sh-i18n--envsubst.c
  286. sha1-array.c
  287. sha1-array.h
  288. sha1-lookup.c
  289. sha1-lookup.h
  290. sha1_file.c
  291. sha1_name.c
  292. shallow.c
  293. shell.c
  294. shortlog.h
  295. show-index.c
  296. sideband.c
  297. sideband.h
  298. sigchain.c
  299. sigchain.h
  300. split-index.c
  301. split-index.h
  302. strbuf.c
  303. strbuf.h
  304. streaming.c
  305. streaming.h
  306. string-list.c
  307. string-list.h
  308. submodule-config.c
  309. submodule-config.h
  310. submodule.c
  311. submodule.h
  312. symlinks.c
  313. tag.c
  314. tag.h
  315. tar.h
  316. tempfile.c
  317. tempfile.h
  318. thread-utils.c
  319. thread-utils.h
  320. trace.c
  321. trace.h
  322. trailer.c
  323. trailer.h
  324. transport-helper.c
  325. transport.c
  326. transport.h
  327. tree-diff.c
  328. tree-walk.c
  329. tree-walk.h
  330. tree.c
  331. tree.h
  332. unicode_width.h
  333. unimplemented.sh
  334. unix-socket.c
  335. unix-socket.h
  336. unpack-trees.c
  337. unpack-trees.h
  338. update_unicode.sh
  339. upload-pack.c
  340. url.c
  341. url.h
  342. urlmatch.c
  343. urlmatch.h
  344. usage.c
  345. userdiff.c
  346. userdiff.h
  347. utf8.c
  348. utf8.h
  349. varint.c
  350. varint.h
  351. version.c
  352. version.h
  353. versioncmp.c
  354. walker.c
  355. walker.h
  356. wildmatch.c
  357. wildmatch.h
  358. worktree.c
  359. worktree.h
  360. wrap-for-bin.sh
  361. wrapper.c
  362. write_or_die.c
  363. ws.c
  364. wt-status.c
  365. wt-status.h
  366. xdiff-interface.c
  367. xdiff-interface.h
  368. 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 http://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 http://news.gmane.org/gmane.comp.version-control.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