Commit Diff


commit - f291ef1fa2e240ab658eb94255b8afcb38c54433
commit + 7afbdbadacd5be6f71eddd9046d5f1bb70bbc5e6
blob - 865db63e42ddaa256c4d7d1d1a9de4fa02ee2f59
blob + c20bcfac4a42bf5558bbc4c938c767c008f4c077
--- lib/pack_create.c
+++ lib/pack_create.c
@@ -938,7 +938,8 @@ add_object(int want_meta, struct got_object_idset *ids
 
 static const struct got_error *
 load_tree_entries(struct got_object_id_queue *ids, int want_meta,
-    struct got_object_idset *idset, struct got_object_id *tree_id,
+    struct got_object_idset *idset, struct got_object_idset *idset_exclude,
+    struct got_object_id *tree_id,
     const char *dpath, time_t mtime, struct got_repository *repo,
     int loose_obj_only, int *ncolored, int *nfound, int *ntrees,
     got_pack_progress_cb progress_cb, void *progress_arg,
@@ -971,7 +972,8 @@ load_tree_entries(struct got_object_id_queue *ids, int
 		}
 
 		if (got_object_tree_entry_is_submodule(e) ||
-		    got_object_idset_contains(idset, id))
+		    got_object_idset_contains(idset, id) ||
+		    got_object_idset_contains(idset_exclude, id))
 			continue;
 		
 		if (asprintf(&p, "%s%s%s", dpath, dpath[0] != '\0' ? "/" : "",
@@ -987,7 +989,8 @@ load_tree_entries(struct got_object_id_queue *ids, int
 				break;
 			STAILQ_INSERT_TAIL(ids, qid, entry);
 		} else if (S_ISREG(mode) || S_ISLNK(mode)) {
-			err = add_object(want_meta, idset, id, p,
+			err = add_object(want_meta,
+			    want_meta ? idset : idset_exclude, id, p,
 			    GOT_OBJ_TYPE_BLOB, mtime, loose_obj_only, repo,
 			    ncolored, nfound, ntrees,
 			    progress_cb, progress_arg, rl);
@@ -1005,6 +1008,7 @@ load_tree_entries(struct got_object_id_queue *ids, int
 
 static const struct got_error *
 load_tree(int want_meta, struct got_object_idset *idset,
+    struct got_object_idset *idset_exclude,
     struct got_object_id *tree_id, const char *dpath, time_t mtime,
     struct got_repository *repo, int loose_obj_only,
     int *ncolored, int *nfound, int *ntrees,
@@ -1015,7 +1019,8 @@ load_tree(int want_meta, struct got_object_idset *idse
 	struct got_object_id_queue tree_ids;
 	struct got_object_qid *qid;
 
-	if (got_object_idset_contains(idset, tree_id))
+	if (got_object_idset_contains(idset, tree_id) ||
+	    got_object_idset_contains(idset_exclude, tree_id))
 		return NULL;
 
 	err = got_object_qid_alloc(&qid, tree_id);
@@ -1035,20 +1040,23 @@ load_tree(int want_meta, struct got_object_idset *idse
 		qid = STAILQ_FIRST(&tree_ids);
 		STAILQ_REMOVE_HEAD(&tree_ids, entry);
 
-		if (got_object_idset_contains(idset, &qid->id)) {
+		if (got_object_idset_contains(idset, &qid->id) ||
+		    got_object_idset_contains(idset_exclude, &qid->id)) {
 			got_object_qid_free(qid);
 			continue;
 		}
 
-		err = add_object(want_meta, idset, &qid->id, dpath,
-		    GOT_OBJ_TYPE_TREE, mtime, loose_obj_only, repo,
+		err = add_object(want_meta, want_meta ? idset : idset_exclude,
+		    &qid->id, dpath, GOT_OBJ_TYPE_TREE,
+		    mtime, loose_obj_only, repo,
 		    ncolored, nfound, ntrees, progress_cb, progress_arg, rl);
 		if (err) {
 			got_object_qid_free(qid);
 			break;
 		}
 
-		err = load_tree_entries(&tree_ids, want_meta, idset, &qid->id,
+		err = load_tree_entries(&tree_ids, want_meta, idset,
+		    idset_exclude, &qid->id,
 		    dpath, mtime, repo, loose_obj_only, ncolored, nfound,
 		    ntrees, progress_cb, progress_arg, rl,
 		    cancel_cb, cancel_arg);
@@ -1063,6 +1071,7 @@ load_tree(int want_meta, struct got_object_idset *idse
 
 static const struct got_error *
 load_commit(int want_meta, struct got_object_idset *idset,
+    struct got_object_idset *idset_exclude,
     struct got_object_id *id, struct got_repository *repo, int loose_obj_only,
     int *ncolored, int *nfound, int *ntrees,
     got_pack_progress_cb progress_cb, void *progress_arg,
@@ -1071,7 +1080,8 @@ load_commit(int want_meta, struct got_object_idset *id
 	const struct got_error *err;
 	struct got_commit_object *commit;
 
-	if (got_object_idset_contains(idset, id))
+	if (got_object_idset_contains(idset, id) ||
+	    got_object_idset_contains(idset_exclude, id))
 		return NULL;
 
 	if (loose_obj_only) {
@@ -1087,14 +1097,16 @@ load_commit(int want_meta, struct got_object_idset *id
 	if (err)
 		return err;
 
-	err = add_object(want_meta, idset, id, "", GOT_OBJ_TYPE_COMMIT,
+	err = add_object(want_meta, want_meta ? idset : idset_exclude,
+	    id, "", GOT_OBJ_TYPE_COMMIT,
 	    got_object_commit_get_committer_time(commit),
 	    loose_obj_only, repo,
 	    ncolored, nfound, ntrees, progress_cb, progress_arg, rl);
 	if (err)
 		goto done;
 
-	err = load_tree(want_meta, idset, got_object_commit_get_tree_id(commit),
+	err = load_tree(want_meta, idset, idset_exclude,
+	    got_object_commit_get_tree_id(commit),
 	    "", got_object_commit_get_committer_time(commit),
 	    repo, loose_obj_only, ncolored, nfound, ntrees,
 	    progress_cb, progress_arg, rl, cancel_cb, cancel_arg);
@@ -1105,6 +1117,7 @@ done:
 
 static const struct got_error *
 load_tag(int want_meta, struct got_object_idset *idset,
+    struct got_object_idset *idset_exclude,
     struct got_object_id *id, struct got_repository *repo, int loose_obj_only,
     int *ncolored, int *nfound, int *ntrees,
     got_pack_progress_cb progress_cb, void *progress_arg,
@@ -1113,7 +1126,8 @@ load_tag(int want_meta, struct got_object_idset *idset
 	const struct got_error *err;
 	struct got_tag_object *tag = NULL;
 
-	if (got_object_idset_contains(idset, id))
+	if (got_object_idset_contains(idset, id) ||
+	    got_object_idset_contains(idset_exclude, id))
 		return NULL;
 
 	if (loose_obj_only) {
@@ -1129,7 +1143,8 @@ load_tag(int want_meta, struct got_object_idset *idset
 	if (err)
 		return err;
 
-	err = add_object(want_meta, idset, id, "", GOT_OBJ_TYPE_TAG,
+	err = add_object(want_meta, want_meta ? idset : idset_exclude,
+	    id, "", GOT_OBJ_TYPE_TAG,
 	    got_object_tag_get_tagger_time(tag), loose_obj_only, repo,
 	    ncolored, nfound, ntrees, progress_cb, progress_arg, rl);
 	if (err)
@@ -1137,13 +1152,13 @@ load_tag(int want_meta, struct got_object_idset *idset
 
 	switch (got_object_tag_get_object_type(tag)) {
 	case GOT_OBJ_TYPE_COMMIT:
-		err = load_commit(want_meta, idset,
+		err = load_commit(want_meta, idset, idset_exclude,
 		    got_object_tag_get_object_id(tag), repo, loose_obj_only,
 		    ncolored, nfound, ntrees, progress_cb, progress_arg, rl,
 		    cancel_cb, cancel_arg);
 		break;
 	case GOT_OBJ_TYPE_TREE:
-		err = load_tree(want_meta, idset,
+		err = load_tree(want_meta, idset, idset_exclude,
 		    got_object_tag_get_object_id(tag), "",
 		    got_object_tag_get_tagger_time(tag), repo, loose_obj_only,
 		    ncolored, nfound, ntrees, progress_cb, progress_arg, rl,
@@ -1464,6 +1479,11 @@ load_object_ids(int *ncolored, int *nfound, int *ntree
 	const struct got_error *err = NULL;
 	struct got_object_id **ids = NULL;
 	int i, nobj = 0, obj_type;
+	struct got_object_idset *idset_exclude;
+
+	idset_exclude = got_object_idset_alloc();
+	if (idset_exclude == NULL)
+		return got_error_from_errno("got_object_idset_alloc");
 
 	*ncolored = 0;
 	*nfound = 0;
@@ -1482,14 +1502,14 @@ load_object_ids(int *ncolored, int *nfound, int *ntree
 		if (err)
 			return err;
 		if (obj_type == GOT_OBJ_TYPE_COMMIT) {
-			err = load_commit(0, idset, id, repo,
+			err = load_commit(0, idset, idset_exclude, id, repo,
 			    loose_obj_only, ncolored, nfound, ntrees,
 			    progress_cb, progress_arg, rl,
 			    cancel_cb, cancel_arg);
 			if (err)
 				goto done;
 		} else if (obj_type == GOT_OBJ_TYPE_TAG) {
-			err = load_tag(0, idset, id, repo,
+			err = load_tag(0, idset, idset_exclude, id, repo,
 			    loose_obj_only, ncolored, nfound, ntrees,
 			    progress_cb, progress_arg, rl,
 			    cancel_cb, cancel_arg);
@@ -1499,9 +1519,9 @@ load_object_ids(int *ncolored, int *nfound, int *ntree
 	}
 
 	for (i = 0; i < nobj; i++) {
-		err = load_commit(1, idset, ids[i], repo, loose_obj_only,
-		    ncolored, nfound, ntrees, progress_cb, progress_arg, rl,
-		    cancel_cb, cancel_arg);
+		err = load_commit(1, idset, idset_exclude,
+		    ids[i], repo, loose_obj_only, ncolored, nfound, ntrees,
+		    progress_cb, progress_arg, rl, cancel_cb, cancel_arg);
 		if (err)
 			goto done;
 	}
@@ -1520,9 +1540,9 @@ load_object_ids(int *ncolored, int *nfound, int *ntree
 			obj_type = m->obj_type;
 		if (obj_type != GOT_OBJ_TYPE_TAG)
 			continue;
-		err = load_tag(1, idset, id, repo, loose_obj_only,
-		    ncolored, nfound, ntrees, progress_cb, progress_arg, rl,
-		    cancel_cb, cancel_arg);
+		err = load_tag(1, idset, idset_exclude, id, repo,
+		    loose_obj_only, ncolored, nfound, ntrees,
+		    progress_cb, progress_arg, rl, cancel_cb, cancel_arg);
 		if (err)
 			goto done;
 	}
@@ -1531,6 +1551,7 @@ done:
 		free(ids[i]);
 	}
 	free(ids);
+	got_object_idset_free(idset_exclude);
 	return err;
 }
 
@@ -1855,17 +1876,6 @@ done:
 	if (outfd != -1 && close(outfd) == -1 && err == NULL)
 		err = got_error_from_errno("close");
 	return err;
-}
-
-static const struct got_error *
-remove_unused_object(struct got_object_id *id, void *data, void *arg)
-{
-	struct got_object_idset *idset = arg;
-
-	if (data == NULL)
-		got_object_idset_remove(NULL, idset, id);
-
-	return NULL;
 }
 
 static const struct got_error *
@@ -1912,10 +1922,6 @@ got_pack_create(uint8_t *packsha1, FILE *packfile,
 	if (err)
 		return err;
 
-	err = got_object_idset_for_each(idset, remove_unused_object, idset);
-	if (err)
-		goto done;
-
 	if (progress_cb) {
 		err = progress_cb(progress_arg, ncolored, nfound, ntrees,
 		    0L, nours, got_object_idset_num_elements(idset), 0, 0);