JAGXXSR7DR5FG77VKBF62BW7Q3JMVHCLHF4VB2PSLIZF4RLE553QC
FMYCPGKDAPOUFLQOCXXKZ6TR75HT3TNCG4X3GAJDM4ARWKNWOSWAC
LMUBFPDX3Z2OVJWYGV43V2HTNQXRTMUHRQ24ZK744GVQHRN43NTAC
PEUS54XQ5KJQYAVUYBG5MWLEHIOVPMZ3ANVC7HPQP6JUWWPRDW5AC
Y26WT3ZFN7KSVXOZ26B5Y2OR4M4VQYQLPMAHPC4O5VIT3ENBISXAC
OBKF6SIIFFHHY7YWKPPX75N23NAVUD5662DKIHXSSIDPKKXQ5ZDQC
Q7TKZCJP2Z75EICZYKCEZDHKGERSOKZGMTSU3UXETBHTF663T66AC
LVX6U4EKYXM6H32X5SZS4UBIM5PW4ND4F4QQOF5EQDX3DUHBYFGAC
ZYOEB24JLLX7AJG4K4OT3CQKWN6HWHENEN2L5QKUNFUFP5SSZMLAC
4RYULBDDDIVSJTIOTBBSQAWMSN6ZBZEFJ6UR7P6ECEXEXTGPMUOAC
XTKRT6OQYN4LARQRDLI2KBSAJTOFZNT4AMBZ46CPUDZXD7IDYYWQC
#ifndef ANI_VERTEX_H
#define ANI_VERTEX_H
/**
* Position of a byte within a change.
*/
typedef uint64_t change_position;
#define CHANGE_POSITION_ROOT ((change_position)0)
#define CHANGE_POSITION_BOTTOM ((change_position)1)
/**
* A byte identifier, a change together with a position
*
* Variants observed:
* - Hash
* - Option<Hash>
* - ChangeId
*/
struct position {};
/**
* A node in the repository graph, made of a change internal identifier, and a
* line identifier in that change.
*/
struct vertex {
void *change;
change_position start, end; /* line identifier */
};
#endif
#ifndef ANI_HUNK_H
#define ANI_HUNK_H
struct local {
char *path;
};
enum basehunk_type {
FILE_MOVE,
FILE_DEL,
FILE_UNDEL,
FILE_ADD,
SOLVE_NAME_CONFLICT,
UNSOLVE_NAME_CONFLICT,
EDIT,
REPLACEMENT,
SOLVE_ORDER_CONFLICT,
UNSOLVE_ORDER_CONFLICT,
RESURRECT_ZOMBIES,
ADD_ROOT,
DEL_ROOT,
};
struct file_move {
char *path;
};
struct edit {
uint64_t atom;
};
struct replacement {
uint64_t atom;
uint64_t replacement;
struct local local;
};
struct basehunk {
enum basehunk_type hunk_type;
union {
struct file_move file_move;
struct edit edit;
struct replacement replacement;
} hunk;
};
const char *hunk_basehunk_type_str(enum basehunk_type);
#endif
#include <stdint.h>
#include <stdlib.h>
#include "hunk.h"
const char *
hunk_basehunk_type_str(enum basehunk_type hunk_type)
{
switch (hunk_type) {
case FILE_MOVE:
return "file move";
case FILE_DEL:
return "file del";
case FILE_UNDEL:
return "file undel";
case FILE_ADD:
return "file add";
case SOLVE_NAME_CONFLICT:
return "solve name conflict";
case UNSOLVE_NAME_CONFLICT:
return "unsolve name conflict";
case EDIT:
return "edit";
case REPLACEMENT:
return "replacement";
case SOLVE_ORDER_CONFLICT:
return "solve order conflict";
case UNSOLVE_ORDER_CONFLICT:
return "unsolve order conflict";
case RESURRECT_ZOMBIES:
return "resurrect zombies";
case ADD_ROOT:
return "add root";
case DEL_ROOT:
return "del root";
default:
abort();
}
}
break;
default:
abort();
}
}
}
void
change_decode_position(struct bincode_state *binstat)
{
uint64_t change_position; /* FIXME this should be its own type */
if (bincode_getu8(binstat)) {
struct hash hash;
hash.variant = (uint8_t)bincode_getu32(binstat);
switch (hash.variant) {
case HASH_NONE:
break;
case HASH_BLAKE3:
bincode_getbytes(
binstat, (uint8_t *)hash.bytes, BLAKE3_BYTES
);
break;
default:
abort();
}
hash_print(&hash);
}
change_position = bincode_getu64(binstat);
printf("ChangePosition(%lu)\n", change_position);
}
void
change_decode_newedge(struct bincode_state *binstat)
{
uint8_t previous, flag;
dump_buf("newedge", binstat->buf, binstat->avail);
previous = bincode_getu8(binstat);
flag = bincode_getu8(binstat);
printf("previous = %u, flag = %u\n", previous, flag);
/* TODO: It might be nice to be able to dump the flags? */
/* from: Position<Change = Option<Hash>> */
change_decode_position(binstat);
/* to: V(Some(HASH)[range?]) */
/* introduced_by: Option<Hash> */
}
void
change_decode_atom(struct bincode_state *binstat)
{
uint64_t edges_len;
int i;
switch (bincode_getu32(binstat)) {
case 0: /* NewVertex<Option<Hash>> */
/* TODO */
break;
case 1:
/* A list of edges */
edges_len = bincode_getu64(binstat);
printf("EdgeMap (%lu elements)\n", edges_len);
for (i = 0; i < edges_len; i++) {
change_decode_newedge(binstat);
break; /* FIXME remove this */
}
/* A Position<Change = Option<Hash>> */
break;
default:
abort();
}
}
/**
* Decode the hunks in a change
*/
void
change_decode_hunks(struct bincode_state *binstat)
{
uint64_t len;
int i;
len = bincode_getu64(binstat);
for (i = 0; i < len; i++) {
enum basehunk_type hunk_type = bincode_getu32(binstat);
printf("%d. %s\n", i + 1, hunk_basehunk_type_str(hunk_type));
switch (hunk_type) {
case EDIT:
printf("Edit. change: Atom, local: Local, encoding: Option<Encoding>\n"
);
change_decode_atom(binstat); /* the change field */
/* change_decode_local */
/* change_decode_encoding (maybe) */
break;
case REPLACEMENT:
printf("Replacement. change: Atom, replacement: Atom, local: Local, encoding: Option<Encoding>\n"
);
#ifndef ANI_ATOM_H
#define ANI_ATOM_H
#define EDGE_FLAG_BLOCK 1
#define EDGE_FLAG_PSEUDO 4
#define EDGE_FLAG_FOLDER 16
#define EDGE_FLAG_PARENT 32
#define EDGE_FLAG_DELETED 128
enum atom_type {
NEW_VERTEX,
EDGE_MAP
};
struct new_vertex {
struct hash up_context; /* FIXME Option<Hash> */
struct hash down_context;
uint8_t flag; /* EDGE_FLAG_* */
uint64_t start; /* start, end: ChangePosition = L64 */
uint64_t end;
/* FIXME inode: Position<Option<Hash>> = struct { change: Option<Hash>, pos: } */
};
struct atom {
enum atom_type atom_type;
union {
struct new_vertex new_vertex;
} atom;
};
#endif