git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH] fast-import: use write_pack_header()
@ 2020-09-06  8:39 René Scharfe
  2020-09-10 12:41 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2020-09-06  8:39 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

Call write_pack_header() to hash and write a pack header instead of
open-coding this function.  This gets rid of duplicate code and of the
magic version number 2 -- which has been used here since c90be46abd
(Changed fast-import's pack header creation to use pack.h, 2006-08-16)
and in pack.h (again) since 29f049a0c2 (Revert "move pack creation to
version 3", 2006-10-14).

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/fast-import.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 1c85eafe43..1bf50a73dc 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -739,7 +739,6 @@ static void start_packfile(void)
 {
 	struct strbuf tmp_file = STRBUF_INIT;
 	struct packed_git *p;
-	struct pack_header hdr;
 	int pack_fd;

 	pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX");
@@ -750,13 +749,8 @@ static void start_packfile(void)
 	p->do_not_close = 1;
 	pack_file = hashfd(pack_fd, p->pack_name);

-	hdr.hdr_signature = htonl(PACK_SIGNATURE);
-	hdr.hdr_version = htonl(2);
-	hdr.hdr_entries = 0;
-	hashwrite(pack_file, &hdr, sizeof(hdr));
-
 	pack_data = p;
-	pack_size = sizeof(hdr);
+	pack_size = write_pack_header(pack_file, 0);
 	object_count = 0;

 	REALLOC_ARRAY(all_packs, pack_id + 1);
--
2.28.0

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

* Re: [PATCH] fast-import: use write_pack_header()
  2020-09-06  8:39 [PATCH] fast-import: use write_pack_header() René Scharfe
@ 2020-09-10 12:41 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2020-09-10 12:41 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano

On Sun, Sep 06, 2020 at 10:39:23AM +0200, René Scharfe wrote:

> Call write_pack_header() to hash and write a pack header instead of
> open-coding this function.  This gets rid of duplicate code and of the
> magic version number 2 -- which has been used here since c90be46abd
> (Changed fast-import's pack header creation to use pack.h, 2006-08-16)
> and in pack.h (again) since 29f049a0c2 (Revert "move pack creation to
> version 3", 2006-10-14).

I think this is worth doing. It locks us into using PACK_VERSION, but
that has been constant for quite a long time now. If we ever finally
have a v4 pack, I expect write_pack_header would grow a version option
and we could deal with it then. :)

-Peff

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

end of thread, other threads:[~2020-09-10 21:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-06  8:39 [PATCH] fast-import: use write_pack_header() René Scharfe
2020-09-10 12:41 ` Jeff King

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