Fix infinite loop when deleting multiple packed refs.

It was stupid to link the same element twice to lock_file_list
and end up in a loop, so we certainly need a fix.

But it is not like we are taking a lock on multiple files in
this case.  It is just that we leave the linked element on the
list even after commit_lock_file() successfully removes the
cruft.

We cannot remove the list element in commit_lock_file(); if we
are interrupted in the middle of list manipulation, the call to
remove_lock_file_on_signal() will happen with a broken list
structure pointed by lock_file_list, which would cause the cruft
to remain, so not removing the list element is the right thing
to do.  Instead we should be reusing the element already on the
list.

There is already a code for that in lock_file() function in
lockfile.c.  The code checks lk->next and the element is linked
only when it is not already on the list -- which is incorrect
for the last element on the list (which has NULL in its next
field), but if you read the check as "is this element already on
the list?" it actually makes sense.  We do not want to link it
on the list again, nor we would want to set up signal/atexit
over and over.

Signed-off-by: Junio C Hamano <junkio@cox.net>
3 files changed
tree: 4605342374bdb48b94ddf67fe0f7a94714ad2d1e
  1. .gitignore
  2. COPYING
  3. Documentation/
  4. GIT-VERSION-GEN
  5. INSTALL
  6. Makefile
  7. README
  8. alloc.c
  9. archive-tar.c
  10. archive-zip.c
  11. archive.h
  12. arm/
  13. base85.c
  14. blob.c
  15. blob.h
  16. builtin-add.c
  17. builtin-annotate.c
  18. builtin-apply.c
  19. builtin-archive.c
  20. builtin-blame.c
  21. builtin-branch.c
  22. builtin-cat-file.c
  23. builtin-check-ref-format.c
  24. builtin-checkout-index.c
  25. builtin-commit-tree.c
  26. builtin-count-objects.c
  27. builtin-diff-files.c
  28. builtin-diff-index.c
  29. builtin-diff-stages.c
  30. builtin-diff-tree.c
  31. builtin-diff.c
  32. builtin-fmt-merge-msg.c
  33. builtin-for-each-ref.c
  34. builtin-grep.c
  35. builtin-init-db.c
  36. builtin-log.c
  37. builtin-ls-files.c
  38. builtin-ls-tree.c
  39. builtin-mailinfo.c
  40. builtin-mailsplit.c
  41. builtin-mv.c
  42. builtin-name-rev.c
  43. builtin-pack-objects.c
  44. builtin-pack-refs.c
  45. builtin-prune-packed.c
  46. builtin-prune.c
  47. builtin-push.c
  48. builtin-read-tree.c
  49. builtin-repo-config.c
  50. builtin-rev-list.c
  51. builtin-rev-parse.c
  52. builtin-rm.c
  53. builtin-runstatus.c
  54. builtin-show-branch.c
  55. builtin-show-ref.c
  56. builtin-stripspace.c
  57. builtin-symbolic-ref.c
  58. builtin-tar-tree.c
  59. builtin-unpack-objects.c
  60. builtin-update-index.c
  61. builtin-update-ref.c
  62. builtin-upload-archive.c
  63. builtin-verify-pack.c
  64. builtin-write-tree.c
  65. builtin.h
  66. cache-tree.c
  67. cache-tree.h
  68. cache.h
  69. check-builtins.sh
  70. check-racy.c
  71. color.c
  72. color.h
  73. combine-diff.c
  74. commit.c
  75. commit.h
  76. compat/
  77. config.c
  78. config.mak.in
  79. configure.ac
  80. connect.c
  81. contrib/
  82. convert-objects.c
  83. copy.c
  84. csum-file.c
  85. csum-file.h
  86. ctype.c
  87. daemon.c
  88. date.c
  89. delta.h
  90. describe.c
  91. diff-delta.c
  92. diff-lib.c
  93. diff.c
  94. diff.h
  95. diffcore-break.c
  96. diffcore-delta.c
  97. diffcore-order.c
  98. diffcore-pickaxe.c
  99. diffcore-rename.c
  100. diffcore.h
  101. dir.c
  102. dir.h
  103. dump-cache-tree.c
  104. entry.c
  105. environment.c
  106. exec_cmd.c
  107. exec_cmd.h
  108. fetch-pack.c
  109. fetch.c
  110. fetch.h
  111. fsck-objects.c
  112. generate-cmdlist.sh
  113. git-am.sh
  114. git-applymbox.sh
  115. git-applypatch.sh
  116. git-archimport.perl
  117. git-bisect.sh
  118. git-checkout.sh
  119. git-clean.sh
  120. git-clone.sh
  121. git-commit.sh
  122. git-compat-util.h
  123. git-cvsexportcommit.perl
  124. git-cvsimport.perl
  125. git-cvsserver.perl
  126. git-fetch.sh
  127. git-instaweb.sh
  128. git-lost-found.sh
  129. git-ls-remote.sh
  130. git-merge-octopus.sh
  131. git-merge-one-file.sh
  132. git-merge-ours.sh
  133. git-merge-recursive-old.py
  134. git-merge-resolve.sh
  135. git-merge-stupid.sh
  136. git-merge.sh
  137. git-p4import.py
  138. git-parse-remote.sh
  139. git-pull.sh
  140. git-quiltimport.sh
  141. git-rebase.sh
  142. git-relink.perl
  143. git-repack.sh
  144. git-request-pull.sh
  145. git-rerere.perl
  146. git-reset.sh
  147. git-resolve.sh
  148. git-revert.sh
  149. git-send-email.perl
  150. git-sh-setup.sh
  151. git-shortlog.perl
  152. git-svn.perl
  153. git-svnimport.perl
  154. git-tag.sh
  155. git-verify-tag.sh
  156. git.c
  157. git.spec.in
  158. gitMergeCommon.py
  159. gitk
  160. gitweb/
  161. grep.c
  162. grep.h
  163. hash-object.c
  164. help.c
  165. http-fetch.c
  166. http-push.c
  167. http.c
  168. http.h
  169. ident.c
  170. imap-send.c
  171. index-pack.c
  172. interpolate.c
  173. interpolate.h
  174. list-objects.c
  175. list-objects.h
  176. local-fetch.c
  177. lockfile.c
  178. log-tree.c
  179. log-tree.h
  180. merge-base.c
  181. merge-file.c
  182. merge-index.c
  183. merge-recursive.c
  184. merge-tree.c
  185. mktag.c
  186. mktree.c
  187. mozilla-sha1/
  188. object-refs.c
  189. object.c
  190. object.h
  191. pack-check.c
  192. pack-redundant.c
  193. pack.h
  194. pager.c
  195. patch-delta.c
  196. patch-id.c
  197. path-list.c
  198. path-list.h
  199. path.c
  200. peek-remote.c
  201. perl/
  202. pkt-line.c
  203. pkt-line.h
  204. ppc/
  205. quote.c
  206. quote.h
  207. read-cache.c
  208. receive-pack.c
  209. refs.c
  210. refs.h
  211. revision.c
  212. revision.h
  213. rsh.c
  214. rsh.h
  215. run-command.c
  216. run-command.h
  217. send-pack.c
  218. server-info.c
  219. setup.c
  220. sha1_file.c
  221. sha1_name.c
  222. shell.c
  223. show-index.c
  224. sideband.c
  225. sideband.h
  226. ssh-fetch.c
  227. ssh-pull.c
  228. ssh-push.c
  229. ssh-upload.c
  230. strbuf.c
  231. strbuf.h
  232. t/
  233. tag.c
  234. tag.h
  235. tar.h
  236. templates/
  237. test-date.c
  238. test-delta.c
  239. test-sha1.c
  240. test-sha1.sh
  241. trace.c
  242. tree-diff.c
  243. tree-walk.c
  244. tree-walk.h
  245. tree.c
  246. tree.h
  247. unpack-file.c
  248. unpack-trees.c
  249. unpack-trees.h
  250. update-server-info.c
  251. upload-pack.c
  252. usage.c
  253. var.c
  254. write_or_die.c
  255. wt-status.c
  256. wt-status.h
  257. xdiff-interface.c
  258. xdiff-interface.h
  259. xdiff/