fetch-pack: use a separate flag for fetch in deepening mode

The shallow repo could be deepened or shortened when then user gives --depth. But in future that won't be the only way to deepen/shorten a repo. Stop relying on args->depth in this mode. Future deepening methods can simply set this flag on instead of updating all these if expressions. The new name "deepen" was chosen after the command to define shallow boundary in pack protocol. New commands also follow this tradition. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jun 12, 2016 at 17:53 UTC 79891cb90a4e5b2680308ba2b757a218b9aaa14c
2 files changed +9 -6
fetch-pack.c
+8 -6
@@ -197,7 +197,7 @@ enum ack_type {
197
198 static void consume_shallow_list(struct fetch_pack_args *args, int fd)
199 {
200 - if (args->stateless_rpc && args->depth > 0) {
200 + if (args->stateless_rpc && args->deepen) {
201 /* If we sent a depth we will get back "duplicate"
202 * shallow and unshallow commands every time there
203 * is a block of have lines exchanged.
@@ -348,7 +348,7 @@ static int find_common(struct fetch_pack_args *args,
348 packet_buf_flush(&req_buf);
349 state_len = req_buf.len;
350
351 - if (args->depth > 0) {
351 + if (args->deepen) {
352 char *line;
353 const char *arg;
354 unsigned char sha1[20];
@@ -557,7 +557,7 @@ static void filter_refs(struct fetch_pack_args *args,
557 }
558
559 if (!keep && args->fetch_all &&
560 - (!args->depth || !starts_with(ref->name, "refs/tags/")))
560 + (!args->deepen || !starts_with(ref->name, "refs/tags/")))
561 keep = 1;
562
563 if (keep) {
@@ -627,7 +627,7 @@ static int everything_local(struct fetch_pack_args *args,
627 }
628 }
629
630 - if (!args->depth) {
630 + if (!args->deepen) {
631 for_each_ref(mark_complete_oid, NULL);
632 for_each_alternate_ref(mark_alternate_complete, NULL);
633 commit_list_sort_by_date(&complete);
@@ -812,6 +812,8 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
812
813 if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
814 die(_("Server does not support shallow clients"));
815 + if (args->depth > 0)
816 + args->deepen = 1;
817 if (server_supports("multi_ack_detailed")) {
818 print_verbose(args, _("Server supports multi_ack_detailed"));
819 multi_ack = 2;
@@ -872,7 +874,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
874
875 if (args->stateless_rpc)
876 packet_flush(fd[1]);
875 - if (args->depth > 0)
877 + if (args->deepen)
878 setup_alternate_shallow(&shallow_lock, &alternate_shallow_file,
879 NULL);
880 else if (si->nr_ours || si->nr_theirs)
@@ -939,7 +941,7 @@ static void update_shallow(struct fetch_pack_args *args,
941 int *status;
942 int i;
943
942 - if (args->depth > 0 && alternate_shallow_file) {
944 + if (args->deepen && alternate_shallow_file) {
945 if (*alternate_shallow_file == '\0') { /* --unshallow */
946 unlink_or_warn(git_path_shallow());
947 rollback_lock_file(&shallow_lock);
fetch-pack.h
+1
@@ -25,6 +25,7 @@ struct fetch_pack_args {
25 unsigned self_contained_and_connected:1;
26 unsigned cloning:1;
27 unsigned update_shallow:1;
28 + unsigned deepen:1;
29 };
30
31 /*