git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: <git@vger.kernel.org>
Cc: "Eric Sunshine" <sunshine@sunshineco.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"René Scharfe" <l.s.r@web.de>, "Jeff King" <peff@peff.net>
Subject: [PATCH v2 32/35] dir: make untracked cache extension hash size independent
Date: Tue, 19 Feb 2019 00:05:23 +0000	[thread overview]
Message-ID: <20190219000526.476553-33-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20190219000526.476553-1-sandals@crustytoothpaste.net>

Instead of using a struct with a flex array member to read and write the
untracked cache extension, use a shorter, fixed-length struct and add
the name and hash data explicitly.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 dir.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/dir.c b/dir.c
index b2cabadf25..7503b56918 100644
--- a/dir.c
+++ b/dir.c
@@ -2545,13 +2545,9 @@ struct ondisk_untracked_cache {
 	struct stat_data info_exclude_stat;
 	struct stat_data excludes_file_stat;
 	uint32_t dir_flags;
-	unsigned char info_exclude_sha1[20];
-	unsigned char excludes_file_sha1[20];
-	char exclude_per_dir[FLEX_ARRAY];
 };
 
 #define ouc_offset(x) offsetof(struct ondisk_untracked_cache, x)
-#define ouc_size(len) (ouc_offset(exclude_per_dir) + len + 1)
 
 struct write_data {
 	int index;	   /* number of written untracked_cache_dir */
@@ -2634,20 +2630,21 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
 	struct write_data wd;
 	unsigned char varbuf[16];
 	int varint_len;
-	size_t len = strlen(untracked->exclude_per_dir);
+	const unsigned hashsz = the_hash_algo->rawsz;
 
-	FLEX_ALLOC_MEM(ouc, exclude_per_dir, untracked->exclude_per_dir, len);
+	ouc = xcalloc(1, sizeof(*ouc));
 	stat_data_to_disk(&ouc->info_exclude_stat, &untracked->ss_info_exclude.stat);
 	stat_data_to_disk(&ouc->excludes_file_stat, &untracked->ss_excludes_file.stat);
-	hashcpy(ouc->info_exclude_sha1, untracked->ss_info_exclude.oid.hash);
-	hashcpy(ouc->excludes_file_sha1, untracked->ss_excludes_file.oid.hash);
 	ouc->dir_flags = htonl(untracked->dir_flags);
 
 	varint_len = encode_varint(untracked->ident.len, varbuf);
 	strbuf_add(out, varbuf, varint_len);
 	strbuf_addbuf(out, &untracked->ident);
 
-	strbuf_add(out, ouc, ouc_size(len));
+	strbuf_add(out, ouc, sizeof(*ouc));
+	strbuf_add(out, untracked->ss_info_exclude.oid.hash, hashsz);
+	strbuf_add(out, untracked->ss_excludes_file.oid.hash, hashsz);
+	strbuf_add(out, untracked->exclude_per_dir, strlen(untracked->exclude_per_dir) + 1);
 	FREE_AND_NULL(ouc);
 
 	if (!untracked->root) {
@@ -2834,6 +2831,9 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
 	int ident_len;
 	ssize_t len;
 	const char *exclude_per_dir;
+	const unsigned hashsz = the_hash_algo->rawsz;
+	const unsigned offset = sizeof(struct ondisk_untracked_cache);
+	const unsigned exclude_per_dir_offset = offset + 2 * hashsz;
 
 	if (sz <= 1 || end[-1] != '\0')
 		return NULL;
@@ -2845,7 +2845,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
 	ident = (const char *)next;
 	next += ident_len;
 
-	if (next + ouc_size(0) > end)
+	if (next + exclude_per_dir_offset + 1 > end)
 		return NULL;
 
 	uc = xcalloc(1, sizeof(*uc));
@@ -2853,15 +2853,15 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
 	strbuf_add(&uc->ident, ident, ident_len);
 	load_oid_stat(&uc->ss_info_exclude,
 		      next + ouc_offset(info_exclude_stat),
-		      next + ouc_offset(info_exclude_sha1));
+		      next + offset);
 	load_oid_stat(&uc->ss_excludes_file,
 		      next + ouc_offset(excludes_file_stat),
-		      next + ouc_offset(excludes_file_sha1));
+		      next + offset + hashsz);
 	uc->dir_flags = get_be32(next + ouc_offset(dir_flags));
-	exclude_per_dir = (const char *)next + ouc_offset(exclude_per_dir);
+	exclude_per_dir = (const char *)next + exclude_per_dir_offset;
 	uc->exclude_per_dir = xstrdup(exclude_per_dir);
 	/* NUL after exclude_per_dir is covered by sizeof(*ouc) */
