Skip to content

Commit

Permalink
git jets: switch to libbytestream
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolajpp committed Jul 22, 2024
1 parent 6125c1c commit 47b2710
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 82 deletions.
17 changes: 7 additions & 10 deletions pkg/noun/jets/e/git.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ static c3_w _read_size(c3_y* buf_y, c3_w* pos_wp, c3_w buf_len_w, c3_w len_w) {
u3_noun u3qe_git_pack_expand_delta_object(u3_noun base,
u3_noun delta) {

/* +$ raw-object [type=object-type size=@ud data=stream:libstream]
// +$ raw-object [type=object-type size=@ud data=octs]

/* +$ raw-object [type=object-type size=@ud data=octs]
+$ pack-object $% raw-object
[%ofs-delta pos=@ud base-offset=@ud =octs]
[%ref-delta pos=@ud =hash =octs]
Expand All @@ -116,12 +118,11 @@ u3_noun u3qe_git_pack_expand_delta_object(u3_noun base,
u3_atom base_size;
u3_noun base_data;

u3_atom base_data_pos;
u3_atom base_data_p_octs;
u3_atom base_data_q_octs;

u3x_trel(base, &base_type, &base_size, &base_data);
u3x_trel(base_data, &base_data_pos, &base_data_p_octs, &base_data_q_octs);
u3x_cell(base_data, &base_data_p_octs, &base_data_q_octs);

// delta=pack-object
//
Expand Down Expand Up @@ -165,7 +166,7 @@ u3_noun u3qe_git_pack_expand_delta_object(u3_noun base,
c3_w bas_len_w;

bas_y = _unpack_octs(base_data_p_octs, &base_data_q_octs, &bas_buf_len_w);
// u3_assert(base_size == (base_data_p_octs - base_data_pos));
u3_assert(base_size == base_data_p_octs);
bas_begin_y = bas_y;
bas_len_w = base_data_p_octs;

Expand All @@ -180,11 +181,9 @@ u3_noun u3qe_git_pack_expand_delta_object(u3_noun base,

// Base size mismatch
//
if (biz_w != (base_data_p_octs - base_data_pos)) {
if (biz_w != base_data_p_octs) {
fprintf(stderr, "bas_buf_len_w = %d, bas_len_w = %d\r\n", bas_buf_len_w, bas_len_w);
fprintf(stderr, "sea_pos = %d, sea_buf_len = %d, sea_len = %d\r\n", sea_pos_w, sea_buf_len_w, sea_len_w);
fprintf(stderr, "u3qe_git_pack_expand_delta_object: base (pos = %d) object size mismatch!\r\n", base_data_pos);

// u3_assert(false);
// _free();
return u3_none;
Expand Down Expand Up @@ -335,11 +334,9 @@ u3_noun u3qe_git_pack_expand_delta_object(u3_noun base,
return u3_none;
}

u3_noun data = u3nc(0, u3nc(u3i_chub(siz_w), u3i_slab_mint(&sab_u)));
u3_noun data = u3nc(u3i_chub(siz_w), u3i_slab_mint(&sab_u));
u3_noun rob = u3nt(u3k(base_type), u3i_chub(siz_w), data);

// fprintf(stderr, "Resolved object of size %d, siz_w = %d\r\n", base_size, siz_w);

return rob;
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/noun/jets/e/git_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ static c3_y _to_hex_dit(c3_w byt)
}

u3_noun u3qe_git_http_read_pkt_lines_on_band(
u3_noun sea,
u3_atom band){
u3_atom band,
u3_noun sea) {

if (c3n == u3a_is_cat(band)) {
u3m_bail(c3__fail);
Expand Down Expand Up @@ -165,9 +165,9 @@ u3_noun u3qe_git_http_read_pkt_lines_on_band(
sea_y += pkt_len_w;
pos_w += pkt_len_w;
}
fprintf(stderr, "Assembled %d bytes\r\n", total_w);
u3_noun octs_red = u3nc(u3i_word(total_w), u3i_slab_mint(&sab_u));

return u3nc(u3nc(u3i_word(0), octs_red), u3k(sea));
return u3nc(octs_red, u3k(sea));
}
u3_noun u3we_git_http_read_pkt_lines_on_band(u3_noun cor) {

Expand Down Expand Up @@ -280,8 +280,8 @@ u3_noun u3we_git_http_write_pkt_lines_on_band(u3_noun cor) {
u3_noun sea;
u3_atom band;

u3x_mean(cor, u3x_sam_2, &sea,
u3x_sam_3, &band, 0);
u3x_mean(cor, u3x_sam_2, &band,
u3x_sam_3, &sea, 0);

return u3qe_git_http_write_pkt_lines_on_band(sea, band);
return u3qe_git_http_write_pkt_lines_on_band(band, sea);
}
27 changes: 18 additions & 9 deletions pkg/noun/jets/e/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@

#define OUTBUF_SZ 4096

u3_noun u3qe_zlib_expand(u3_atom pos, u3_noun byts) {
u3_noun u3qe_zlib_expand(u3_atom pos, u3_atom oft, u3_noun octs) {

c3_d pos_d;
c3_d oft_d;
c3_d wid_d;

u3_atom wid;
u3_atom dat;

u3x_cell(byts, &wid, &dat);
u3x_cell(octs, &wid, &dat);

size_t sad_i = u3r_met(3, dat);

if (c3n == (u3r_safe_chub(pos, &pos_d))) {
return u3_none;
}
if (c3n == (u3r_safe_chub(oft, &oft_d))) {
return u3_none;
}
if (c3n == (u3r_safe_chub(wid, &wid_d))) {
return u3_none;
}
Expand All @@ -46,13 +50,14 @@ u3_noun u3qe_zlib_expand(u3_atom pos, u3_noun byts) {
z_stream zea;
c3_w zas_w;

zea.next_in = byt_y + pos_d;
zea.avail_in = (wid_d - pos_d);
zea.next_in = byt_y + oft_d + pos_d;
zea.avail_in = (wid_d - oft_d - pos_d);

zea.zalloc = Z_NULL;
zea.zfree = Z_NULL;
zea.opaque = Z_NULL;


/* Allocate output buffer
*/

Expand Down Expand Up @@ -95,6 +100,7 @@ u3_noun u3qe_zlib_expand(u3_atom pos, u3_noun byts) {
}
}


size_t len_i = sob_i - zea.avail_out;
pos_d += zea.total_in;

Expand All @@ -112,15 +118,18 @@ u3_noun u3qe_zlib_expand(u3_atom pos, u3_noun byts) {
u3_atom buf_a = u3i_slab_mint(&sab_u);

return u3nc(u3nc(len_a, buf_a),
u3nc(u3i_chub(pos_d), u3k(byts)));
u3nt(u3i_chub(pos_d), u3k(oft), u3k(octs)));
}

