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