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