odb: handle changing a repository's commondir

The function `repo_set_gitdir()` is called in two situations:

  - To initialize the repository with its discovered location. As part
    of this we also set up the new object database.

  - To update the repository's discovered location in case the process
    changes its working directory so that we update relative paths. This
    means we also have to update any relative paths that are potentially
    used in the object database.

In the context of the object database we ideally wouldn't ever have to
worry about the second case: if all paths used by our object database
sources were absolute, then we wouldn't have to update them. But
unfortunately, the paths aren't only used to locate files owned by the
given source, but we also use them for reporting purposes. One such
example is `repo_get_object_directory()`, where we cannot just change
semantics to always return absolute paths, as that is likely to break
tooling out there.

One solution to this would be to have both a "display path" and an
"internal path". This would allow us to use internal paths for all
internal matters, but continue to use the potentially-relative display
paths so that we don't break compatibility. But converting the codebase
to honor this split is quite a messy endeavour, and it wouldn't even
help us with the goal to get rid of the need to update the display path
on chdir(3p).

Another solution would be to rework "setup.c" so that we never have to
update paths in the first place. In that case, we'd only initialize the
repository once we have figured out final locations for all directories.
This would be a significant simplification of that subsystem indeed, but
the current logic is so messy that it would take significant investments
to get there.

Meanwhile though, while object sources may still use relative paths, the
best thing we can do is to handle the reparenting of the object source
paths in the object database itself. This can be done by registering one
callback for each object database so that we get notified whenever the
current working directory changes, and we then perform the reparenting
ourselves.

Ideally, this wouldn't even happen on the object database level, but
instead handled by each object database source. But we don't yet have
proper pluggable object database sources, so this will need to be
handled at a later point in time.

The logic itself is rather simple:

  - We register the callback when creating the object database.

  - We unregister the callback when releasing it again.

  - We split up `set_git_dir_1()` so that it becomes possible to skip
    recreating the object database. This is required because the
    function is called both when the current working directory changes,
    but also when we set up the repository. Calling this function
    without skipping creation of the ODB will result in a bug in case
    it's already created.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 files changed