-	next += ouc_size(strlen(exclude_per_dir));
+	next += exclude_per_dir_offset + strlen(exclude_per_dir) + 1;
 	if (next >= end)
 		goto done2;
 

  parent reply	other threads:[~2019-02-19  0:06 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-19  0:04 [PATCH v2 00/35] Hash function transition part 16 brian m. carlson
2019-02-19  0:04 ` [PATCH v2 01/35] t/lib-submodule-update: use appropriate length constant brian m. carlson
2019-02-19  0:04 ` [PATCH v2 02/35] khash: move oid hash table definition brian m. carlson
2019-02-19  0:04 ` [PATCH v2 03/35] pack-bitmap: make bitmap header handling hash agnostic brian m. carlson
2019-02-19  0:04 ` [PATCH v2 04/35] pack-bitmap: convert struct stored_bitmap to object_id brian m. carlson
2019-02-19  0:04 ` [PATCH v2 05/35] pack-bitmap: replace sha1_to_hex brian m. carlson
2019-02-19  0:04 ` [PATCH v2 06/35] pack-bitmap: switch hard-coded constants to the_hash_algo brian m. carlson
2019-02-19  0:04 ` [PATCH v2 07/35] pack-bitmap: switch hash tables to use struct object_id brian m. carlson
2019-02-19  0:04 ` [PATCH v2 08/35] submodule: avoid hard-coded constants brian m. carlson
2019-02-19  0:05 ` [PATCH v2 09/35] notes-merge: switch to use the_hash_algo brian m. carlson
2019-02-19  0:05 ` [PATCH v2 10/35] notes: make hash size independent brian m. carlson
2019-02-19  0:05 ` [PATCH v2 11/35] notes: replace sha1_to_hex brian m. carlson
2019-02-19  0:05 ` [PATCH v2 12/35] object-store: rename and expand packed_git's sha1 member brian m. carlson
2019-02-19  0:05 ` [PATCH v2 13/35] builtin/name-rev: make hash-size independent brian m. carlson
2019-02-19  0:05 ` [PATCH v2 14/35] fast-import: " brian m. carlson
2019-02-19  0:05 ` [PATCH v2 15/35] fast-import: replace sha1_to_hex brian m. carlson
2019-02-19  0:05 ` [PATCH v2 16/35] builtin/am: make hash size independent brian m. carlson
2019-02-19  0:05 ` [PATCH v2 17/35] builtin/pull: make hash-size independent brian m. carlson
2019-02-19  0:05 ` [PATCH v2 18/35] http-push: convert to use the_hash_algo brian m. carlson
2019-02-19  0:05 ` [PATCH v2 19/35] http-backend: allow 64-character hex names brian m. carlson
2019-02-19  0:05 ` [PATCH v2 20/35] http-push: remove remaining uses of sha1_to_hex brian m. carlson
2019-02-19  0:05 ` [PATCH v2 21/35] http-walker: replace sha1_to_hex brian m. carlson
2019-02-19  0:05 ` [PATCH v2 22/35] http: replace hard-coded constant with the_hash_algo brian m. carlson
2019-02-19  0:05 ` [PATCH v2 23/35] http: compute hash of downloaded objects using the_hash_algo brian m. carlson
2019-02-19  0:05 ` [PATCH v2 24/35] http: replace sha1_to_hex brian m. carlson
2019-02-19  0:05 ` [PATCH v2 25/35] remote-curl: make hash size independent brian m. carlson
2019-02-19  0:05 ` [PATCH v2 26/35] hash: add a function to lookup hash algorithm by length brian m. carlson
2019-02-19  0:05 ` [PATCH v2 27/35] get-tar-commit-id: parse comment record brian m. carlson
2019-02-19  0:05 ` [PATCH v2 28/35] builtin/get-tar-commit-id: make hash size independent brian m. carlson
2019-02-19  0:05 ` [PATCH v2 29/35] archive: convert struct archiver_args to object_id brian m. carlson
2019-02-19  0:05 ` [PATCH v2 30/35] refspec: make hash size independent brian m. carlson
2019-02-19  0:05 ` [PATCH v2 31/35] builtin/difftool: use parse_oid_hex brian m. carlson
2019-02-19  0:05 ` brian m. carlson [this message]
2019-02-19  0:05 ` [PATCH v2 33/35] read-cache: read data in a hash-independent way brian m. carlson
2019-02-19  0:05 ` [PATCH v2 34/35] Git.pm: make hash size independent brian m. carlson
2019-02-19  0:05 ` [PATCH v2 35/35] gitweb: " brian m. carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190219000526.476553-33-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).