From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: "Shawn O. Pearce" <spearce@spearce.org>
Subject: [PATCH 4/5] write_idx_file: need_large_offset() helper function
Date: Mon, 28 Feb 2011 01:49:42 -0800 [thread overview]
Message-ID: <1298886583-30965-5-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1298886583-30965-1-git-send-email-gitster@pobox.com>
Extract the logic to determine if a given "offset" value needs to be
represented as a large offset in the .idx file into a separate helper
function.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* This incidentally "fixes" the initial determination of index_version.
Earlier it didn't take the off32-limit given from the command line into
account when inspecting the offset of the last object in the pack, but
this version does. As off32-limit is primarily a debugging feature,
this does not matter much, but as long as we are touching the
surrounding code, it would be better to fix it.
pack-write.c | 29 +++++++++++++++++++----------
1 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/pack-write.c b/pack-write.c
index 16529c3..92e7eef 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -16,6 +16,11 @@ static int sha1_compare(const void *_a, const void *_b)
return hashcmp(a->sha1, b->sha1);
}
+static int need_large_offset(off_t offset, const struct pack_idx_option *opts)
+{
+ return (offset >> 31) || (opts->off32_limit < offset);
+}
+
/*
* On entry *sha1 contains the pack content SHA1 hash, on exit it is
* the SHA1 hash of sorted object names. The objects array passed in
@@ -65,7 +70,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
}
/* if last object's offset is >= 2^31 we should use index V2 */
- index_version = (last_obj_offset >> 31) ? 2 : opts->version;
+ index_version = need_large_offset(last_obj_offset, opts) ? 2 : opts->version;
/* index versions 2 and above need a header */
if (index_version >= 2) {
@@ -125,8 +130,11 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
list = sorted_by_sha;
for (i = 0; i < nr_objects; i++) {
struct pack_idx_entry *obj = *list++;
- uint32_t offset = (obj->offset <= opts->off32_limit) ?
- obj->offset : (0x80000000 | nr_large_offset++);
+ uint32_t offset;
+
+ offset = (need_large_offset(obj->offset, opts)
+ ? (0x80000000 | nr_large_offset++)
+ : obj->offset);
offset = htonl(offset);
sha1write(f, &offset, 4);
}
@@ -136,13 +144,14 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
while (nr_large_offset) {
struct pack_idx_entry *obj = *list++;
uint64_t offset = obj->offset;
- if (offset > opts->off32_limit) {
- uint32_t split[2];
- split[0] = htonl(offset >> 32);
- split[1] = htonl(offset & 0xffffffff);
- sha1write(f, split, 8);
- nr_large_offset--;
- }
+ uint32_t split[2];
+
+ if (!need_large_offset(offset, opts))
+ continue;
+ split[0] = htonl(offset >> 32);
+ split[1] = htonl(offset & 0xffffffff);
+ sha1write(f, split, 8);
+ nr_large_offset--;
}
}
--
1.7.4.1.249.g4aa72
next prev parent reply other threads:[~2011-02-28 9:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-28 9:49 [PATCH 0/5] Using index-pack in place of verify-pack Junio C Hamano
2011-02-28 9:49 ` [PATCH 1/5] index-pack: group the delta-base array entries also by type Junio C Hamano
2011-02-28 9:49 ` [PATCH 2/5] write_idx_file: introduce a struct to hold idx customization options Junio C Hamano
2011-02-28 9:49 ` [PATCH 3/5] index-pack: --verify Junio C Hamano
2011-02-28 17:48 ` Shawn O. Pearce
2011-02-28 18:54 ` Junio C Hamano
2011-02-28 9:49 ` Junio C Hamano [this message]
2011-02-28 9:49 ` [PATCH 5/5] index-pack --verify: read anomalous offsets from v2 idx file Junio C Hamano
2011-02-28 13:07 ` [PATCH 0/5] Using index-pack in place of verify-pack Sverre Rabbelier
2011-02-28 16:16 ` Junio C Hamano
2011-02-28 16:46 ` Sverre Rabbelier
2011-02-28 16:58 ` Jeff King
2011-02-28 17:01 ` Sverre Rabbelier
2011-02-28 17:25 ` Shawn O. Pearce
2011-02-28 19:50 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1298886583-30965-5-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/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.
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 NNTP newsgroup(s).