tree: ca6562bce8200de04bde4366e7a9d4235322bf43
  1. .github/
  2. bin-wrappers/
  3. block-sha1/
  4. builtin/
  5. ci/
  6. compat/
  7. compiler-tricks/
  8. contrib/
  9. Documentation/
  10. ewah/
  11. git-gui/
  12. gitk-git/
  13. gitweb/
  14. mergetools/
  15. negotiator/
  16. oss-fuzz/
  17. perl/
  18. po/
  19. refs/
  20. reftable/
  21. sha1/
  22. sha1dc/
  23. sha256/
  24. src/
  25. subprojects/
  26. t/
  27. templates/
  28. trace2/
  29. xdiff/
  30. .cirrus.yml
  31. .clang-format
  32. .editorconfig
  33. .gitattributes
  34. .gitignore
  35. .gitlab-ci.yml
  36. .gitmodules
  37. .mailmap
  38. .tsan-suppressions
  39. abspath.c
  40. abspath.h
  41. aclocal.m4
  42. add-interactive.c
  43. add-interactive.h
  44. add-patch.c
  45. advice.c
  46. advice.h
  47. alias.c
  48. alias.h
  49. alloc.c
  50. alloc.h
  51. apply.c
  52. apply.h
  53. archive-tar.c
  54. archive-zip.c
  55. archive.c
  56. archive.h
  57. attr.c
  58. attr.h
  59. banned.h
  60. base85.c
  61. base85.h
  62. bisect.c
  63. bisect.h
  64. blame.c
  65. blame.h
  66. blob.c
  67. blob.h
  68. bloom.c
  69. bloom.h
  70. branch.c
  71. branch.h
  72. builtin.h
  73. bundle-uri.c
  74. bundle-uri.h
  75. bundle.c
  76. bundle.h
  77. cache-tree.c
  78. cache-tree.h
  79. Cargo.toml
  80. cbtree.c
  81. cbtree.h
  82. chdir-notify.c
  83. chdir-notify.h
  84. check-builtins.sh
  85. checkout.c
  86. checkout.h
  87. chunk-format.c
  88. chunk-format.h
  89. CODE_OF_CONDUCT.md
  90. color.c
  91. color.h
  92. column.c
  93. column.h
  94. combine-diff.c
  95. command-list.txt
  96. commit-graph.c
  97. commit-graph.h
  98. commit-reach.c
  99. commit-reach.h
  100. commit-slab-decl.h
  101. commit-slab-impl.h
  102. commit-slab.h
  103. commit.c
  104. commit.h
  105. common-exit.c
  106. common-init.c
  107. common-init.h
  108. common-main.c
  109. config.c
  110. config.h
  111. config.mak.dev
  112. config.mak.in
  113. config.mak.uname
  114. configure.ac
  115. connect.c
  116. connect.h
  117. connected.c
  118. connected.h
  119. convert.c
  120. convert.h
  121. copy.c
  122. copy.h
  123. COPYING
  124. credential.c
  125. credential.h
  126. csum-file.c
  127. csum-file.h
  128. ctype.c
  129. daemon.c
  130. date.c
  131. date.h
  132. decorate.c
  133. decorate.h
  134. delta-islands.c
  135. delta-islands.h
  136. delta.h
  137. detect-compiler
  138. diagnose.c
  139. diagnose.h
  140. diff-delta.c
  141. diff-lib.c
  142. diff-merges.c
  143. diff-merges.h
  144. diff-no-index.c
  145. diff.c
  146. diff.h
  147. diffcore-break.c
  148. diffcore-delta.c
  149. diffcore-order.c
  150. diffcore-pickaxe.c
  151. diffcore-rename.c
  152. diffcore-rotate.c
  153. diffcore.h
  154. dir-iterator.c
  155. dir-iterator.h
  156. dir.c
  157. dir.h
  158. editor.c
  159. editor.h
  160. entry.c
  161. entry.h
  162. environment.c
  163. environment.h
  164. exec-cmd.c
  165. exec-cmd.h
  166. fetch-negotiator.c
  167. fetch-negotiator.h
  168. fetch-pack.c
  169. fetch-pack.h
  170. fmt-merge-msg.c
  171. fmt-merge-msg.h
  172. for-each-ref.h
  173. fsck.c
  174. fsck.h
  175. fsmonitor--daemon.h
  176. fsmonitor-ipc.c
  177. fsmonitor-ipc.h
  178. fsmonitor-ll.h
  179. fsmonitor-path-utils.h
  180. fsmonitor-settings.c
  181. fsmonitor-settings.h
  182. fsmonitor.c
  183. fsmonitor.h
  184. generate-cmdlist.sh
  185. generate-configlist.sh
  186. generate-hooklist.sh
  187. generate-perl.sh
  188. generate-python.sh
  189. generate-script.sh
  190. gettext.c
  191. gettext.h
  192. git-archimport.perl
  193. GIT-BUILD-OPTIONS.in
  194. git-compat-util.h
  195. git-curl-compat.h
  196. git-cvsexportcommit.perl
  197. git-cvsimport.perl
  198. git-cvsserver.perl
  199. git-difftool--helper.sh
  200. git-filter-branch.sh
  201. git-instaweb.sh
  202. git-merge-octopus.sh
  203. git-merge-one-file.sh
  204. git-merge-resolve.sh
  205. git-mergetool--lib.sh
  206. git-mergetool.sh
  207. git-p4.py
  208. git-quiltimport.sh
  209. git-request-pull.sh
  210. git-send-email.perl
  211. git-sh-i18n.sh
  212. git-sh-setup.sh
  213. git-submodule.sh
  214. git-svn.perl
  215. GIT-VERSION-FILE.in
  216. GIT-VERSION-GEN
  217. git-web--browse.sh
  218. git-zlib.c
  219. git-zlib.h
  220. git.c
  221. git.rc.in
  222. gpg-interface.c
  223. gpg-interface.h
  224. graph.c
  225. graph.h
  226. grep.c
  227. grep.h
  228. hash-lookup.c
  229. hash-lookup.h
  230. hash.c
  231. hash.h
  232. hashmap.c
  233. hashmap.h
  234. help.c
  235. help.h
  236. hex-ll.c
  237. hex-ll.h
  238. hex.c
  239. hex.h
  240. hook.c
  241. hook.h
  242. http-backend.c
  243. http-fetch.c
  244. http-push.c
  245. http-walker.c
  246. http.c
  247. http.h
  248. ident.c
  249. ident.h
  250. imap-send.c
  251. INSTALL
  252. iterator.h
  253. json-writer.c
  254. json-writer.h
  255. khash.h
  256. kwset.c
  257. kwset.h
  258. levenshtein.c
  259. levenshtein.h
  260. LGPL-2.1
  261. line-log.c
  262. line-log.h
  263. line-range.c
  264. line-range.h
  265. linear-assignment.c
  266. linear-assignment.h
  267. list-objects-filter-options.c
  268. list-objects-filter-options.h
  269. list-objects-filter.c
  270. list-objects-filter.h
  271. list-objects.c
  272. list-objects.h
  273. list.h
  274. lockfile.c
  275. lockfile.h
  276. log-tree.c
  277. log-tree.h
  278. loose.c
  279. loose.h
  280. ls-refs.c
  281. ls-refs.h
  282. mailinfo.c
  283. mailinfo.h
  284. mailmap.c
  285. mailmap.h
  286. Makefile
  287. match-trees.c
  288. match-trees.h
  289. mem-pool.c
  290. mem-pool.h
  291. merge-blobs.c
  292. merge-blobs.h
  293. merge-ll.c
  294. merge-ll.h
  295. merge-ort-wrappers.c
  296. merge-ort-wrappers.h
  297. merge-ort.c
  298. merge-ort.h
  299. merge.c
  300. merge.h
  301. mergesort.h
  302. meson.build
  303. meson_options.txt
  304. midx-write.c
  305. midx.c
  306. midx.h
  307. name-hash.c
  308. name-hash.h
  309. notes-cache.c
  310. notes-cache.h
  311. notes-merge.c
  312. notes-merge.h
  313. notes-utils.c
  314. notes-utils.h
  315. notes.c
  316. notes.h
  317. object-file-convert.c
  318. object-file-convert.h
  319. object-file.c
  320. object-file.h
  321. object-name.c
  322. object-name.h
  323. object.c
  324. object.h
  325. odb.c
  326. odb.h
  327. oid-array.c
  328. oid-array.h
  329. oidmap.c
  330. oidmap.h
  331. oidset.c
  332. oidset.h
  333. oidtree.c
  334. oidtree.h
  335. pack-bitmap-write.c
  336. pack-bitmap.c
  337. pack-bitmap.h
  338. pack-check.c
  339. pack-mtimes.c
  340. pack-mtimes.h
  341. pack-objects.c
  342. pack-objects.h
  343. pack-refs.c
  344. pack-refs.h
  345. pack-revindex.c
  346. pack-revindex.h
  347. pack-write.c
  348. pack.h
  349. packfile.c
  350. packfile.h
  351. pager.c
  352. pager.h
  353. parallel-checkout.c
  354. parallel-checkout.h
  355. parse-options-cb.c
  356. parse-options.c
  357. parse-options.h
  358. parse.c
  359. parse.h
  360. patch-delta.c
  361. patch-ids.c
  362. patch-ids.h
  363. path-walk.c
  364. path-walk.h
  365. path.c
  366. path.h
  367. pathspec.c
  368. pathspec.h
  369. pkt-line.c
  370. pkt-line.h
  371. preload-index.c
  372. preload-index.h
  373. pretty.c
  374. pretty.h
  375. prio-queue.c
  376. prio-queue.h
  377. progress.c
  378. progress.h
  379. promisor-remote.c
  380. promisor-remote.h
  381. prompt.c
  382. prompt.h
  383. protocol-caps.c
  384. protocol-caps.h
  385. protocol.c
  386. protocol.h
  387. prune-packed.c
  388. prune-packed.h
  389. pseudo-merge.c
  390. pseudo-merge.h
  391. quote.c
  392. quote.h
  393. range-diff.c
  394. range-diff.h
  395. reachable.c
  396. reachable.h
  397. read-cache-ll.h
  398. read-cache.c
  399. read-cache.h
  400. README.md
  401. rebase-interactive.c
  402. rebase-interactive.h
  403. rebase.c
  404. rebase.h
  405. ref-filter.c
  406. ref-filter.h
  407. reflog-walk.c
  408. reflog-walk.h
  409. reflog.c
  410. reflog.h
  411. refs.c
  412. refs.h
  413. refspec.c
  414. refspec.h
  415. remote-curl.c
  416. remote.c
  417. remote.h
  418. repack-cruft.c
  419. repack-filtered.c
  420. repack-geometry.c
  421. repack-midx.c
  422. repack-promisor.c
  423. repack.c
  424. repack.h
  425. replace-object.c
  426. replace-object.h
  427. repo-settings.c
  428. repo-settings.h
  429. repository.c
  430. repository.h
  431. rerere.c
  432. rerere.h
  433. reset.c
  434. reset.h
  435. resolve-undo.c
  436. resolve-undo.h
  437. revision.c
  438. revision.h
  439. run-command.c
  440. run-command.h
  441. sane-ctype.h
  442. scalar.c
  443. SECURITY.md
  444. send-pack.c
  445. send-pack.h
  446. sequencer.c
  447. sequencer.h
  448. serve.c
  449. serve.h
  450. server-info.c
  451. server-info.h
  452. setup.c
  453. setup.h
  454. sh-i18n--envsubst.c
  455. sha1dc_git.c
  456. sha1dc_git.h
  457. shallow.c
  458. shallow.h
  459. shared.mak
  460. shell.c
  461. shortlog.h
  462. sideband.c
  463. sideband.h
  464. sigchain.c
  465. sigchain.h
  466. simple-ipc.h
  467. sparse-index.c
  468. sparse-index.h
  469. split-index.c
  470. split-index.h
  471. stable-qsort.c
  472. statinfo.c
  473. statinfo.h
  474. strbuf.c
  475. strbuf.h
  476. streaming.c
  477. streaming.h
  478. string-list.c
  479. string-list.h
  480. strmap.c
  481. strmap.h
  482. strvec.c
  483. strvec.h
  484. sub-process.c
  485. sub-process.h
  486. submodule-config.c
  487. submodule-config.h
  488. submodule.c
  489. submodule.h
  490. symlinks.c
  491. symlinks.h
  492. tag.c
  493. tag.h
  494. tar.h
  495. tempfile.c
  496. tempfile.h
  497. thread-utils.c
  498. thread-utils.h
  499. tmp-objdir.c
  500. tmp-objdir.h
  501. trace.c
  502. trace.h
  503. trace2.c
  504. trace2.h
  505. trailer.c
  506. trailer.h
  507. transport-helper.c
  508. transport-internal.h
  509. transport.c
  510. transport.h
  511. tree-diff.c
  512. tree-walk.c
  513. tree-walk.h
  514. tree.c
  515. tree.h
  516. unicode-width.h
  517. unimplemented.sh
  518. unix-socket.c
  519. unix-socket.h
  520. unix-stream-server.c
  521. unix-stream-server.h
  522. unpack-trees.c
  523. unpack-trees.h
  524. upload-pack.c
  525. upload-pack.h
  526. url.c
  527. url.h
  528. urlmatch.c
  529. urlmatch.h
  530. usage.c
  531. userdiff.c
  532. userdiff.h
  533. utf8.c
  534. utf8.h
  535. varint.c
  536. varint.h
  537. version-def.h.in
  538. version.c
  539. version.h
  540. versioncmp.c
  541. versioncmp.h
  542. walker.c
  543. walker.h
  544. wildmatch.c
  545. wildmatch.h
  546. worktree.c
  547. worktree.h
  548. wrapper.c
  549. wrapper.h
  550. write-or-die.c
  551. write-or-die.h
  552. ws.c
  553. ws.h
  554. wt-status.c
  555. wt-status.h
  556. xdiff-interface.c
  557. xdiff-interface.h
README.md

Build status

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.adoc to get started, then see Documentation/giteveryday.adoc for a useful minimum set of commands, and Documentation/git-<commandname>.adoc 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.adoc (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 and Documentation/CodingGuidelines).

Those wishing to help with error message, usage and informational message string translations (localization l10) should see po/README.md (a po file is a Portable Object file that holds the translations).

To subscribe to the list, send an email to git+subscribe@vger.kernel.org (see https://subspace.kernel.org/subscribing.html for details). The mailing list archives are available at https://lore.kernel.org/git/, https://marc.info/?l=git and other archival sites.

Issues which are security relevant should be disclosed privately to the Git Security mailing list git-security@googlegroups.com.

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