fetch, upload-pack: --deepen=N extends shallow boundary by N commits

In git-fetch, --depth argument is always relative with the latest
remote refs. This makes it a bit difficult to cover this use case,
where the user wants to make the shallow history, say 3 levels
deeper. It would work if remote refs have not moved yet, but nobody
can guarantee that, especially when that use case is performed a
couple months after the last clone or "git fetch --depth". Also,
modifying shallow boundary using --depth does not work well with
clones created by --since or --not.

This patch fixes that. A new argument --deepen=<N> will add <N> more (*)
parent commits to the current history regardless of where remote refs
are.

Have/Want negotiation is still respected. So if remote refs move, the
server will send two chunks: one between "have" and "want" and another
to extend shallow history. In theory, the client could send no "want"s
in order to get the second chunk only. But the protocol does not allow
that. Either you send no want lines, which means ls-remote; or you
have to send at least one want line that carries deep-relative to the
server..

The main work was done by Dongcan Jiang. I fixed it up here and there.
And of course all the bugs belong to me.

(*) We could even support --deepen=<N> where <N> is negative. In that
case we can cut some history from the shallow clone. This operation
(and --depth=<shorter depth>) does not require interaction with remote
side (and more complicated to implement as a result).

Helped-by: Duy Nguyen <pclouds@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Dongcan Jiang <dongcan.jiang@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 files changed
tree: dd1a8c3e3da2256f28894ea98e31ebc1a4ce8918
  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. refs/
  15. t/
  16. templates/
  17. vcs-svn/
  18. xdiff/
  19. .gitattributes
  20. .gitignore
  21. .mailmap
  22. .travis.yml
  23. abspath.c
  24. aclocal.m4
  25. advice.c
  26. advice.h
  27. alias.c
  28. alloc.c
  29. archive-tar.c
  30. archive-zip.c
  31. archive.c
  32. archive.h
  33. argv-array.c
  34. argv-array.h
  35. attr.c
  36. attr.h
  37. base85.c
  38. bisect.c
  39. bisect.h
  40. blob.c
  41. blob.h
  42. branch.c
  43. branch.h
  44. builtin.h
  45. bulk-checkin.c
  46. bulk-checkin.h
  47. bundle.c
  48. bundle.h
  49. cache-tree.c
  50. cache-tree.h
  51. cache.h
  52. check-builtins.sh
  53. check-racy.c
  54. check_bindir
  55. color.c
  56. color.h
  57. column.c
  58. column.h
  59. combine-diff.c
  60. command-list.txt
  61. commit-slab.h
  62. commit.c
  63. commit.h
  64. config.c
  65. config.mak.in
  66. config.mak.uname
  67. configure.ac
  68. connect.c
  69. connect.h
  70. connected.c
  71. connected.h
  72. convert.c
  73. convert.h
  74. copy.c
  75. COPYING
  76. credential-cache--daemon.c
  77. credential-cache.c
  78. credential-store.c
  79. credential.c
  80. credential.h
  81. csum-file.c
  82. csum-file.h
  83. ctype.c
  84. daemon.c
  85. date.c
  86. decorate.c
  87. decorate.h
  88. delta.h
  89. diff-delta.c
  90. diff-lib.c
  91. diff-no-index.c
  92. diff.c
  93. diff.h
  94. diffcore-break.c
  95. diffcore-delta.c
  96. diffcore-order.c
  97. diffcore-pickaxe.c
  98. diffcore-rename.c
  99. diffcore.h
  100. dir.c
  101. dir.h
  102. editor.c
  103. entry.c
  104. environment.c
  105. exec_cmd.c
  106. exec_cmd.h
  107. fast-import.c
  108. fetch-pack.c
  109. fetch-pack.h
  110. fmt-merge-msg.h
  111. fsck.c
  112. fsck.h
  113. generate-cmdlist.sh
  114. gettext.c
  115. gettext.h
  116. git-add--interactive.perl
  117. git-archimport.perl
  118. git-bisect.sh
  119. git-compat-util.h
  120. git-cvsexportcommit.perl
  121. git-cvsimport.perl
  122. git-cvsserver.perl
  123. git-difftool--helper.sh
  124. git-difftool.perl
  125. git-filter-branch.sh
  126. git-instaweb.sh
  127. git-merge-octopus.sh
  128. git-merge-one-file.sh
  129. git-merge-resolve.sh
  130. git-mergetool--lib.sh
  131. git-mergetool.sh
  132. git-p4.py
  133. git-parse-remote.sh
  134. git-quiltimport.sh
  135. git-rebase--am.sh
  136. git-rebase--interactive.sh
  137. git-rebase--merge.sh
  138. git-rebase.sh
  139. git-relink.perl
  140. git-remote-testgit.sh
  141. git-request-pull.sh
  142. git-send-email.perl
  143. git-sh-i18n.sh
  144. git-sh-setup.sh
  145. git-stash.sh
  146. git-submodule.sh
  147. git-svn.perl
  148. GIT-VERSION-GEN
  149. git-web--browse.sh
  150. git.c
  151. git.rc
  152. git.spec.in
  153. gpg-interface.c
  154. gpg-interface.h
  155. graph.c
  156. graph.h
  157. grep.c
  158. grep.h
  159. hashmap.c
  160. hashmap.h
  161. help.c
  162. help.h
  163. hex.c
  164. http-backend.c
  165. http-fetch.c
  166. http-push.c
  167. http-walker.c
  168. http.c
  169. http.h
  170. ident.c
  171. imap-send.c
  172. INSTALL
  173. khash.h
  174. kwset.c
  175. kwset.h
  176. levenshtein.c
  177. levenshtein.h
  178. LGPL-2.1
  179. line-log.c
  180. line-log.h
  181. line-range.c
  182. line-range.h
  183. list-objects.c
  184. list-objects.h
  185. ll-merge.c
  186. ll-merge.h
  187. lockfile.c
  188. lockfile.h
  189. log-tree.c
  190. log-tree.h
  191. mailinfo.c
  192. mailinfo.h
  193. mailmap.c
  194. mailmap.h
  195. Makefile
  196. match-trees.c
  197. merge-blobs.c
  198. merge-blobs.h
  199. merge-recursive.c
  200. merge-recursive.h
  201. merge.c
  202. mergesort.c
  203. mergesort.h
  204. name-hash.c
  205. notes-cache.c
  206. notes-cache.h
  207. notes-merge.c
  208. notes-merge.h
  209. notes-utils.c
  210. notes-utils.h
  211. notes.c
  212. notes.h
  213. object.c
  214. object.h
  215. pack-bitmap-write.c
  216. pack-bitmap.c
  217. pack-bitmap.h
  218. pack-check.c
  219. pack-objects.c
  220. pack-objects.h
  221. pack-revindex.c
  222. pack-revindex.h
  223. pack-write.c
  224. pack.h
  225. pager.c
  226. parse-options-cb.c
  227. parse-options.c
  228. parse-options.h
  229. patch-delta.c
  230. patch-ids.c
  231. patch-ids.h
  232. path.c
  233. pathspec.c
  234. pathspec.h
  235. pkt-line.c
  236. pkt-line.h
  237. preload-index.c
  238. pretty.c
  239. prio-queue.c
  240. prio-queue.h
  241. progress.c
  242. progress.h
  243. prompt.c
  244. prompt.h
  245. quote.c
  246. quote.h
  247. reachable.c
  248. reachable.h
  249. read-cache.c
  250. README
  251. ref-filter.c
  252. ref-filter.h
  253. reflog-walk.c
  254. reflog-walk.h
  255. refs.c
  256. refs.h
  257. remote-curl.c
  258. remote-testsvn.c
  259. remote.c
  260. remote.h
  261. replace_object.c
  262. rerere.c
  263. rerere.h
  264. resolve-undo.c
  265. resolve-undo.h
  266. revision.c
  267. revision.h
  268. run-command.c
  269. run-command.h
  270. send-pack.c
  271. send-pack.h
  272. sequencer.c
  273. sequencer.h
  274. server-info.c
  275. setup.c
  276. sh-i18n--envsubst.c
  277. sha1-array.c
  278. sha1-array.h
  279. sha1-lookup.c
  280. sha1-lookup.h
  281. sha1_file.c
  282. sha1_name.c
  283. shallow.c
  284. shell.c
  285. shortlog.h
  286. show-index.c
  287. sideband.c
  288. sideband.h
  289. sigchain.c
  290. sigchain.h
  291. split-index.c
  292. split-index.h
  293. strbuf.c
  294. strbuf.h
  295. streaming.c
  296. streaming.h
  297. string-list.c
  298. string-list.h
  299. submodule-config.c
  300. submodule-config.h
  301. submodule.c
  302. submodule.h
  303. symlinks.c
  304. tag.c
  305. tag.h
  306. tar.h
  307. tempfile.c
  308. tempfile.h
  309. test-chmtime.c
  310. test-config.c
  311. test-ctype.c
  312. test-date.c
  313. test-delta.c
  314. test-dump-cache-tree.c
  315. test-dump-split-index.c
  316. test-dump-untracked-cache.c
  317. test-fake-ssh.c
  318. test-genrandom.c
  319. test-hashmap.c
  320. test-index-version.c
  321. test-line-buffer.c
  322. test-match-trees.c
  323. test-mergesort.c
  324. test-mktemp.c
  325. test-parse-options.c
  326. test-path-utils.c
  327. test-prio-queue.c
  328. test-read-cache.c
  329. test-regex.c
  330. test-revision-walking.c
  331. test-run-command.c
  332. test-scrap-cache-tree.c
  333. test-sha1-array.c
  334. test-sha1.c
  335. test-sha1.sh
  336. test-sigchain.c
  337. test-string-list.c
  338. test-submodule-config.c
  339. test-subprocess.c
  340. test-svn-fe.c
  341. test-urlmatch-normalization.c
  342. test-wildmatch.c
  343. thread-utils.c
  344. thread-utils.h
  345. trace.c
  346. trace.h
  347. trailer.c
  348. trailer.h
  349. transport-helper.c
  350. transport.c
  351. transport.h
  352. tree-diff.c
  353. tree-walk.c
  354. tree-walk.h
  355. tree.c
  356. tree.h
  357. unicode_width.h
  358. unimplemented.sh
  359. unix-socket.c
  360. unix-socket.h
  361. unpack-trees.c
  362. unpack-trees.h
  363. update_unicode.sh
  364. upload-pack.c
  365. url.c
  366. url.h
  367. urlmatch.c
  368. urlmatch.h
  369. usage.c
  370. userdiff.c
  371. userdiff.h
  372. utf8.c
  373. utf8.h
  374. varint.c
  375. varint.h
  376. version.c
  377. version.h
  378. versioncmp.c
  379. walker.c
  380. walker.h
  381. wildmatch.c
  382. wildmatch.h
  383. worktree.c
  384. worktree.h
  385. wrap-for-bin.sh
  386. wrapper.c
  387. write_or_die.c
  388. ws.c
  389. wt-status.c
  390. wt-status.h
  391. xdiff-interface.c
  392. xdiff-interface.h
  393. zlib.c