git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH] packfile: use get_be64() for large offsets
@ 2018-01-17 19:08 Derrick Stolee
  2018-01-17 22:29 ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Derrick Stolee @ 2018-01-17 19:08 UTC (permalink / raw)
  To: git; +Cc: git, stolee, Derrick Stolee

The pack-index version 2 format uses two 4-byte integers in network-byte order to represent one 8-byte value. The current implementation has several code clones for stitching these integers together.

Use get_be64() to create an 8-byte integer from two 4-byte integers represented this way.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 pack-revindex.c | 6 ++----
 packfile.c      | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/pack-revindex.c b/pack-revindex.c
index 1b7ebd8d7e..ff5f62c033 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -134,10 +134,8 @@ static void create_pack_revindex(struct packed_git *p)
 			if (!(off & 0x80000000)) {
 				p->revindex[i].offset = off;
 			} else {
-				p->revindex[i].offset =
-					((uint64_t)ntohl(*off_64++)) << 32;
-				p->revindex[i].offset |=
-					ntohl(*off_64++);
+				p->revindex[i].offset = get_be64(off_64);
+				off_64 += 2;
 			}
 			p->revindex[i].nr = i;
 		}
diff --git a/packfile.c b/packfile.c
index 4a5fe7ab18..228ed0d59a 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1702,8 +1702,7 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n)
 			return off;
 		index += p->num_objects * 4 + (off & 0x7fffffff) * 8;
 		check_pack_index_ptr(p, index);
-		return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) |
-				   ntohl(*((uint32_t *)(index + 4)));
+		return get_be64(index);
 	}
 }
 
-- 
2.15.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] packfile: use get_be64() for large offsets
  2018-01-17 19:08 [PATCH] packfile: use get_be64() for large offsets Derrick Stolee
@ 2018-01-17 22:29 ` Jeff King
  2018-01-18 11:04   ` [PATCH v2] " Derrick Stolee
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff King @ 2018-01-17 22:29 UTC (permalink / raw)
  To: Derrick Stolee; +Cc: git, git, stolee

On Wed, Jan 17, 2018 at 02:08:23PM -0500, Derrick Stolee wrote:

> The pack-index version 2 format uses two 4-byte integers in network-byte order to represent one 8-byte value. The current implementation has several code clones for stitching these integers together.

Yeah, this seems like a no-brainer, and the patch itself looks obviously
correct.

Please wrap your commit messages a bit shorter, though (say, between
60-72 chars).

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] packfile: use get_be64() for large offsets
  2018-01-17 22:29 ` Jeff King
@ 2018-01-18 11:04   ` Derrick Stolee
  2018-01-18 14:15     ` SZEDER Gábor
  0 siblings, 1 reply; 5+ messages in thread
From: Derrick Stolee @ 2018-01-18 11:04 UTC (permalink / raw)
  To: git; +Cc: stolee, peff, git, Derrick Stolee

The pack-index version 2 format uses two 4-byte integers in network-
byte order to represent one 8-byte value. The current implementation
has several code clones for stitching these integers together.

Use get_be64() to create an 8-byte integer from two 4-byte integers
represented this way.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 pack-revindex.c | 6 ++----
 packfile.c      | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/pack-revindex.c b/pack-revindex.c
index 1b7ebd8d7e..ff5f62c033 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -134,10 +134,8 @@ static void create_pack_revindex(struct packed_git *p)
 			if (!(off & 0x80000000)) {
 				p->revindex[i].offset = off;
 			} else {
-				p->revindex[i].offset =
-					((uint64_t)ntohl(*off_64++)) << 32;
-				p->revindex[i].offset |=
-					ntohl(*off_64++);
+				p->revindex[i].offset = get_be64(off_64);
+				off_64 += 2;
 			}
 			p->revindex[i].nr = i;
 		}
diff --git a/packfile.c b/packfile.c
index 4a5fe7ab18..228ed0d59a 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1702,8 +1702,7 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n)
 			return off;
 		index += p->num_objects * 4 + (off & 0x7fffffff) * 8;
 		check_pack_index_ptr(p, index);
-		return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) |
-				   ntohl(*((uint32_t *)(index + 4)));
+		return get_be64(index);
 	}
 }
 
-- 
2.15.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] packfile: use get_be64() for large offsets
  2018-01-18 11:04   ` [PATCH v2] " Derrick Stolee
