╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ patch.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
396 .tree_entries = &tree_entries, 397 .event = .{ .patchrev = revision.event }, 398 }; 399 event_count += 1; 400 } else { 401 const existing = current_revision orelse unreachable; 402 if (!selected.matches(existing)) return error.InvalidPatch; 403 } 404 405 var patch = patch_record.event; 406 patch.status = .{ .merged = merged_oid }; 407 events[event_count] = .{ 408 .id = std.fmt.bytesToHex(patch_id.*, .lower), 409 .timestamp = if (merged_author != null) merged_timestamp else @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 410 .author = merged_author orelse original_author, 411 .event = .{ .patch = patch }, 412 }; 413 event_count += 1; 414 415 try evt.commitEvents(.xit, repo_opts, state, io, allocator, evt.events_ref, events[0..event_count], null); 416 if (!try evt.consumeInTransaction(.repo, .xit, repo_opts, state, db, moment, io, allocator, evt.events_ref)) return error.CancelTransaction; 417 return true; 418 } 419 420 // find patches merged by commits received in a push 421 pub fn detectMerged( 422 comptime repo_opts: rp.RepoOpts(.xit), 423 state: rp.Repo(.xit, repo_opts).State(.read_write), 424 db: *evt.EventDB(repo_opts.hash), 425 moment: *evt.EventDB(repo_opts.hash).HashMap(.read_write), 426 io: std.Io, 427 allocator: std.mem.Allocator, 428 repo_root_path: []const u8, 429 updates: []const xit.net_server_receive_pack.AppliedRefUpdate, 430 error_writer: *std.Io.Writer, 431 ) !void { 432 const DB = evt.EventDB(repo_opts.hash); 433 var arena = std.heap.ArenaAllocator.init(allocator); 434 defer arena.deinit(); 435 436 const haxy_moment = try evt.currentMomentFromRepoMoment(repo_opts.hash, moment.readOnly()); 437 const revisions_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Patch.revision_to_id_set_key)) orelse return; 438 const revisions = try DB.HashMap(.read_only).init(revisions_cursor); 439 var events_ref_buffer: [rf.MAX_REF_CONTENT_SIZE]u8 = undefined; 440 const events_ref_path = try evt.events_ref.toPath(&events_ref_buffer); 441 const heads_prefix = "refs/heads/"; 442 for (updates) |update| { 443 if (!std.mem.startsWith(u8, update.ref_name, heads_prefix) or 444 std.mem.eql(u8, update.ref_name, events_ref_path) or 445 std.mem.eql(u8, update.old_oid, update.new_oid)) continue; 446 if (update.old_oid.len != hash.hexLen(repo_opts.hash) or 447 update.new_oid.len != hash.hexLen(repo_opts.hash)) return error.InvalidOid; 448 var old_oid: [hash.hexLen(repo_opts.hash)]u8 = undefined; 449 var new_oid: [hash.hexLen(repo_opts.hash)]u8 = undefined; 450 @memcpy(&old_oid, update.old_oid); 451 @memcpy(&new_oid, update.new_oid); 452 if (std.mem.allEqual(u8, &new_oid, '0')) continue; 453 454 var commits = try obj.ObjectIterator(.xit, repo_opts).init(state.readOnly(), io, arena.allocator(), .{ .kind = .commit }); 455 defer commits.deinit(); 456 if (!std.mem.allEqual(u8, &old_oid, '0')) try commits.exclude(&old_oid); 457 try commits.include(&new_oid); 458 var revision_key_buffer: [rf.MAX_REF_CONTENT_SIZE + 1 + hash.hexLen(repo_opts.hash)]u8 = undefined; 459 while (try commits.next(arena.allocator())) |commit| { 460 defer commit.deinit(); 461 const key = try std.fmt.bufPrint(&revision_key_buffer, "{s}\x00{s}", .{ update.ref_name[heads_prefix.len..], &commit.oid }); 462 const ids_cursor = try revisions.getCursor(hash.hashInt(repo_opts.hash, key)) orelse continue; 463 const ids = try DB.CountedHashSet(.read_only).init(ids_cursor); 464 var ids_iter = try ids.iterator(); 465 while (try ids_iter.next()) |cursor| { 466 const pair = try cursor.readKeyValuePair(); 467 var patch_id: [evt.event_id_size]u8 = undefined; 468 if ((try pair.key_cursor.readBytes(&patch_id)).len != patch_id.len) return error.InvalidPatch; 469 const patch_hex = std.fmt.bytesToHex(patch_id, .lower); 470 importMerged(repo_opts, state, db, moment, io, allocator, repo_root_path, &patch_id, &commit.oid) catch |err| { 471 serve_common.logError(io, error_writer, "failed to mark patch {s} as merged: {s}\n", .{ &patch_hex, @errorName(err) }); 472 continue; 473 }; 474 } 475 } 476 } 477 } 478