lock_packed_refs(): fix cache validity check

Commit 28ed9830b1 (get_packed_ref_cache(): assume "packed-refs" won't
change while locked, 2017-05-22) assumes that the "packed-refs" file
cannot change while we hold the lock. That assumption is
justified *if* the lock has been held the whole time since the
"packed-refs" file was last read.

But in `lock_packed_refs()`, we ourselves lock the "packed-refs" file
and then call `get_packed_ref_cache()` to ensure that the cache agrees
with the file. The intent is to guard against the possibility that
another process changed the "packed-refs" file the moment before we
locked it.

This check was defeated because `get_packed_ref_cache()` saw that the
file was locked, and therefore didn't do the `stat_validity_check()`
that we want.

The mistake was compounded with a misleading comment in
`lock_packed_refs()` claiming that it was doing the right thing. That
comment came from an earlier draft of the mh/packed-ref-store-prep
patch series when the commits were in a different order.

So instead:

* Extract a function `validate_packed_ref_cache()` that does the
  validity check independent of whether the lock is held.

* Change `get_packed_ref_cache()` to call the new function, but only
  if the lock *isn't* held.

* Change `lock_packed_refs()` to call the new function in any case
  before calling `get_packed_ref_cache()`.

* Fix the comment in `lock_packed_refs()`.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: 65dbc52e5e4da2e5b8fa9858e77ee416b62837e0
  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. sha1dc/
  17. t/
  18. templates/
  19. vcs-svn/
  20. xdiff/
  21. .gitattributes
  22. .gitignore
  23. .mailmap
  24. .travis.yml
  25. abspath.c
  26. aclocal.m4
  27. advice.c
  28. advice.h
  29. alias.c
  30. alloc.c
  31. apply.c
  32. apply.h
  33. archive-tar.c
  34. archive-zip.c
  35. archive.c
  36. archive.h
  37. argv-array.c
  38. argv-array.h
  39. attr.c
  40. attr.h
  41. base85.c
  42. bisect.c
  43. bisect.h
  44. blob.c
  45. blob.h
  46. branch.c
  47. branch.h
  48. builtin.h
  49. bulk-checkin.c
  50. bulk-checkin.h
  51. bundle.c
  52. bundle.h
  53. cache-tree.c
  54. cache-tree.h
  55. cache.h
  56. check-builtins.sh
  57. check-racy.c
  58. check_bindir
  59. color.c
  60. color.h
  61. column.c
  62. column.h
  63. combine-diff.c
  64. command-list.txt
  65. commit-slab.h
  66. commit.c
  67. commit.h
  68. common-main.c
  69. config.c
  70. config.mak.in
  71. config.mak.uname
  72. configure.ac
  73. connect.c
  74. connect.h
  75. connected.c
  76. connected.h
  77. convert.c
  78. convert.h
  79. copy.c
  80. COPYING
  81. credential-cache--daemon.c
  82. credential-cache.c
  83. credential-store.c
  84. credential.c
  85. credential.h
  86. csum-file.c
  87. csum-file.h
  88. ctype.c
  89. daemon.c
  90. date.c
  91. decorate.c
  92. decorate.h
  93. delta.h
  94. diff-delta.c
  95. diff-lib.c
  96. diff-no-index.c
  97. diff.c
  98. diff.h
  99. diffcore-break.c
  100. diffcore-delta.c
  101. diffcore-order.c
  102. diffcore-pickaxe.c
  103. diffcore-rename.c
  104. diffcore.h
  105. dir-iterator.c
  106. dir-iterator.h
  107. dir.c
  108. dir.h
  109. editor.c
  110. entry.c
  111. environment.c
  112. exec_cmd.c
  113. exec_cmd.h
  114. fast-import.c
  115. fetch-pack.c
  116. fetch-pack.h
  117. fmt-merge-msg.h
  118. fsck.c
  119. fsck.h
  120. generate-cmdlist.sh
  121. gettext.c
  122. gettext.h
  123. git-add--interactive.perl
  124. git-archimport.perl
  125. git-bisect.sh
  126. git-compat-util.h
  127. git-cvsexportcommit.perl
  128. git-cvsimport.perl
  129. git-cvsserver.perl
  130. git-difftool--helper.sh
  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-remote-testgit.sh
  146. git-request-pull.sh
  147. git-send-email.perl
  148. git-sh-i18n.sh
  149. git-sh-setup.sh
  150. git-stash.sh
  151. git-submodule.sh
  152. git-svn.perl
  153. GIT-VERSION-GEN
  154. git-web--browse.sh
  155. git.c
  156. git.rc
  157. gpg-interface.c
  158. gpg-interface.h
  159. graph.c
  160. graph.h
  161. grep.c
  162. grep.h
  163. hash.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. oidset.c
  225. oidset.h
  226. pack-bitmap-write.c
  227. pack-bitmap.c
  228. pack-bitmap.h
  229. pack-check.c
  230. pack-objects.c
  231. pack-objects.h
  232. pack-revindex.c
  233. pack-revindex.h
  234. pack-write.c
  235. pack.h
  236. pager.c
  237. parse-options-cb.c
  238. parse-options.c
  239. parse-options.h
  240. patch-delta.c
  241. patch-ids.c
  242. patch-ids.h
  243. path.c
  244. pathspec.c
  245. pathspec.h
  246. pkt-line.c
  247. pkt-line.h
  248. preload-index.c
  249. pretty.c
  250. prio-queue.c
  251. prio-queue.h
  252. progress.c
  253. progress.h
  254. prompt.c
  255. prompt.h
  256. quote.c
  257. quote.h
  258. reachable.c
  259. reachable.h
  260. read-cache.c
  261. README.md
  262. ref-filter.c
  263. ref-filter.h
  264. reflog-walk.c
  265. reflog-walk.h
  266. refs.c
  267. refs.h
  268. remote-curl.c
  269. remote-testsvn.c
  270. remote.c
  271. remote.h
  272. replace_object.c
  273. rerere.c
  274. rerere.h
  275. resolve-undo.c
  276. resolve-undo.h
  277. revision.c
  278. revision.h
  279. run-command.c
  280. run-command.h
  281. send-pack.c
  282. send-pack.h
  283. sequencer.c
  284. sequencer.h
  285. server-info.c
  286. setup.c
  287. sh-i18n--envsubst.c
  288. sha1-array.c
  289. sha1-array.h
  290. sha1-lookup.c
  291. sha1-lookup.h
  292. sha1_file.c
  293. sha1_name.c
  294. shallow.c
  295. shell.c
  296. shortlog.h
  297. show-index.c
  298. sideband.c
  299. sideband.h
  300. sigchain.c
  301. sigchain.h
  302. split-index.c
  303. split-index.h
  304. strbuf.c
  305. strbuf.h
  306. streaming.c
  307. streaming.h
  308. string-list.c
  309. string-list.h
  310. submodule-config.c
  311. submodule-config.h
  312. submodule.c
  313. submodule.h
  314. symlinks.c
  315. tag.c
  316. tag.h
  317. tar.h
  318. tempfile.c
  319. tempfile.h
  320. thread-utils.c
  321. thread-utils.h
  322. tmp-objdir.c
  323. tmp-objdir.h
  324. trace.c
  325. trace.h
  326. trailer.c
  327. trailer.h
  328. transport-helper.c
  329. transport.c
  330. transport.h
  331. tree-diff.c
  332. tree-walk.c
  333. tree-walk.h
  334. tree.c
  335. tree.h
  336. unicode_width.h
  337. unimplemented.sh
  338. unix-socket.c
  339. unix-socket.h
  340. unpack-trees.c
  341. unpack-trees.h
  342. upload-pack.c
  343. url.c
  344. url.h
  345. urlmatch.c
  346. urlmatch.h
  347. usage.c
  348. userdiff.c
  349. userdiff.h
  350. utf8.c
  351. utf8.h
  352. varint.c
  353. varint.h
  354. version.c
  355. version.h
  356. versioncmp.c
  357. walker.c
  358. walker.h
  359. wildmatch.c
  360. wildmatch.h
  361. worktree.c
  362. worktree.h
  363. wrap-for-bin.sh
  364. wrapper.c
  365. write_or_die.c
  366. ws.c
  367. wt-status.c
  368. wt-status.h
  369. xdiff-interface.c
  370. xdiff-interface.h
  371. 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