mirror of
				https://git.proxmox.com/git/libgit2
				synced 2025-10-31 01:23:30 +00:00 
			
		
		
		
	khash: avoid using kh_foreach/kh_foreach_value directly
				
					
				
			This commit is contained in:
		
							parent
							
								
									63e914cbf4
								
							
						
					
					
						commit
						9694d9ba79
					
				| @ -53,7 +53,7 @@ void git_cache_dump_stats(git_cache *cache) | ||||
| 	printf("Cache %p: %"PRIuZ" items cached, %"PRIdZ" bytes\n", | ||||
| 		cache, git_cache_size(cache), cache->used_memory); | ||||
| 
 | ||||
| 	kh_foreach_value(cache->map, object, { | ||||
| 	git_oidmap_foreach_value(cache->map, object, { | ||||
| 		char oid_str[9]; | ||||
| 		printf(" %s%c %s (%"PRIuZ")\n", | ||||
| 			git_object_type2string(object->type), | ||||
| @ -84,7 +84,7 @@ static void clear_cache(git_cache *cache) | ||||
| 	if (git_cache_size(cache) == 0) | ||||
| 		return; | ||||
| 
 | ||||
| 	kh_foreach_value(cache->map, evict, { | ||||
| 	git_oidmap_foreach_value(cache->map, evict, { | ||||
| 		git_cached_obj_decref(evict); | ||||
| 	}); | ||||
| 
 | ||||
|  | ||||
| @ -1106,8 +1106,9 @@ void git_indexer_free(git_indexer *idx) | ||||
| 
 | ||||
| 	if (idx->pack->idx_cache) { | ||||
| 		struct git_pack_entry *pentry; | ||||
| 		kh_foreach_value( | ||||
| 			idx->pack->idx_cache, pentry, { git__free(pentry); }); | ||||
| 		git_oidmap_foreach_value(idx->pack->idx_cache, pentry, { | ||||
| 			git__free(pentry); | ||||
| 		}); | ||||
| 
 | ||||
| 		git_oidmap_free(idx->pack->idx_cache); | ||||
| 	} | ||||
|  | ||||
| @ -149,7 +149,7 @@ void git_mempack_reset(git_odb_backend *_backend) | ||||
| 	struct memory_packer_db *db = (struct memory_packer_db *)_backend; | ||||
| 	struct memobject *object = NULL; | ||||
| 
 | ||||
| 	kh_foreach_value(db->objects, object, { | ||||
| 	git_oidmap_foreach_value(db->objects, object, { | ||||
| 		git__free(object); | ||||
| 	}); | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										18
									
								
								src/pack.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/pack.c
									
									
									
									
									
								
							| @ -78,13 +78,12 @@ static void free_cache_object(void *o) | ||||
| 
 | ||||
| static void cache_free(git_pack_cache *cache) | ||||
| { | ||||
| 	khiter_t k; | ||||
| 	git_pack_cache_entry *entry; | ||||
| 
 | ||||
| 	if (cache->entries) { | ||||
| 		for (k = kh_begin(cache->entries); k != kh_end(cache->entries); k++) { | ||||
| 			if (kh_exist(cache->entries, k)) | ||||
| 				free_cache_object(kh_value(cache->entries, k)); | ||||
| 		} | ||||
| 		git_offmap_foreach_value(cache->entries, entry, { | ||||
| 			free_cache_object(entry); | ||||
| 		}); | ||||
| 
 | ||||
| 		git_offmap_free(cache->entries); | ||||
| 		cache->entries = NULL; | ||||
| @ -135,18 +134,13 @@ static void free_lowest_entry(git_pack_cache *cache) | ||||
| 	git_pack_cache_entry *entry; | ||||
| 	khiter_t k; | ||||
| 
 | ||||
| 	for (k = kh_begin(cache->entries); k != kh_end(cache->entries); k++) { | ||||
| 		if (!kh_exist(cache->entries, k)) | ||||
| 			continue; | ||||
| 
 | ||||
| 		entry = kh_value(cache->entries, k); | ||||
| 
 | ||||
| 	git_offmap_foreach(cache->entries, k, entry, { | ||||
| 		if (entry && entry->refcount.val == 0) { | ||||
| 			cache->memory_used -= entry->raw.len; | ||||
| 			kh_del(off, cache->entries, k); | ||||
| 			free_cache_object(entry); | ||||
| 		} | ||||
| 	} | ||||
| 	}); | ||||
| } | ||||
| 
 | ||||
| static int cache_add( | ||||
|  | ||||
| @ -702,7 +702,7 @@ void git_revwalk_reset(git_revwalk *walk) | ||||
| 
 | ||||
| 	assert(walk); | ||||
| 
 | ||||
| 	kh_foreach_value(walk->commits, commit, { | ||||
| 	git_oidmap_foreach_value(walk->commits, commit, { | ||||
| 		commit->seen = 0; | ||||
| 		commit->in_degree = 0; | ||||
| 		commit->topo_delay = 0; | ||||
|  | ||||
| @ -323,7 +323,6 @@ static int update_target(git_refdb *db, transaction_node *node) | ||||
| int git_transaction_commit(git_transaction *tx) | ||||
| { | ||||
| 	transaction_node *node; | ||||
| 	git_strmap_iter pos; | ||||
| 	int error = 0; | ||||
| 
 | ||||
| 	assert(tx); | ||||
| @ -335,11 +334,7 @@ int git_transaction_commit(git_transaction *tx) | ||||
| 		return error; | ||||
| 	} | ||||
| 
 | ||||
| 	for (pos = kh_begin(tx->locks); pos < kh_end(tx->locks); pos++) { | ||||
| 		if (!git_strmap_has_data(tx->locks, pos)) | ||||
| 			continue; | ||||
| 
 | ||||
| 		node = git_strmap_value_at(tx->locks, pos); | ||||
| 	git_strmap_foreach_value(tx->locks, node, { | ||||
| 		if (node->reflog) { | ||||
| 			if ((error = tx->db->backend->reflog_write(tx->db->backend, node->reflog)) < 0) | ||||
| 				return error; | ||||
| @ -349,7 +344,7 @@ int git_transaction_commit(git_transaction *tx) | ||||
| 			if ((error = update_target(tx->db, node)) < 0) | ||||
| 				return error; | ||||
| 		} | ||||
| 	} | ||||
| 	}); | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| @ -358,7 +353,6 @@ void git_transaction_free(git_transaction *tx) | ||||
| { | ||||
| 	transaction_node *node; | ||||
| 	git_pool pool; | ||||
| 	git_strmap_iter pos; | ||||
| 
 | ||||
| 	assert(tx); | ||||
| 
 | ||||
| @ -373,16 +367,12 @@ void git_transaction_free(git_transaction *tx) | ||||
| 	} | ||||
| 
 | ||||
| 	/* start by unlocking the ones we've left hanging, if any */ | ||||
| 	for (pos = kh_begin(tx->locks); pos < kh_end(tx->locks); pos++) { | ||||
| 		if (!git_strmap_has_data(tx->locks, pos)) | ||||
| 			continue; | ||||
| 
 | ||||
| 		node = git_strmap_value_at(tx->locks, pos); | ||||
| 	git_strmap_foreach_value(tx->locks, node, { | ||||
| 		if (node->committed) | ||||
| 			continue; | ||||
| 
 | ||||
| 		git_refdb_unlock(tx->db, node->payload, false, false, NULL, NULL, NULL); | ||||
| 	} | ||||
| 	}); | ||||
| 
 | ||||
| 	git_refdb_free(tx->db); | ||||
| 	git_strmap_free(tx->locks); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Patrick Steinhardt
						Patrick Steinhardt