Download raw body.
regress: change how trim_obj_id works
On Sat, Jul 13, 2024 at 04:09:24PM +0200, Omar Polo wrote:
> Omar Polo <op@omarpolo.com> wrote:
> > trim_obj_ids is a bit weird IMHO in that you have to specify how many
> > characters to drop *from the end* instead of how many to keep from the
> > beginning. This comes in the way of enabling some parts of the regress
> > for sha256 since object IDs are longer, and a `trim_obj_id 38` will not
> > yield 2 characters, but 26!
> >
> > Instead, what about using the numeric argument to mean the number of
> > characters to keep from the beginning? Then `trim_obj_id 2` will always
> > return the first two characters, regardless of the length of the hash.
> >
> > The diff boils down to
> >
> > @@ -132,13 +132,7 @@ trim_obj_id()
> > local trimcount=$1
> > local id=$2
> >
> > - local pat=""
> > - while [ "$trimcount" -gt 0 ]; do
> > - pat="[0-9a-f]$pat"
> > - trimcount=$((trimcount - 1))
> > - done
> > -
> > - echo ${id%$pat}
> > + echo "$id" | sed -E "s/^([0-9a-f]{$trimcount}).*/\1/"
> > }
> >
> > plus a mechanical fix for all the places where it's used. Regress of
> > course passes. ok?
>
> forgot to stage a few files, here's a diff that fixes tog/ and gotd/
> too.
>
yes ok, i already got confused about this myself on occasion.
regress: change how trim_obj_id works