name-hash: allow hashing an empty string

Usually we do not pass an empty string to the function hash_name()
because we almost always ask for hash values for a path that is a
candidate to be added to the index. However, check-ignore (and most
likely check-attr, but I didn't check) apparently has a callchain
to ask the hash value for an empty path when it was given a "." from
the top-level directory to ask "Is the path . excluded by default?"

Make sure that hash_name() does not overrun the end of the given
pathname even when it is empty.

Remove a sweep-the-issue-under-the-rug conditional in check-ignore
that avoided to pass an empty string to the callchain while at it.
It is a valid question to ask for check-ignore if the top-level is
set to be ignored by default, even though the answer is most likely
no, if only because there is currently no way to specify such an
entry in the .gitignore file. But it is an unusual thing to ask and
it is not worth optimizing for it by special casing at the top level
of the call chain.

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