diff mbox series

[v1,01/10] packfile: move sizep computation

Message ID 20240715003519.2671385-2-e@80x24.org (mailing list archive)
State New, archived
Headers show
Series cat-file speedups | expand

Commit Message

Eric Wong July 15, 2024, 12:35 a.m. UTC
From: Jeff King <peff@peff.net>

This makes the next commit to avoid redundant object info
lookups easier to understand.

[ew: commit message]

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Eric Wong <e@80x24.org>
---
 packfile.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

Comments

Patrick Steinhardt July 24, 2024, 8:35 a.m. UTC | #1
On Mon, Jul 15, 2024 at 12:35:10AM +0000, Eric Wong wrote:
> From: Jeff King <peff@peff.net>
> 
> This makes the next commit to avoid redundant object info

Starting with "this" without mentioning what "this" is in the commit
subject reads a bit weird. I know you mention what you do in the commit
title, but we usually use fully self-contained commit messages here.

> lookups easier to understand.
> 
> [ew: commit message]
> 
> Signed-off-by: Jeff King <peff@peff.net>
> Signed-off-by: Eric Wong <e@80x24.org>
> ---
>  packfile.c | 35 ++++++++++++++++++-----------------
>  1 file changed, 18 insertions(+), 17 deletions(-)
> 
> diff --git a/packfile.c b/packfile.c
> index 813584646f..e547522e3d 100644
> --- a/packfile.c
> +++ b/packfile.c
> @@ -1527,7 +1527,8 @@ int packed_object_info(struct repository *r, struct packed_git *p,
>  
>  	/*
>  	 * We always get the representation type, but only convert it to
> -	 * a "real" type later if the caller is interested.
> +	 * a "real" type later if the caller is interested. Likewise...
> +	 * tbd.

This comment gets addressed in the next commit, so this should likely
not be changed here?

Patrick
diff mbox series

Patch

diff --git a/packfile.c b/packfile.c
index 813584646f..e547522e3d 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1527,7 +1527,8 @@  int packed_object_info(struct repository *r, struct packed_git *p,
 
 	/*
 	 * We always get the representation type, but only convert it to
-	 * a "real" type later if the caller is interested.
+	 * a "real" type later if the caller is interested. Likewise...
+	 * tbd.
 	 */
 	if (oi->contentp) {
 		*oi->contentp = cache_or_unpack_entry(r, p, obj_offset, oi->sizep,
@@ -1536,24 +1537,24 @@  int packed_object_info(struct repository *r, struct packed_git *p,
 			type = OBJ_BAD;
 	} else {
 		type = unpack_object_header(p, &w_curs, &curpos, &size);
-	}
 
-	if (!oi->contentp && oi->sizep) {
-		if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
-			off_t tmp_pos = curpos;
-			off_t base_offset = get_delta_base(p, &w_curs, &tmp_pos,
-							   type, obj_offset);
-			if (!base_offset) {
-				type = OBJ_BAD;
-				goto out;
+		if (oi->sizep) {
+			if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
+				off_t tmp_pos = curpos;
+				off_t base_offset = get_delta_base(p, &w_curs, &tmp_pos,
+								   type, obj_offset);
+				if (!base_offset) {
+					type = OBJ_BAD;
+					goto out;
+				}
+				*oi->sizep = get_size_from_delta(p, &w_curs, tmp_pos);
+				if (*oi->sizep == 0) {
+					type = OBJ_BAD;
+					goto out;
+				}
+			} else {
+				*oi->sizep = size;
 			}
-			*oi->sizep = get_size_from_delta(p, &w_curs, tmp_pos);
-			if (*oi->sizep == 0) {
-				type = OBJ_BAD;
-				goto out;
-			}
-		} else {
-			*oi->sizep = size;
 		}
 	}