git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] Use uint32_t for unpack-objects counters

From
Dan McGee <dpmcgee@gmail.com>
Date
Mar 31, 2011, 01:24 UTC
Message-ID
<1301534674-31981-2-git-send-email-dpmcgee@gmail.com>
In-Reply-To
<1301534674-31981-1-git-send-email-dpmcgee@gmail.com>

This is a follow-up to the very old commit 7cadf491c6d7a2. The fixes are relatively simple (unsigned -> uint32_t) and we can also turn a static global (nr_objects) into a passed variable since it is used in very few places.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
---
 builtin/unpack-objects.c |   38 ++++++++++++++++++++------------------
 1 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index f63973c..a9e681e 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -124,7 +124,7 @@ static void *get_data(unsigned long size)
 
 struct delta_info {
 	unsigned char base_sha1[20];
-	unsigned nr;
+	uint32_t nr;
 	off_t base_offset;
 	unsigned long size;
 	void *delta;
@@ -133,7 +133,7 @@ struct delta_info {
 
 static struct delta_info *delta_list;
 
-static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1,
+static void add_delta_to_list(uint32_t nr, unsigned const char *base_sha1,
 			      off_t base_offset,
 			      void *delta, unsigned long size)
 {
@@ -158,7 +158,6 @@ struct obj_info {
 #define FLAG_WRITTEN (1u<<21)
 
 static struct obj_info *obj_list;
-static unsigned nr_objects;
 
 /*
  * Called only from check_object() after it verified this object
@@ -206,16 +205,16 @@ static int check_object(struct object *obj, int type, void *data)
 	return 0;
 }
 
-static void write_rest(void)
+static void write_rest(uint32_t nr_objects)
 {
-	unsigned i;
+	uint32_t i;
 	for (i = 0; i < nr_objects; i++) {
 		if (obj_list[i].obj)
 			check_object(obj_list[i].obj, OBJ_ANY, NULL);
 	}
 }
 
-static void added_object(unsigned nr, enum object_type type,
+static void added_object(uint32_t nr, enum object_type type,
 			 void *data, unsigned long size);
 
 /*
@@ -223,7 +222,7 @@ static void added_object(unsigned nr, enum object_type type,
  * of it.  Under --strict, this buffers structured objects in-core,
  * to be checked at the end.
  */
-static void write_object(unsigned nr, enum object_type type,
+static void write_object(uint32_t nr, enum object_type type,
 			 void *buf, unsigned long size)
 {
 	if (!strict) {
@@ -259,7 +258,7 @@ static void write_object(unsigned nr, enum object_type type,
 	}
 }
 
-static void resolve_delta(unsigned nr, enum object_type type,
+static void resolve_delta(uint32_t nr, enum object_type type,
 			  void *base, unsigned long base_size,
 			  void *delta, unsigned long delta_size)
 {
@@ -279,7 +278,7 @@ static void resolve_delta(unsigned nr, enum object_type type,
  * We now know the contents of an object (which is nr-th in the pack);
  * resolve all the deltified objects that are based on it.
  */
-static void added_object(unsigned nr, enum object_type type,
+static void added_object(uint32_t nr, enum object_type type,
 			 void *data, unsigned long size)
 {
 	struct delta_info **p = &delta_list;
@@ -300,7 +299,7 @@ static void added_object(unsigned nr, enum object_type type,
 }
 
 static void unpack_non_delta_entry(enum object_type type, unsigned long size,
-				   unsigned nr)
+				   uint32_t nr)
 {
 	void *buf = get_data(size);
 
@@ -310,7 +309,7 @@ static void unpack_non_delta_entry(enum object_type type, unsigned long size,
 		free(buf);
 }
 
-static int resolve_against_held(unsigned nr, const unsigned char *base,
+static int resolve_against_held(uint32_t nr, const unsigned char *base,
 				void *delta_data, unsigned long delta_size)
 {
 	struct object *obj;
@@ -327,7 +326,7 @@ static int resolve_against_held(unsigned nr, const unsigned char *base,
 }
 
 static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
-			       unsigned nr)
+			       uint32_t nr)
 {
 	void *delta_data, *base;
 	unsigned long base_size;
@@ -356,7 +355,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
 		unsigned base_found = 0;
 		unsigned char *pack, c;
 		off_t base_offset;
-		unsigned lo, mid, hi;
+		uint32_t lo, mid, hi;
 
 		pack = fill(1);
 		c = *pack;
@@ -421,7 +420,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
 	free(base);
 }
 
-static void unpack_one(unsigned nr)
+static void unpack_one(uint32_t nr)
 {
 	unsigned shift;
 	unsigned char *pack;
@@ -464,9 +463,9 @@ static void unpack_one(unsigned nr)
 	}
 }
 
-static void unpack_all(void)
+static uint32_t unpack_all(void)
 {
-	int i;
+	uint32_t i, nr_objects;
 	struct progress *progress = NULL;
 	struct pack_header *hdr = fill(sizeof(struct pack_header));
 
@@ -490,11 +489,14 @@ static void unpack_all(void)
 
 	if (delta_list)
 		die("unresolved deltas left after unpacking");
+
+	return nr_objects;
 }
 
 int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
 {
 	int i;
+	uint32_t nr_objects;
 	unsigned char sha1[20];
 
 	read_replace_refs = 0;
@@ -545,11 +547,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
 		usage(unpack_usage);
 	}
 	git_SHA1_Init(&ctx);
-	unpack_all();
+	nr_objects = unpack_all();
 	git_SHA1_Update(&ctx, buffer, offset);
 	git_SHA1_Final(sha1, &ctx);
 	if (strict)
-		write_rest();
+		write_rest(nr_objects);
 	if (hashcmp(fill(20), sha1))
 		die("final sha1 did not match");
 	use(20);
-- 
1.7.4.2
Previous: Dan McGeeNext: Dan McGee
Message 2 of 6 in “write_idx_file should use an unsigned nr_objects parameter”
  1. 1/4 write_idx_file should use an unsigned nr_objects parameterDan McGee, Mar 31, 2011
  2. 2/4 Use uint32_t for unpack-objects countersDan McGee, Mar 31, 2011
  3. 3/4 Use uint32_t for index-pack countersDan McGee, Mar 31, 2011
  4. 4/4 Unify pack header checking between index-pack and unpack-objectsDan McGee, Mar 31, 2011
  5. Junio C HamanoApr 1, 2011
  6. Dan McGeeApr 1, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.