navid/veins / commit

31d8486273aa

Navid M <navidmomtahen@gmail.com> · 2026-11-26

parents: 061a2e5987e8

Browse files at this commit · Download source

all: fixes to graph
--- a/src/src/cli/log_cmd.sx+++ b/src/src/cli/log_cmd.sx@@ -25,6 +25,7 @@     message: mut bytes.Bytes     author: mut bytes.Bytes     conflicted: mut bool+    has_changes: mut bool }  fn new_rec(@@ -43,6 +44,7 @@     r.message = bytes.Bytes.dup(message)     r.author = bytes.Bytes.dup(author)     r.conflicted = false+    r.has_changes = false     return r } @@ -217,6 +219,9 @@                     lc.c.author.name                 )                 rec.conflicted = treewalk.conflicted(st.handles, lc.c.root_tree)+                if objid.Id.eql(id, wc) {+                    rec.has_changes = graph.has_changes(st.handles, lc)+                }                 changeid.free(cid_full)                 graph.free_loaded(lc)                 @append(recs, rec)@@ -260,8 +265,13 @@     for i < @len(recs) {         val r: ref LogRec = rec_at(recs, i)         val marker: mut str.StringView = str.from_cstr(c" ")+        val marker_color: mut terminal.Color = terminal.Color.Default         if objid.Id.eql(r.id, wc) {             marker = str.from_cstr(c"@")+            marker_color = terminal.Color.Red+            if r.has_changes {+                marker_color = terminal.Color.BrightCyan+            }         }         val hex: ref u8 = objid.Id.hex(r.id)         val short: str.StringView = str.view(hex, 12)@@ -269,7 +279,7 @@         val stamp: bytes.Bytes = datetime.format_utc(r.seconds)         val msg_view = str.view(r.message.ptr, r.message.len as i64)         val author_view = str.view(r.author.ptr, r.author.len as i64)-        print_cell(marker, 1, terminal.Color.Default, false)+        print_cell(marker, 1, marker_color, false)         stdio.print(" ", {})         print_cell(short, w_commit, terminal.Color.Red, false)         print_gap()@@ -291,6 +301,8 @@         print_gap()         if msg_view.len > 0 {             terminal.print(msg_view, terminal.Color.Green)+        } else {+            terminal.print(str.from_cstr(c"<unset>"), terminal.Color.BrightBlack)         }         val names = viewops.bookmark_names(v, r.id)         for name in names {--- a/src/src/cli/new_cmd.sx+++ b/src/src/cli/new_cmd.sx@@ -10,8 +10,6 @@ val types     = use("../object/types.sx") val commit    = use("../object/commit.sx") val graph     = use("../object/graph.sx")-val tree      = use("../object/tree.sx")-val treewalk  = use("../object/treewalk.sx") val store     = use("../store/store.sx") val layout    = use("../store/layout.sx") val txn       = use("../store/txn.sx")@@ -27,38 +25,6 @@     val out: ref u8 = @alloc(32) as ref u8     @memcpy(out as ref void, id.ptr as ref void, 32)     return objid.id(out)-}--fn wc_has_changes(handles: list[ref store.Handle], lc: ref graph.LoadedCommit) bool = trust {-    if @len(lc.c.parents) > 0 {-        val p = @get(lc.c.parents, 0)-        val pid: mut objid.Id = objid.id_none()-        if p is some x {-            pid = x-        }-        val pl_opt = graph.load_commit(handles, pid)-        val changed: mut bool = true-        match pl_opt {-            some parent => {-                changed = !objid.Id.eql(parent.c.root_tree, lc.c.root_tree)-                graph.free_loaded(parent)-            }-            none => {-            }-        }-        return changed-    }-    val t_opt = treewalk.read_tree(handles, lc.c.root_tree)-    val changed: mut bool = true-    match t_opt {-        some t => {-            changed = @len(t.entries) > 0-            tree.free_tree(t)-        }-        none => {-        }-    }-    return changed }  fn copy_renames(rs: list[ref commit.Rename]) list[ref commit.Rename] = trust {@@ -186,7 +152,7 @@         none => {         }     }-    val changed: bool = wc_has_changes(st.handles, lc)+    val changed: bool = graph.has_changes(st.handles, lc)     val same_message: bool = bytes.Bytes.eql(message, lc.c.message)     if !changed && (require_changes || same_message) {         if require_changes {--- a/src/src/object/graph.sx+++ b/src/src/object/graph.sx@@ -5,6 +5,8 @@ val objid     = use("../object/id.sx") val types     = use("../object/types.sx") val commit    = use("../object/commit.sx")+val tree      = use("../object/tree.sx")+val treewalk  = use("../object/treewalk.sx") val view      = use("../object/view.sx") val changeid  = use("changeid.sx") val state     = use("../store/state.sx")@@ -102,6 +104,39 @@     commit.free_commit(lc.c)     files.free_buffer(lc.body)     @free(lc as ref void)+}++/// True when the commit's tree differs from its first parent's tree.+pub fn has_changes(handles: list[ref store.Handle], lc: ref LoadedCommit) bool = trust {+    if @len(lc.c.parents) > 0 {+        val p = @get(lc.c.parents, 0)+        val pid: mut objid.Id = objid.id_none()+        if p is some x {+            pid = x+        }+        val pl_opt = load_commit(handles, pid)+        val changed: mut bool = true+        match pl_opt {+            some parent => {+                changed = !objid.Id.eql(parent.c.root_tree, lc.c.root_tree)+                free_loaded(parent)+            }+            none => {+            }+        }+        return changed+    }+    val t_opt = treewalk.read_tree(handles, lc.c.root_tree)+    val changed: mut bool = true+    match t_opt {+        some t => {+            changed = @len(t.entries) > 0+            tree.free_tree(t)+        }+        none => {+        }+    }+    return changed }  /// Collect all commits reachable from `start`.