change: deduplicate some code repetition

laumann
May 12, 2023, 12:25 PM
U3JWO63YYQDCJX7CWXCS3N26CHY2TASADTCQIEDSJ7WC25GLZD5QC

Dependencies

  • [2] WFA5BBRF Fix warnings
  • [3] 2U7P5SFQ Change struct names "struct foo -> typedef struct Foo"
  • [4] KEC3WLFN change: remove debugging lines
  • [5] FMYCPGKD change: extract hash list decoding into reused function
  • [6] ZKAOPMCH change: Implement decoding of edits, atoms, positions, among others
  • [7] JAGXXSR7 change: initial work on decoding hunks
  • [*] Q7TKZCJP Add initial support for reading the offsets from a (fixed) change
  • [*] RIWSVVAS change: decompress the 'contents' with zstd_seekable
  • [*] OBKF6SII change: decompress the hashed section too

Change contents

  • edit in change.c at line 151
    [10.2591]
    [11.1065]
    }
    static void
    change_readhash(Bincode *binstat, uint8_t *dest, uint8_t variant)
    {
    switch (variant) {
    case HASH_BLAKE3:
    bincode_getbytes(binstat, dest, BLAKE3_BYTES);
    break;
    case HASH_NONE:
    /* Do nothing - no bytes to consume */
    break;
    default:
    die("unknown hash variant: %u", variant);
    }
  • replacement in change.c at line 180
    [2.129][3.311:371](),[3.311][3.311:371](),[3.371][3.989:1068](),[3.1068][3.514:583](),[3.514][3.514:583](),[3.583][3.2209:2246]()
    switch (target->entries[i].variant) {
    case HASH_BLAKE3:
    bincode_getbytes(
    binstat, target->entries[i].bytes, BLAKE3_BYTES
    );
    break;
    case HASH_NONE:
    /* Do nothing, no bytes to consume */
    break;
    default:
    abort();
    }
    [2.129]
    [3.2246]
    change_readhash(
    binstat, target->entries[i].bytes,
    target->entries[i].variant
    );
  • replacement in change.c at line 192
    [3.1196][3.1196:1347](),[3.1347][3.2509:2537](),[3.2509][3.2509:2537](),[3.2537][3.1348:1375]()
    switch (pos->change.variant) {
    case HASH_BLAKE3:
    bincode_getbytes(
    binstat, (uint8_t *)&pos->change.bytes,
    BLAKE3_BYTES
    );
    break;
    case HASH_NONE:
    break;
    default:
    abort();
    }
    [3.1196]
    [3.1375]
    change_readhash(
    binstat, (uint8_t *)&pos->change.bytes,
    pos->change.variant
    );
  • replacement in change.c at line 210
    [3.1626][3.1626:1653](),[3.1653][3.2537:2578](),[3.2537][3.2537:2578](),[3.2578][3.1654:1704](),[3.1704][3.2627:2643](),[3.2627][3.2627:2643](),[3.2643][3.1705:1733](),[3.1733][3.2643:2670](),[3.2643][3.2643:2670]()
    switch (hash->variant) {
    case HASH_BLAKE3:
    bincode_getbytes(
    binstat, (uint8_t *)hash->bytes, BLAKE3_BYTES
    );
    break;
    case HASH_NONE:
    break;
    default:
    abort();
    }
    [3.1626]
    [3.1734]
    change_readhash(binstat, (uint8_t *)hash->bytes, hash->variant);
  • replacement in change.c at line 224
    [3.2132][3.2132:2321]()
    switch (hash->variant) {
    case HASH_BLAKE3:
    bincode_getbytes(
    binstat, (uint8_t *)hash->bytes, BLAKE3_BYTES
    );
    break;
    case HASH_NONE:
    break;
    default:
    abort();
    }
    [3.2132]
    [3.2460]
    change_readhash(binstat, (uint8_t *)hash->bytes, hash->variant);
  • edit in change.c at line 227
    [3.2465]
    [3.2465]