╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ patch.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
941 @memcpy(&new_oid, update.new_oid); 942 if (std.mem.allEqual(u8, &new_oid, '0')) continue; 943 944 var commits = try obj.ObjectIterator(.xit, repo_opts).init(state.readOnly(), io, arena.allocator(), .{ .kind = .commit }); 945 defer commits.deinit(); 946 if (!std.mem.allEqual(u8, &old_oid, '0')) try commits.exclude(&old_oid); 947 var targets: std.ArrayList(struct { 948 before_oid: [hash.hexLen(repo_opts.hash)]u8, 949 after_oid: [hash.hexLen(repo_opts.hash)]u8, 950 }) = .empty; 951 { 952 var first_parents = try obj.ObjectIterator(.xit, repo_opts).init(state.readOnly(), io, arena.allocator(), .{ .kind = .commit, .first_parent = true }); 953 defer first_parents.deinit(); 954 if (!std.mem.allEqual(u8, &old_oid, '0')) try first_parents.exclude(&old_oid); 955 try first_parents.include(&new_oid); 956 while (try first_parents.next(arena.allocator())) |commit| { 957 defer commit.deinit(); 958 try targets.append(arena.allocator(), .{ 959 .before_oid = (commit.content.commit.metadata.firstParent() orelse &old_oid).*, 960 .after_oid = commit.oid, 961 }); 962 } 963 } 964 965 // visit target commits oldest first, attributing each revision to the 966 // commit that introduced it; the shared iterator visits each ancestor once 967 var revision_key_buffer: [rf.MAX_REF_CONTENT_SIZE + 1 + hash.hexLen(repo_opts.hash)]u8 = undefined; 968 while (targets.pop()) |target| { 969 try commits.include(&target.after_oid); 970 while (try commits.next(arena.allocator())) |commit| { 971 defer commit.deinit(); 972 const key = try std.fmt.bufPrint(&revision_key_buffer, "{s}\x00{s}", .{ update.ref_name[heads_prefix.len..], &commit.oid }); 973 const ids_cursor = try revisions.getCursor(hash.hashInt(repo_opts.hash, key)) orelse continue; 974 const ids = try DB.CountedHashSet(.read_only).init(ids_cursor); 975 var ids_iter = try ids.iterator(); 976 while (try ids_iter.next()) |cursor| { 977 const pair = try cursor.readKeyValuePair(); 978 var patch_id: [evt.event_id_size]u8 = undefined; 979 if ((try pair.key_cursor.readBytes(&patch_id)).len != patch_id.len) return error.InvalidPatch; 980 const patch_hex = std.fmt.bytesToHex(patch_id, .lower); 981 // a fast-forward has no recorded merge boundary; use the old ref tip 982 const before_oid = if (std.mem.eql(u8, &commit.oid, &target.after_oid)) &old_oid else &target.before_oid; 983 importMerged(repo_opts, state, db, moment, io, allocator, repo_root_path, &patch_id, &commit.oid, before_oid, &target.after_oid) catch |err| { 984 serve_common.logError(io, error_writer, "failed to mark patch {s} as merged: {s}\n", .{ &patch_hex, @errorName(err) }); 985 continue; 986 }; 987 } 988 } 989 } 990 } 991 } 992