13
#include "transport.h"
14
#include "version.h"
15
#include "prio-queue.h"
16
+#include "sha1-array.h"
17
18
static int transfer_unpack_limit = -1;
19
static int fetch_unpack_limit = -1;
775
int fd[2],
776
const struct ref *orig_ref,
777
struct ref **sought, int nr_sought,
778
+ struct shallow_info *si,
779
char **pack_lockfile)
780
{
781
struct ref *ref = copy_ref_list(orig_ref);
854
if (args->depth > 0)
855
setup_alternate_shallow(&shallow_lock, &alternate_shallow_file,
856
NULL);
857
+ else if (args->cloning && si->shallow && si->shallow->nr)
858
+ alternate_shallow_file = setup_temporary_shallow(si->shallow);
859
else
860
alternate_shallow_file = NULL;
861
if (get_pack(args, fd, pack_lockfile))
929
return dst;
930
}
931
928
-static void update_shallow(struct fetch_pack_args *args)
932
+static void update_shallow(struct fetch_pack_args *args,
933
+ struct shallow_info *si)
934
{
935
+ int i;
936
+
937
if (args->depth > 0 && alternate_shallow_file) {
938
if (*alternate_shallow_file == '\0') { /* --unshallow */
939
unlink_or_warn(git_path("shallow"));
942
commit_lock_file(&shallow_lock);
943
return;
944
}
945
+
946
+ if (!si->shallow || !si->shallow->nr)
947
+ return;
948
+
949
+ if (alternate_shallow_file) {
950
+ /*
951
+ * The temporary shallow file is only useful for
952
+ * index-pack and unpack-objects because it may
953
+ * contain more roots than we want. Delete it.
954
+ */
955
+ if (*alternate_shallow_file)
956
+ unlink(alternate_shallow_file);
957
+ free((char *)alternate_shallow_file);
958
+ }
959
+
960
+ if (args->cloning) {
961
+ /*
962
+ * remote is shallow, but this is a clone, there are
963
+ * no objects in repo to worry about. Accept any
964
+ * shallow points that exist in the pack (iow in repo
965
+ * after get_pack() and reprepare_packed_git())
966
+ */
967
+ struct sha1_array extra = SHA1_ARRAY_INIT;
968
+ unsigned char (*sha1)[20] = si->shallow->sha1;
969
+ for (i = 0; i < si->shallow->nr; i++)
970
+ if (has_sha1_file(sha1[i]))
971
+ sha1_array_append(&extra, sha1[i]);
972
+ if (extra.nr) {
973
+ setup_alternate_shallow(&shallow_lock,
974
+ &alternate_shallow_file,
975
+ &extra);
976
+ commit_lock_file(&shallow_lock);
977
+ }
978
+ sha1_array_clear(&extra);
979
+ return;
980
+ }
981
}
982
983
struct ref *fetch_pack(struct fetch_pack_args *args,
985
const struct ref *ref,
986
const char *dest,
987
struct ref **sought, int nr_sought,
988
+ struct sha1_array *shallow,
989
char **pack_lockfile)
990
{
991
struct ref *ref_cpy;
992
+ struct shallow_info si;
993
994
fetch_pack_setup();
995
if (nr_sought)
999
packet_flush(fd[1]);
1000
die("no matching remote head");
1001
}
957
- ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, pack_lockfile);
958
- update_shallow(args);
1002
+ prepare_shallow_info(&si, shallow);
1003
+ ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,
1004
+ &si, pack_lockfile);
1005
reprepare_packed_git();
1006
+ update_shallow(args, &si);
1007
+ clear_shallow_info(&si);
1008
return ref_cpy;
1009
}