u3_noun u3we_zlib_expand(u3_noun sea) {
u3_noun u3we_zlib_expand(u3_noun cor) {

u3_atom pos;
u3_noun byts;
u3_atom oft;
u3_noun octs;

u3x_mean(sea, u3x_sam_2, &pos, u3x_sam_3, &byts, 0);
u3x_mean(cor, u3x_sam_2, &pos,
u3x_sam_6, &oft,
u3x_sam_7, &octs, 0);

return u3qe_zlib_expand(pos, byts);
return u3qe_zlib_expand(pos, oft, octs);
}
2 changes: 1 addition & 1 deletion pkg/noun/jets/q.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
u3_noun u3qe_json_de(u3_atom);
u3_atom u3qe_json_en(u3_noun);

u3_noun u3qe_zlib_expand(u3_atom, u3_noun);
u3_noun u3qe_zlib_expand(u3_atom, u3_atom, u3_noun);

u3_noun u3qe_stream_append_get_bytes(u3_atom n, u3_noun red, u3_noun sea);
u3_noun u3qe_stream_append_read_bytes(u3_atom n, u3_noun red, u3_noun sea);
Expand Down
105 changes: 50 additions & 55 deletions pkg/noun/jets/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2120,53 +2120,6 @@ static u3j_core _139_hex_json_d[] =
{}
};

/*
* Zlib
*/
static u3j_harm _139_hex_zlib_expand_a[] = {{".2", u3we_zlib_expand, c3y}, {}};
static u3j_core _139_hex_zlib_d[] =
{
{ "expand", 7, _139_hex_zlib_expand_a, 0, no_hashes },
{}
};

/*
* Stream library
*/
static u3j_harm _139_hex_stream_append_get_bytes_a[] =
{{".2", u3we_stream_append_get_bytes, c3y},{}};

static u3j_harm _139_hex_stream_append_read_bytes_a[] =
{{".2", u3we_stream_append_read_bytes, c3y},{}};

static u3j_core _139_hex_stream_d[] =
{
{ "append-get-bytes", 7, _139_hex_stream_append_get_bytes_a, 0, no_hashes },
{ "append-read-bytes", 7, _139_hex_stream_append_read_bytes_a, 0, no_hashes },
{}
};

/*
* Git HTTP protocol
*/
static u3j_harm _139_hex_git_http_read_pkt_lines_on_band_a[] =
{{".2", u3we_git_http_read_pkt_lines_on_band, c3y}, {}};
static u3j_harm _139_hex_git_http_write_pkt_lines_on_band_a[] =
{{".2", u3we_git_http_write_pkt_lines_on_band, c3y}, {}};

