╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issue.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
287 // absent when both sides created the issue independently 288 var base_description: []const u8 = ""; 289 if (try entry.getCursor(hash.hashInt(repo_opts.hash, evt.base_record_key))) |base_cursor| { 290 const base = try evt.read(Record, DB, repo_opts.hash, arena, try DB.HashMap(.read_only).init(base_cursor)); 291 base_description = base.event.description; 292 } 293 294 const chunks = try diff3.chunks(io, allocator, arena, base_description, live.event.description, theirs.event.description); 295 var resolutions: std.ArrayList([]const u8) = .empty; 296 var hunk_index: usize = 0; 297 for (chunks) |chunk| { 298 if (chunk != .conflict) continue; 299 try resolutions.append(aa, if (hunk_index < resolve.hunks.len) resolve.hunks[hunk_index] else (chunk.conflict.ours orelse "")); 300 hunk_index += 1; 301 } 302 updated.description = try diff3.assemble(aa, chunks, resolutions.items); 303 return updated; 304 } 305 306 // the issue `id_bytes` names in the repo's consumed event db (the repo's own 307 // db for xit; the side db next to a git repo), or null 308 fn readById( 309 comptime repo_kind: rp.RepoKind, 310 comptime repo_opts: rp.RepoOpts(repo_kind), 311 io: std.Io, 312 allocator: std.mem.Allocator, 313 arena: *std.heap.ArenaAllocator, 314 repo: *rp.Repo(repo_kind, repo_opts), 315 id_bytes: *const [evt.event_id_size]u8, 316 ) !?Record { 317 const DB = evt.EventDB(repo_opts.hash); 318 var event_db_maybe: ?evt.LocalEventDB(repo_opts.hash) = if (repo_kind == .git) try evt.LocalEventDB(repo_opts.hash).openReadOnly(io, allocator, repo.core.repo_dir) else null; 319 defer if (event_db_maybe) |*event_db| event_db.deinit(io, allocator); 320 const moment = (if (event_db_maybe) |*event_db| 321 evt.currentMomentFromDb(repo_opts.hash, event_db.db) 322 else if (repo_kind == .git) 323 return null 324 else 325 evt.currentMoment(repo_opts, repo)) catch return null; 326 const event_id_to_issue_cursor = (try moment.getCursor(hash.hashInt(repo_opts.hash, "event-id->issue"))) orelse return null; 327 const event_id_to_issue = try DB.HashMap(.read_only).init(event_id_to_issue_cursor); 328 const issue_cursor = (try event_id_to_issue.getCursor(hash.hashInt(repo_opts.hash, id_bytes))) orelse return null; 329 const issue_map = try DB.HashMap(.read_only).init(issue_cursor); 330 return try evt.read(Record, DB, repo_opts.hash, arena, issue_map); 331 } 332 333 // remove an issue's order key from its tags' `status` sets, pruning entries 334 // whose set becomes empty 335 fn removeFromTagSets( 336 comptime DB: type, 337 tag_to_issues: DB.SortedMap(.read_write), 338 tags: []const u8, 339 status: Status, 340 order_key: []const u8, 341 ) !void { 342 var tag_iter = tagIterator(tags); 343 while (tag_iter.next()) |tag| { 344 // skipped the same way consume skipped it, so it was never indexed 345 if (tag.len == 0 or tag.len > tag_max_len) continue; 346 var key_buffer: TagStatusKey = undefined; 347 const key = try tagStatusKey(&key_buffer, tag, status); 348 const tag_set_cursor = try tag_to_issues.putCursor(key); 349 const tag_set = try DB.SortedSet(.read_write).init(tag_set_cursor); 350 _ = try tag_set.remove(order_key); 351 if (0 == try tag_set.count()) _ = try tag_to_issues.remove(key); 352 } 353 } 354