get_repo_path: refactor path-allocation

The get_repo_path function calls mkpath() and then does some
non-trivial operations on it, like calling
is_git_directory() and read_gitfile(). These are actually
OK (they do not use more pathname static buffers
themselves), but it takes a fair bit of work to verify.

Let's use our own strbuf to store the path, and we can
simply reuse it for each iteration of the loop (we can even
avoid rewriting the beginning part, since we are trying a
series of suffixes).

To make the strbuf cleanup easier, we split out a thin
wrapper. As a bonus, this wrapper can factor out the
canonicalization that happens in all of the early-return
code paths.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: e7bf8ddf1a1f6400f74ef3f3a82fae58434f3cd1
  1. block-sha1/
  2. builtin/
  3. compat/
  4. contrib/
  5. Documentation/
  6. ewah/
  7. git-gui/
  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-slab.h
  60. commit.c
  61. commit.h
  62. config.c
  63. config.mak.in
  64. config.mak.uname
  65. configure.ac
  66. connect.c
  67. connect.h
  68. connected.c
  69. connected.h
  70. convert.c
  71. convert.h
  72. copy.c
  73. COPYING
  74. credential-cache--daemon.c
  75. credential-cache.c
  76. credential-store.c
  77. credential.c
  78. credential.h
  79. csum-file.c
  80. csum-file.h
  81. ctype.c
  82. daemon.c
  83. date.c
  84. decorate.c
  85. decorate.h
  86. delta.h
  87. diff-delta.c
  88. diff-lib.c
  89. diff-no-index.c
  90. diff.c
  91. diff.h
  92. diffcore-break.c
  93. diffcore-delta.c
  94. diffcore-order.c
  95. diffcore-pickaxe.c
  96. diffcore-rename.c
  97. diffcore.h
  98. dir.c
  99. dir.h
  100. editor.c
  101. entry.c
  102. environment.c
  103. exec_cmd.c
  104. exec_cmd.h
  105. fast-import.c
  106. fetch-pack.c
  107. fetch-pack.h
  108. fmt-merge-msg.h
  109. fsck.c
  110. fsck.h
  111. generate-cmdlist.perl
  112. gettext.c
  113. gettext.h
  114. git-add--interactive.perl
  115. git-am.sh
  116. git-archimport.perl
  117. git-bisect.sh
  118. git-compat-util.h
  119. git-cvsexportcommit.perl
  120. git-cvsimport.perl
  121. git-cvsserver.perl
  122. git-difftool--helper.sh
  123. git-difftool.perl
  124. git-filter-branch.sh
  125. git-instaweb.sh
  126. git-merge-octopus.sh
  127. git-merge-one-file.sh
  128. git-merge-resolve.sh
  129. git-mergetool--lib.sh
  130. git-mergetool.sh
  131. git-p4.py
  132. git-parse-remote.sh
  133. git-quiltimport.sh
  134. git-rebase--am.sh
  135. git-rebase--interactive.sh
  136. git-rebase--merge.sh
  137. git-rebase.sh
  138. git-relink.perl
  139. git-remote-testgit.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.rc
  151. git.spec.in
  152. gpg-interface.c
  153. gpg-interface.h
  154. graph.c
  155. graph.h
  156. grep.c
  157. grep.h
  158. hashmap.c
  159. hashmap.h
  160. help.c
  161. help.h
  162. hex.c
  163. http-backend.c
  164. http-fetch.c
  165. http-push.c
  166. http-walker.c
  167. http.c
  168. http.h
  169. ident.c
  170. imap-send.c
  171. INSTALL
  172. khash.h
  173. kwset.c
  174. kwset.h
  175. levenshtein.c
  176. levenshtein.h
  177. LGPL-2.1
  178. line-log.c
  179. line-log.h
  180. line-range.c
  181. line-range.h
  182. list-objects.c
  183. list-objects.h
  184. ll-merge.c
  185. ll-merge.h
  186. lockfile.c
  187. lockfile.h
  188. log-tree.c
  189. log-tree.h
  190. mailmap.c
  191. mailmap.h
  192. Makefile
  193. match-trees.c
  194. merge-blobs.c
  195. merge-blobs.h
  196. merge-recursive.c
  197. merge-recursive.h
  198. merge.c
  199. mergesort.c
  200. mergesort.h
  201. name-hash.c
  202. notes-cache.c
  203. notes-cache.h
  204. notes-merge.c
  205. notes-merge.h
  206. notes-utils.c
  207. notes-utils.h
  208. notes.c
  209. notes.h
  210. object.c
  211. object.h
  212. pack-bitmap-write.c
  213. pack-bitmap.c
  214. pack-bitmap.h
  215. pack-check.c
  216. pack-objects.c
  217. pack-objects.h
  218. pack-revindex.c
  219. pack-revindex.h
  220. pack-write.c
  221. pack.h
  222. pager.c
  223. parse-options-cb.c
  224. parse-options.c
  225. parse-options.h
  226. patch-delta.c
  227. patch-ids.c
  228. patch-ids.h
  229. path.c
  230. pathspec.c
  231. pathspec.h
  232. pkt-line.c
  233. pkt-line.h
  234. preload-index.c
  235. pretty.c
  236. prio-queue.c
  237. prio-queue.h
  238. progress.c
  239. progress.h
  240. prompt.c
  241. prompt.h
  242. quote.c
  243. quote.h
  244. reachable.c
  245. reachable.h
  246. read-cache.c
  247. README
  248. ref-filter.c
  249. ref-filter.h
  250. reflog-walk.c
  251. reflog-walk.h
  252. refs.c
  253. refs.h
  254. remote-curl.c
  255. remote-testsvn.c
  256. remote.c
  257. remote.h
  258. replace_object.c
  259. rerere.c
  260. rerere.h
  261. resolve-undo.c
  262. resolve-undo.h
  263. revision.c
  264. revision.h
  265. run-command.c
  266. run-command.h
  267. send-pack.c
  268. send-pack.h
  269. sequencer.c
  270. sequencer.h
  271. server-info.c
  272. setup.c
  273. sh-i18n--envsubst.c
  274. sha1-array.c
  275. sha1-array.h
  276. sha1-lookup.c
  277. sha1-lookup.h
  278. sha1_file.c
  279. sha1_name.c
  280. shallow.c
  281. shell.c
  282. shortlog.h
  283. show-index.c
  284. sideband.c
  285. sideband.h
  286. sigchain.c
  287. sigchain.h
  288. split-index.c
  289. split-index.h
  290. strbuf.c
  291. strbuf.h
  292. streaming.c
  293. streaming.h
  294. string-list.c
  295. string-list.h
  296. submodule.c
  297. submodule.h
  298. symlinks.c
  299. tag.c
  300. tag.h
  301. tar.h
  302. test-chmtime.c
  303. test-config.c
  304. test-ctype.c
  305. test-date.c
  306. test-delta.c
  307. test-dump-cache-tree.c
  308. test-dump-split-index.c
  309. test-dump-untracked-cache.c
  310. test-genrandom.c
  311. test-hashmap.c
  312. test-index-version.c
  313. test-line-buffer.c
  314. test-match-trees.c
  315. test-mergesort.c
  316. test-mktemp.c
  317. test-parse-options.c
  318. test-path-utils.c
  319. test-prio-queue.c
  320. test-read-cache.c
  321. test-regex.c
  322. test-revision-walking.c
  323. test-run-command.c
  324. test-scrap-cache-tree.c
  325. test-sha1-array.c
  326. test-sha1.c
  327. test-sha1.sh
  328. test-sigchain.c
  329. test-string-list.c
  330. test-subprocess.c
  331. test-svn-fe.c
  332. test-urlmatch-normalization.c
  333. test-wildmatch.c
  334. thread-utils.c
  335. thread-utils.h
  336. trace.c
  337. trace.h
  338. trailer.c
  339. trailer.h
  340. transport-helper.c
  341. transport.c
  342. transport.h
  343. tree-diff.c
  344. tree-walk.c
  345. tree-walk.h
  346. tree.c
  347. tree.h
  348. unicode_width.h
  349. unimplemented.sh
  350. unix-socket.c
  351. unix-socket.h
  352. unpack-trees.c
  353. unpack-trees.h
  354. update_unicode.sh
  355. upload-pack.c
  356. url.c
  357. url.h
  358. urlmatch.c
  359. urlmatch.h
  360. usage.c
  361. userdiff.c
  362. userdiff.h
  363. utf8.c
  364. utf8.h
  365. varint.c
  366. varint.h
  367. version.c
  368. version.h
  369. versioncmp.c
  370. walker.c
  371. walker.h
  372. wildmatch.c
  373. wildmatch.h
  374. wrap-for-bin.sh
  375. wrapper.c
  376. write_or_die.c
  377. ws.c
  378. wt-status.c
  379. wt-status.h
  380. xdiff-interface.c
  381. xdiff-interface.h
  382. zlib.c