╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ patch.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
342 event_count += 1; 343 344 try evt.commitEvents(.xit, repo_opts, state, io, allocator, evt.events_ref, events[0..event_count], null); 345 if (!try evt.consumeInTransaction(.repo, .xit, repo_opts, state, db, moment, io, allocator, evt.events_ref)) return error.CancelTransaction; 346 return true; 347 } 348 349 // find patches merged by commits received in a push 350 pub fn detectMerged( 351 comptime repo_opts: rp.RepoOpts(.xit), 352 state: rp.Repo(.xit, repo_opts).State(.read_write), 353 db: *evt.EventDB(repo_opts.hash), 354 moment: *evt.EventDB(repo_opts.hash).HashMap(.read_write), 355 io: std.Io, 356 allocator: std.mem.Allocator, 357 repo_root_path: []const u8, 358 updates: []const xit.net_server_receive_pack.AppliedRefUpdate, 359 error_writer: *std.Io.Writer, 360 ) !void { 361 const DB = evt.EventDB(repo_opts.hash); 362 var arena = std.heap.ArenaAllocator.init(allocator); 363 defer arena.deinit(); 364 365 const haxy_moment = try evt.currentMomentFromRepoMoment(repo_opts.hash, moment.readOnly()); 366 const revisions_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Patch.revision_to_id_set_key)) orelse return; 367 const revisions = try DB.HashMap(.read_only).init(revisions_cursor); 368 var events_ref_buffer: [rf.MAX_REF_CONTENT_SIZE]u8 = undefined; 369 const events_ref_path = try evt.events_ref.toPath(&events_ref_buffer); 370 for (updates) |update| { 371 if (!std.mem.startsWith(u8, update.ref_name, "refs/heads/") or 372 std.mem.eql(u8, update.ref_name, events_ref_path) or 373 std.mem.eql(u8, update.old_oid, update.new_oid)) continue; 374 if (update.old_oid.len != hash.hexLen(repo_opts.hash) or 375 update.new_oid.len != hash.hexLen(repo_opts.hash)) return error.InvalidOid; 376 var old_oid: [hash.hexLen(repo_opts.hash)]u8 = undefined; 377 var new_oid: [hash.hexLen(repo_opts.hash)]u8 = undefined; 378 @memcpy(&old_oid, update.old_oid); 379 @memcpy(&new_oid, update.new_oid); 380 if (std.mem.allEqual(u8, &new_oid, '0')) continue; 381 382 var commits = try obj.ObjectIterator(.xit, repo_opts).init(state.readOnly(), io, arena.allocator(), .{ .kind = .commit }); 383 defer commits.deinit(); 384 if (!std.mem.allEqual(u8, &old_oid, '0')) try commits.exclude(&old_oid); 385 try commits.include(&new_oid); 386 var revision_key_buffer: [rf.MAX_REF_CONTENT_SIZE + 1 + hash.hexLen(repo_opts.hash)]u8 = undefined; 387 while (try commits.next(arena.allocator())) |commit| { 388 defer commit.deinit(); 389 const key = try std.fmt.bufPrint(&revision_key_buffer, "{s}\x00{s}", .{ update.ref_name, &commit.oid }); 390 const ids_cursor = try revisions.getCursor(hash.hashInt(repo_opts.hash, key)) orelse continue; 391 const ids = try DB.CountedHashSet(.read_only).init(ids_cursor); 392 var ids_iter = try ids.iterator(); 393 while (try ids_iter.next()) |cursor| { 394 const pair = try cursor.readKeyValuePair(); 395 var patch_id: [evt.event_id_size]u8 = undefined; 396 if ((try pair.key_cursor.readBytes(&patch_id)).len != patch_id.len) return error.InvalidPatch; 397 const patch_hex = std.fmt.bytesToHex(patch_id, .lower); 398 importMerged(repo_opts, state, db, moment, io, allocator, repo_root_path, &patch_id) catch |err| { 399 serve_common.logError(io, error_writer, "failed to mark patch {s} as merged: {s}\n", .{ &patch_hex, @errorName(err) }); 400 continue; 401 }; 402 } 403 } 404 } 405 } 406