change: rework printing of patches - print Edit and Newvertex types

laumann
Nov 11, 2022, 10:55 PM
YDQLW2ZOAH7PZ7HHVTSFUO5IWE6O7FDNXVNIN7GG4TJ3P2B2BM4AC

Dependencies

  • [2] QYRJIOYP change: separate decoding and printing of hashed struct
  • [3] WMFNGOYT change: reduce printed noise, rework some code
  • [4] ZKAOPMCH change: Implement decoding of edits, atoms, positions, among others
  • [5] KDJUAAAL change: prefix function names with change_
  • [6] OBKF6SII change: decompress the hashed section too
  • [7] 3FT3XTJM change: support -v/-h flags
  • [8] RIWSVVAS change: decompress the 'contents' with zstd_seekable
  • [9] Q7TKZCJP Add initial support for reading the offsets from a (fixed) change
  • [10] 2U7P5SFQ Change struct names "struct foo -> typedef struct Foo"
  • [*] XTKRT6OQ format the codebase
  • [*] QEFCNNVC change: display offsets for given change file

Change contents

  • edit in change.c at line 510
    [12.2024]
    [3.2592]
    }
    void
    print_positionlist(Positionlist *plist)
    {
    Position *p;
    int i;
    p = &plist->first;
    printf("P0.%lu", p->pos);
    if (plist->len > 1)
    for (i = 0; i < plist->len - 1; i++) {
    printf("P%d.%lu", i + 1, plist->entries[i].pos);
    }
  • edit in change.c at line 527
    [3.2599]
    [13.4]
    * TODO To properly print EDGE_MAP types we need access to referenced changes to pull deleted lines
    */
    void
    print_atom(Atom *a, uint8_t *contents)
    {
    Newvertex *v;
    Edgemap *m;
    char *c, x;
    int i, waseol;
    switch (a->atomtype) {
    case NEW_VERTEX:
    v = &a->newvertex;
    printf("up: ");
    print_positionlist(&v->upcontext);
    printf(", ");
    printf("new: %lu:%lu, down: ", v->start, v->end);
    print_positionlist(&v->downcontext);
    printf("\n");
    waseol = 1;
    for (i = v->start; i < v->end; i++) {
    if (waseol) {
    printf("+ ");
    waseol = 0;
    }
    x = contents[i];
    putchar(x);
    if (x == '\n')
    waseol = 1;
    }
    printf("\n");
    break;
    case EDGE_MAP:
    m = &a->edgemap;
    printf("EdgeMap... \n");
    break;
    default:
    abort();
    }
    }
    /**
  • edit in change.c at line 619
    [2.949]
    [2.1473]
    /**
    * Seek to the point in the file where contents begin. Keep in mind,
    * we've already read 56 bytes.
    */
    if (lseek(fd, off.contents_off, SEEK_SET) == -1) {
    perror("lseek");
    goto out;
    }
    contents = change_read_contents(fd, &off);
    if (verbose)
    dump_buf("contents", contents, off.contents_len);
  • replacement in change.c at line 656
    [2.2234][2.2234:2249]()
    printf("\n");
    [2.2234]
    [2.2249]
    printf("\n#Hunks\n\n");
  • replacement in change.c at line 658
    [2.2250][3.2622:2730](),[3.2622][3.2622:2730](),[3.2778][3.2778:2866]()
    /**
    * Seek to the point in the file where contents begin. Keep in mind,
    * we've already read 56 bytes.
    */
    if (lseek(fd, off.contents_off, SEEK_SET) == -1) {
    perror("lseek");
    goto out;
    [2.2250]
    [3.2866]
    /* FIXME: Put all the hashes of dependencies in a big list, and number them from 2 */
    for (i = 0; i < hashed.hunks.len; i++) {
    Basehunk *hunk = &hashed.hunks.entries[i];
    printf("%d. %s", i + 1, hunk_basehunk_type_str(hunk->hunktype));
    switch (hunk->hunktype) {
    case EDIT:
    Edit *e = &hunk->edit;
    Atom *c = &e->change;
    printf(" in %s:%u (%s)", e->local.path, e->local.line,
    e->encoding);
    printf("\n");
    print_atom(c, contents);
    break;
    case REPLACEMENT:
    Replacement *r = &hunk->replacement;
    printf(" in %s:%u (%s)", r->local.path, r->local.line,
    r->encoding);
    printf("\n");
    break;
    default:
    printf(" [not yet implemented]\n");
    break;
    }
  • edit in change.c at line 685
    [3.2870][3.144:188](),[3.188][3.118:184]()
    contents = change_read_contents(fd, &off);
    if (verbose)
    dump_buf("contents", contents, off.contents_len);