Commit Diff


commit - 65f92520952841ce9afbb2068908932c5edaf906229375f74630ada4c758d88e
commit + c46b1605c71bd0ae9d2cfa477c55baa7b08a6a67c4009342fdca91a8ca606d44
blob - 4131582a4a1521051e8a847bac311d68ac9aaace975b6fcba2a2e7ffef0ffab3
blob + b3782a72b716bd9b1ad93009e1293ea85370f35d97c65aca9b5b180c956a991a
--- lib/pack_create.c	
+++ lib/pack_create.c	
@@ -1143,8 +1143,8 @@ got_pack_find_pack_for_commit_painting(struct got_pack
 	*best_packidx = NULL;
 
 	/*
-	 * Find the largest pack which contains at least some of the
-	 * commits we are interested in.
+	 * Find the largest pack which contains the commit at the head
+	 * of the queue and some other commits we are interested in.
 	 */
 	RB_FOREACH(pe, got_pathlist_head, &repo->packidx_paths) {
 		const char *path_packidx = pe->path;
@@ -1157,15 +1157,24 @@ got_pack_find_pack_for_commit_painting(struct got_pack
 			break;
 
 		nobj = be32toh(packidx->hdr.fanout_table[0xff]);
-		if (nobj <= nobj_max)
+		if (nobj < nobj_max)
 			continue;
 
-		STAILQ_FOREACH(qid, ids, entry) {
+		qid = STAILQ_FIRST(ids);
+		idx = got_packidx_get_object_idx(packidx, &qid->id);
+		if (idx == -1)
+			continue;
+		ncommits++;
+
+		qid = STAILQ_NEXT(qid, entry);
+		while (qid) {
 			idx = got_packidx_get_object_idx(packidx, &qid->id);
 			if (idx != -1)
 				ncommits++;
+			qid = STAILQ_NEXT(qid, entry);
 		}
-		if (ncommits > ncommits_max) {
+
+		if (ncommits >= ncommits_max) {
 			best_packidx_path = path_packidx;
 			nobj_max = nobj;
 			ncommits_max = ncommits;
@@ -1280,9 +1289,12 @@ find_pack_for_enumeration(struct got_packidx **best_pa
 
 	*best_packidx = NULL;
 
+	if (nids == 0)
+		return NULL;
+
 	/*
-	 * Find the largest pack which contains at least some of the
-	 * commits and tags we are interested in.
+	 * Find the largest pack which contains the commit at the head
+	 * of the queue and some other commits we are interested in.
 	 */
 	RB_FOREACH(pe, got_pathlist_head, &repo->packidx_paths) {
 		const char *path_packidx = pe->path;
@@ -1294,15 +1306,20 @@ find_pack_for_enumeration(struct got_packidx **best_pa
 			break;
 
 		nobj = be32toh(packidx->hdr.fanout_table[0xff]);
-		if (nobj <= nobj_max)
+		if (nobj < nobj_max)
 			continue;
 
-		for (i = 0; i < nids; i++) {
+		idx = got_packidx_get_object_idx(packidx, ids[0]);
+		if (idx == -1)
+			continue;
+		ncommits++;
+
+		for (i = 1; i < nids; i++) {
 			idx = got_packidx_get_object_idx(packidx, ids[i]);
 			if (idx != -1)
 				ncommits++;
 		}
-		if (ncommits > ncommits_max) {
+		if (ncommits >= ncommits_max) {
 			best_packidx_path = path_packidx;
 			nobj_max = nobj;
 			ncommits_max = ncommits;