On Tue, 27 Aug 2013, Junio C Hamano wrote: > Nicolas Pitre <nico@xxxxxxxxxxx> writes: > > > Add variable length number encoding. Let's apply the same encoding > > currently used for the offset to base of OBJ_OFS_DELTA objects which > > is the most efficient way to do this, and apply it to everything with > > pack version 4. > > > > Also add SHA1 reference encoding. This one is either an index into a > > SHA1 table encoded using the variable length number encoding, or the > > literal 20 bytes SHA1 prefixed with a 0. > > > > The index 0 discriminates between an actual index value or the literal > > SHA1. Therefore when the index is used its value must be increased by 1. > > > > Signed-off-by: Nicolas Pitre <nico@xxxxxxxxxxx> > > --- > > packv4-create.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 44 insertions(+) > > > > diff --git a/packv4-create.c b/packv4-create.c > > index 012129b..bf33d15 100644 > > --- a/packv4-create.c > > +++ b/packv4-create.c > > @@ -245,6 +245,50 @@ static void dict_dump(void) > > dump_dict_table(tree_path_table); > > } > > > > +/* > > + * Encode a numerical value with variable length into the destination buffer > > + */ > > +static unsigned char *add_number(unsigned char *dst, uint64_t value) > > +{ > > + unsigned char buf[20]; > > + unsigned pos = sizeof(buf) - 1; > > + buf[pos] = value & 127; > > + while (value >>= 7) > > + buf[--pos] = 128 | (--value & 127); > > + do { > > + *dst++ = buf[pos++]; > > + } while (pos < sizeof(buf)); > > + return dst; > > +} > > This may want to reuse (or enhance-then-reuse) varint.[ch]. Goodie! I didn't notice this had happened. Nicolas -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html