get_shallow_commits: Avoid memory leak if a commit has been reached already.
[gitweb.git] / fetch-pack.c
index f335bd42b7b61429a307b0d6930987f1058c8034..bb310b644f65116f96d711bd5a145acd2f10fa6a 100644 (file)
@@ -189,7 +189,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
        if (!fetching)
                return 1;
 
-       if (depth >  0) {
+       if (depth > 0) {
                char line[1024];
                unsigned char sha1[20];
                int len;
@@ -198,11 +198,21 @@ static int find_common(int fd[2], unsigned char *result_sha1,
                        if (!strncmp("shallow ", line, 8)) {
                                if (get_sha1_hex(line + 8, sha1))
                                        die("invalid shallow line: %s", line);
-                               /* no need making it shallow if we have it already */
-                               if (lookup_object(sha1))
-                                       continue;
                                register_shallow(sha1);
+                               continue;
+                       }
+                       if (!strncmp("unshallow ", line, 10)) {
+                               if (get_sha1_hex(line + 10, sha1))
+                                       die("invalid unshallow line: %s", line);
+                               if (!lookup_object(sha1))
+                                       die("object not found: %s", line);
+                               /* make sure that it is parsed as shallow */
+                               parse_object(sha1);
+                               if (unregister_shallow(sha1))
+                                       die("no shallow found: %s", line);
+                               continue;
                        }
+                       die("expected shallow/unshallow, got %s", line);
                }
        }
 
@@ -391,9 +401,11 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
                }
        }
 
-       for_each_ref(mark_complete, NULL);
-       if (cutoff)
-               mark_recent_complete_commits(cutoff);
+       if (!depth) {
+               for_each_ref(mark_complete, NULL);
+               if (cutoff)
+                       mark_recent_complete_commits(cutoff);
+       }
 
        /*
         * Mark all complete remote refs as common refs.
@@ -646,8 +658,6 @@ int main(int argc, char **argv)
        }
        if (!dest)
                usage(fetch_pack_usage);
-       if (is_repository_shallow() && depth > 0)
-               die("Deepening of a shallow repository not yet supported!");
        pid = git_connect(fd, dest, exec);
        if (pid < 0)
                return 1;
@@ -690,7 +700,7 @@ int main(int argc, char **argv)
 
                fd = hold_lock_file_for_update(&lock, shallow, 1);
                if (!write_shallow_commits(fd, 0)) {
-                       unlink(lock.filename);
+                       unlink(shallow);
                        rollback_lock_file(&lock);
                } else {
                        close(fd);