Re: [PATCH 31/38] sha1_file.c: make use of decode_varint()
- From
SZEDER Gábor <szeder@ira.uka.de>
- Date
- Sep 5, 2013, 07:35 UTC
- Message-ID
- <20130905073552.GD28959@goldbirke>
- In-Reply-To
- <1378362001-1738-32-git-send-email-nico@fluxnic.net>
On Thu, Sep 05, 2013 at 02:19:54AM -0400, Nicolas Pitre wrote:
Show 37 quoted lines
> ... replacing the equivalent open coded loop.
>
> Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
> ---
> sha1_file.c | 14 +++-----------
> 1 file changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/sha1_file.c b/sha1_file.c
> index a298933..67eb903 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -1687,20 +1687,12 @@ static off_t get_delta_base(struct packed_git *p,
> * is stupid, as then a REF_DELTA would be smaller to store.
> */
> if (type == OBJ_OFS_DELTA) {
> - unsigned used = 0;
> - unsigned char c = base_info[used++];
> - base_offset = c & 127;
> - while (c & 128) {
> - base_offset += 1;
> - if (!base_offset || MSB(base_offset, 7))
> - return 0; /* overflow */
> - c = base_info[used++];
> - base_offset = (base_offset << 7) + (c & 127);
> - }
> + const unsigned char *cp = base_info;
> + base_offset = decode_varint(&cp);
> base_offset = delta_obj_offset - base_offset;
> if (base_offset <= 0 || base_offset >= delta_obj_offset)
> return 0; /* out of bound */
> - *curpos += used;
> + *curpos += cp - base_info;
> } else if (type == OBJ_REF_DELTA) {
> /* The base entry _must_ be in the same pack */
> base_offset = find_pack_entry_one(base_info, p);
> --
> 1.8.4.38.g317e65bThis patch seems to be a cleanup independent from pack v4, it applies cleanly on master and passes all tests in itself.
Best, Gábor