GitRoot

craft your forge, build your project, grow your community freely
  1// SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
  2//
  3// SPDX-License-Identifier: MIT
  4
  5import { Date } from "date";
  6import { __server, Commit } from "./server";
  7
  8export function init(
  9  repoNamePtr: i32,
 10  repoNameSize: i32,
 11  confHasChangedPtr: i32,
 12  confHasChangedSize: i32,
 13  confPtr: i32,
 14  confSize: i32
 15): void {
 16  const repoName = String.UTF8.decodeUnsafe(repoNamePtr, repoNameSize);
 17  const serializedConf = String.UTF8.decodeUnsafe(confPtr, confSize);
 18  const confHasChanged = String.UTF8.decodeUnsafe(
 19    confHasChangedPtr,
 20    confHasChangedSize
 21  );
 22  if (__server && __server!.plugin) {
 23    __server!.plugin!.init(repoName, confHasChanged == "true", serializedConf);
 24  }
 25}
 26
 27export function startCommit(
 28  branchPtr: i32,
 29  branchSize: i32,
 30  hashPrt: i32,
 31  hashSize: i32,
 32  msgPrt: i32,
 33  msgSize: i32,
 34  datePtr: i32,
 35  dateSize: i32,
 36  committerPtr: i32,
 37  committerSize: i32
 38): void {
 39  if (__server && __server!.plugin) {
 40    const branch = String.UTF8.decodeUnsafe(branchPtr, branchSize);
 41    const hash = String.UTF8.decodeUnsafe(hashPrt, hashSize);
 42    const msg = String.UTF8.decodeUnsafe(msgPrt, msgSize);
 43    const date = String.UTF8.decodeUnsafe(datePtr, dateSize);
 44    const committer = String.UTF8.decodeUnsafe(committerPtr, committerSize);
 45    const commit = Commit.build(
 46      branch,
 47      hash,
 48      msg,
 49      Date.fromString(date),
 50      committer
 51    );
 52    __server!.plugin!.startCommit(commit);
 53  }
 54}
 55
 56export function addFile(ptr: i32, size: i32): void {
 57  if (__server && __server!.plugin) {
 58    __server!.plugin!.addFile(String.UTF8.decodeUnsafe(ptr, size));
 59  }
 60}
 61
 62export function modFile(
 63  fromPtr: i32,
 64  fromSize: i32,
 65  toPtr: i32,
 66  toSize: i32
 67): void {
 68  if (__server && __server!.plugin) {
 69    __server!.plugin!.modFile(
 70      String.UTF8.decodeUnsafe(fromPtr, fromSize),
 71      String.UTF8.decodeUnsafe(toPtr, toSize)
 72    );
 73  }
 74}
 75
 76export function delFile(ptr: i32, size: i32): void {
 77  if (__server && __server!.plugin) {
 78    __server!.plugin!.delFile(String.UTF8.decodeUnsafe(ptr, size));
 79  }
 80}
 81
 82export function endCommit(
 83  branchPtr: i32,
 84  branchSize: i32,
 85  hashPrt: i32,
 86  hashSize: i32,
 87  msgPrt: i32,
 88  msgSize: i32,
 89  datePtr: i32,
 90  dateSize: i32,
 91  committerPtr: i32,
 92  committerSize: i32
 93): void {
 94  if (__server && __server!.plugin) {
 95    const branch = String.UTF8.decodeUnsafe(branchPtr, branchSize);
 96    const hash = String.UTF8.decodeUnsafe(hashPrt, hashSize);
 97    const msg = String.UTF8.decodeUnsafe(msgPrt, msgSize);
 98    const date = String.UTF8.decodeUnsafe(datePtr, dateSize);
 99    const committer = String.UTF8.decodeUnsafe(committerPtr, committerSize);
100    const commit = Commit.build(
101      branch,
102      hash,
103      msg,
104      Date.fromString(date),
105      committer
106    );
107    __server!.plugin!.endCommit(commit);
108  }
109}
110
111export function finish(): void {
112  if (__server && __server!.plugin) {
113    __server!.plugin!.finish();
114  }
115}
116
117export function defaultRun(): string {
118  if (__server) {
119    return __server!.run;
120  }
121  return "[]";
122}
123
124export function malloc(size: usize): usize {
125  const ptr = __new(size, 1);
126  __pin(ptr);
127  return ptr;
128}
129
130export function free(ptr: usize): void {
131  __unpin(ptr);
132}