]> git.proxmox.com Git - libgit2.git/commitdiff
Be smarter about selecting wants
authorCarlos Martín Nieto <carlos@cmartin.tk>
Sun, 7 Aug 2011 12:27:47 +0000 (14:27 +0200)
committerVicent Marti <tanoku@gmail.com>
Thu, 18 Aug 2011 00:34:09 +0000 (02:34 +0200)
There is no need to inspect what the local repository is like. Only
check whether the objects exist locally.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
include/git2/net.h
src/fetch.c

index 7c49f804b40e0e099570d8974b56abcc0f389efe..d4f4755277d5be944b05248aa7489e1fe6212c06 100644 (file)
@@ -52,8 +52,7 @@ GIT_BEGIN_DECL
  * Remote head description, given out on `ls` calls.
  */
 struct git_remote_head {
-       int local:1, /* available locally */
-           want:1; /* want to update */
+       int local:1; /* available locally */
        git_oid oid;
        git_oid loid;
        char *name;
index e00b2e31ecd742faed201cf369c70db843bde5b2..ccc8aa03c11d13fff0a40521cf4185326bda1801 100644 (file)
@@ -61,8 +61,6 @@ static int filter_wants(git_remote *remote)
        }
 
        for (i = 0; i < refs.len; ++i) {
-               char local[1024];
-               git_reference *ref;
                git_remote_head *head = refs.heads[i];
 
                /* If it doesn't match the refpec, we don't want it */
@@ -74,34 +72,10 @@ static int filter_wants(git_remote *remote)
                        goto cleanup;
                }
 
-               /* If the local ref is the same, we don't want it either */
-               error = git_refspec_transform(local, sizeof(local), spec, head->name);
-               if (error < GIT_SUCCESS) {
-                       error = git__rethrow(error, "Error transforming ref name");
-                       goto cleanup;
-               }
-
-               error = git_reference_lookup(&ref, repo, local);
-               /* If we don't have it locally, it's new, so we want it */
-               if (error < GIT_SUCCESS && error != GIT_ENOTFOUND) {
-                       error = git__rethrow(error, "Error looking up local ref");
-                       goto cleanup;
-               }
-
-               if (ref != NULL) {
-                       if (!git_oid_cmp(&head->oid, git_reference_oid(ref)))
-                               continue;
-
+               /* If we have the object, mark it so we don't ask for it */
+               if (git_odb_exists(repo->db, &head->oid))
                        head->local = 1;
-                       git_oid_cpy(&head->loid, git_reference_oid(ref));
-               }
 
-               /*
-                * Now we know we want to have that ref, so add it as a "want"
-                * to the list, storing the local oid for that branch so we
-                * don't have to look for it again.
-                */
-               head->want = 1;
                error = git_vector_insert(&list, head);
                if (error < GIT_SUCCESS)
                        goto cleanup;