From 752661636262ef92f1d69ccd36fd651599805fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 14 Mar 2012 21:40:55 +0700 Subject: {fetch,receive}-pack: skip sha-1 integrity test on objects from new pack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we fetch or push, usually "git rev-list --verify-objects --not --all --stdin" is used to make sure that all objects between existing refs and new refs are good. This means no gaps in between, all objects are well-formed, object content agrees with its sha-1 signature. For the last one, --verify-objects calls check_sha1_signature() via parse_object(). check_sha1_signature() is an expensive operation, especially when new refs are far away from existing ones because all objects in between are re-hashed. Because objects coming from the new pack are already hashed by index-pack, we can trust their integrity. The only objects left to check are existing ones in repo but has no connection to any current refs. Pass the new pack id down to--verify-objects and skip check_sha1_signature() on objects from that pack. As an (extreme) example, a repository is created with only one commit: e83c516 (Initial revision of "git", the information manager from hell - 2005-04-07). The rest of git.git is fetched on top. Without the patch: $ time git fetch file:///home/pclouds/w/git/.git remote: Counting objects: 125656, done. remote: Compressing objects: 100% (33280/33280), done. remote: Total 125656 (delta 92585), reused 123464 (delta 90682) Receiving objects: 100% (125656/125656), 34.60 MiB | 8.47 MiB/s, done. Resolving deltas: 100% (92585/92585), done. >From file:///home/pclouds/t/test/ * branch HEAD -> FETCH_HEAD real 1m30.437s user 1m31.338s sys 0m1.687s With the patch: $ time git fetch file:///home/pclouds/w/git/.git remote: Counting objects: 125656, done. remote: Compressing objects: 100% (33280/33280), done. remote: Total 125656 (delta 92585), reused 123464 (delta 90682) Receiving objects: 100% (125656/125656), 34.60 MiB | 7.86 MiB/s, done. Resolving deltas: 100% (92585/92585), done. >From file:///home/pclouds/t/test/ * branch HEAD -> FETCH_HEAD real 0m52.182s user 0m53.151s sys 0m1.465s Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/fetch.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'builtin/fetch.c') diff --git a/builtin/fetch.c b/builtin/fetch.c index 8ec4eae3eb..77c26caae2 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -368,7 +368,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20]) } static int store_updated_refs(const char *raw_url, const char *remote_name, - struct ref *ref_map) + struct ref *ref_map, const char *pack_lockfile) { FILE *fp; struct commit *commit; @@ -389,7 +389,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, url = xstrdup("foreign"); rm = ref_map; - if (check_everything_connected(iterate_ref_map, 0, &rm)) { + if (check_everything_connected(iterate_ref_map, 0, pack_lockfile, &rm)) { rc = error(_("%s did not send all necessary objects\n"), url); goto abort; } @@ -516,7 +516,8 @@ static int quickfetch(struct ref *ref_map) */ if (depth) return -1; - return check_everything_connected(iterate_ref_map, 1, &rm); + return check_everything_connected(iterate_ref_map, + CHECK_CONNECT_QUIET, NULL, &rm); } static int fetch_refs(struct transport *transport, struct ref *ref_map) @@ -526,8 +527,9 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map) ret = transport_fetch_refs(transport, ref_map); if (!ret) ret |= store_updated_refs(transport->url, - transport->remote->name, - ref_map); + transport->remote->name, + ref_map, + transport->pack_lockfile); transport_unlock_pack(transport); return ret; } -- cgit v1.2.1