@ 2018-01-18 14:15     ` SZEDER Gábor
  2018-01-19 19:12       ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: SZEDER Gábor @ 2018-01-18 14:15 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: SZEDER Gábor, git, stolee, peff, git, Derrick Stolee

Junio,

> The pack-index version 2 format uses two 4-byte integers in network-
> byte order to represent one 8-byte value. The current implementation
> has several code clones for stitching these integers together.
> 
> Use get_be64() to create an 8-byte integer from two 4-byte integers
> represented this way.
> 
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  pack-revindex.c | 6 ++----
>  packfile.c      | 3 +--
>  2 files changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/pack-revindex.c b/pack-revindex.c
> index 1b7ebd8d7e..ff5f62c033 100644
> --- a/pack-revindex.c
> +++ b/pack-revindex.c
> @@ -134,10 +134,8 @@ static void create_pack_revindex(struct packed_git *p)
>  			if (!(off & 0x80000000)) {
>  				p->revindex[i].offset = off;
>  			} else {
> -				p->revindex[i].offset =
> -					((uint64_t)ntohl(*off_64++)) << 32;
> -				p->revindex[i].offset |=
> -					ntohl(*off_64++);
> +				p->revindex[i].offset = get_be64(off_64);
> +				off_64 += 2;
>  			}
>  			p->revindex[i].nr = i;
>  		}
> diff --git a/packfile.c b/packfile.c
> index 4a5fe7ab18..228ed0d59a 100644
> --- a/packfile.c
> +++ b/packfile.c
> @@ -1702,8 +1702,7 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n)
>  			return off;
>  		index += p->num_objects * 4 + (off & 0x7fffffff) * 8;
>  		check_pack_index_ptr(p, index);
> -		return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) |
> -				   ntohl(*((uint32_t *)(index + 4)));
> +		return get_be64(index);
>  	}
>  }
>  
> -- 
> 2.15.0
> 

This patch can't be applied to 'maint' currently at 3013dff86 (Prepare
for 2.15.2, 2017-12-06), as it is in case of 'ds/use-get-be64',
because 'maint' doesn't have get_be64() yet (b2e39d006 (bswap: add 64
bit endianness helper get_be64, 2017-09-22)).


Gábor


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] packfile: use get_be64() for large offsets
  2018-01-18 14:15     ` SZEDER Gábor
@ 2018-01-19 19:12       ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2018-01-19 19:12 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: git, stolee, peff, git, Derrick Stolee

SZEDER Gábor <szeder.dev@gmail.com> writes:

> Junio,
> ...
> This patch can't be applied to 'maint' currently at 3013dff86 (Prepare
> for 2.15.2, 2017-12-06), as it is in case of 'ds/use-get-be64',
> because 'maint' doesn't have get_be64() yet (b2e39d006 (bswap: add 64
> bit endianness helper get_be64, 2017-09-22)).

Thanks for stopping me.  

I do not always get to test anything not in 'next' in isolation
before I actually try to merge it there (at which time I would have
noticed), and you caught me in this one doing a short-cut "just
queue it somewhere and throw it in 'pu'".



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-01-19 19:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-17 19:08 [PATCH] packfile: use get_be64() for large offsets Derrick Stolee
2018-01-17 22:29 ` Jeff King
2018-01-18 11:04   ` [PATCH v2] " Derrick Stolee
2018-01-18 14:15     ` SZEDER Gábor
2018-01-19 19:12       ` Junio C Hamano

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git