static u3j_core _139_hex_git_http_d[] =
{
{ "read-pkt-lines-on-band", 7, _139_hex_git_http_read_pkt_lines_on_band_a, 0, no_hashes},
{ "write-pkt-lines-on-band", 7, _139_hex_git_http_write_pkt_lines_on_band_a, 0, no_hashes},
{}
};

static u3j_harm _139_hex_git_pack_expand_delta_object_a[] =
{{".2", u3we_git_pack_expand_delta_object, c3y}, {}};

static u3j_core _139_hex_git_pack_d[] =
{{"expand-delta-object", 7, _139_hex_git_pack_expand_delta_object_a, c3y}, {}};

static u3j_core _139_hex_d[] =
{ { "lore", 63, _140_hex_lore_a, 0, no_hashes },
{ "leer", 63, _140_hex_leer_a, 0, no_hashes },
Expand All @@ -2185,10 +2138,6 @@ static u3j_core _139_hex_d[] =
{ "secp", 6, 0, _140_hex_secp_d, no_hashes },
{ "mimes", 31, 0, _140_hex_mimes_d, no_hashes },
{ "json", 31, 0, _139_hex_json_d, no_hashes },
{ "zlib", 31, 0, _139_hex_zlib_d, no_hashes},
{ "stream", 31, 0, _139_hex_stream_d, no_hashes},
{ "git-pack", 31, 0, _139_hex_git_pack_d, no_hashes},
{ "git-http", 31, 0, _139_hex_git_http_d, no_hashes},
{}
};

Expand Down Expand Up @@ -2391,6 +2340,52 @@ static u3j_core _138_hex_blake_d[] =
{ "blake3-impl", 7, 0, _138_hex_blake3_impl_d, no_hashes },
{}
};
/*
* Zlib
*/
static u3j_harm _138_hex_zlib_expand_a[] = {{".2", u3we_zlib_expand, c3y}, {}};
static u3j_core _138_hex_zlib_d[] =
{
{ "expand", 7, _138_hex_zlib_expand_a, 0, no_hashes },
{}
};

/*
* Stream library
*/
static u3j_harm _138_hex_stream_append_get_bytes_a[] =
{{".2", u3we_stream_append_get_bytes, c3y},{}};

static u3j_harm _138_hex_stream_append_read_bytes_a[] =
{{".2", u3we_stream_append_read_bytes, c3y},{}};

static u3j_core _138_hex_stream_d[] =
{
{ "append-get-bytes", 7, _138_hex_stream_append_get_bytes_a, 0, no_hashes },
{ "append-read-bytes", 7, _138_hex_stream_append_read_bytes_a, 0, no_hashes },
{}
};

/*
* Git HTTP protocol
*/
static u3j_harm _138_hex_git_http_read_pkt_lines_on_band_a[] =
{{".2", u3we_git_http_read_pkt_lines_on_band, c3y}, {}};
static u3j_harm _138_hex_git_http_write_pkt_lines_on_band_a[] =
{{".2", u3we_git_http_write_pkt_lines_on_band, c3y}, {}};

static u3j_core _138_hex_git_http_d[] =
{
{ "read-pkt-lines-on-band", 7, _138_hex_git_http_read_pkt_lines_on_band_a, 0, no_hashes},
{ "write-pkt-lines-on-band", 7, _138_hex_git_http_write_pkt_lines_on_band_a, 0, no_hashes},
{}
};

static u3j_harm _138_hex_git_pack_expand_delta_object_a[] =
{{".2", u3we_git_pack_expand_delta_object, c3y}, {}};

static u3j_core _138_hex_git_pack_d[] =
{{"expand-delta-object", 7, _138_hex_git_pack_expand_delta_object_a, c3y}, {}};

static u3j_core _138_hex_d[] =
{ { "lore", 63, _140_hex_lore_a, 0, no_hashes },
Expand All @@ -2411,10 +2406,10 @@ static u3j_core _138_hex_d[] =
{ "mimes", 31, 0, _140_hex_mimes_d, no_hashes },
{ "json", 31, 0, _139_hex_json_d, no_hashes },
/* Git jets */
{ "zlib", 31, 0, _139_hex_zlib_d, no_hashes},
{ "stream", 31, 0, _139_hex_stream_d, no_hashes},
{ "git-pack", 31, 0, _139_hex_git_pack_d, no_hashes},
{ "git-http", 31, 0, _139_hex_git_http_d, no_hashes},
{ "zlib", 31, 0, _138_hex_zlib_d, no_hashes},
{ "stream", 31, 0, _138_hex_stream_d, no_hashes},
{ "git-pack", 31, 0, _138_hex_git_pack_d, no_hashes},
{ "git-http", 31, 0, _138_hex_git_http_d, no_hashes},
{}
};

Expand Down

0 comments on commit 47b2710

Please sign in to comment.