Select the types of activity you want to include in your feed.
chore: apply dune fmt and use Alcotest.failf (E616)
Replace Alcotest.fail (Fmt.str ...) with Alcotest.failf in test_huri. Apply dune fmt formatting across precommit, requests, qemu, and publicsuffix packages.
···354354 let committer_email = Git.User.email (Git.Commit.committer commit) in
355355 String.equal email committer_email
356356357357+let scan_commits_for_ai_attribution repo commits user_email =
358358+ let found = ref 0 in
359359+ let skipped_email = ref 0 in
360360+ let skipped_no_ai = ref 0 in
361361+ let result =
362362+ List.filter_map
363363+ (fun (info : Git.Rev_list.commit_info) ->
364364+ match Git.Repository.read repo info.hash with
365365+ | Ok (Git.Value.Commit c) ->
366366+ if not (is_my_commit ~user_email c) then begin
367367+ incr skipped_email;
368368+ None
369369+ end
370370+ else
371371+ let msg = Git.Commit.message c in
372372+ let has_ai =
373373+ match msg with
374374+ | Some m -> message_has_ai_attribution m
375375+ | None -> false
376376+ in
377377+ if has_ai then begin
378378+ incr found;
379379+ let hash = String.sub (Git.Hash.to_hex info.hash) 0 7 in
380380+ let subject =
381381+ match msg with
382382+ | Some m -> (
383383+ match String.split_on_char '\n' m with
384384+ | subj :: _ -> String.trim subj
385385+ | [] -> "")
386386+ | None -> ""
387387+ in
388388+ Some { hash; subject }
389389+ end
390390+ else begin
391391+ incr skipped_no_ai;
392392+ None
393393+ end
394394+ | _ -> None)
395395+ commits
396396+ in
397397+ Log.debug (fun m ->
398398+ m "check_ai_attribution: found=%d skipped_email=%d skipped_no_ai=%d"
399399+ !found !skipped_email !skipped_no_ai);
400400+ result
401401+357402let check_ai_attribution ctx dir =
358403 Log.debug (fun m -> m "check_ai_attribution: dir=%s" dir);
359404 match git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with
···363408 []
364409 | Some git_root -> (
365410 Log.debug (fun m -> m "check_ai_attribution: git_root=%s" git_root);
366366- (* Use full filesystem for absolute paths *)
367411 let repo = Git.Repository.open_repo ~fs:ctx.fs (Fpath.v git_root) in
368412 let user_email = user_email ~fs:ctx.fs repo in
369413 Log.debug (fun m ->
···376420 | Some head_hash ->
377421 Log.debug (fun m ->
378422 m "check_ai_attribution: HEAD=%s" (Git.Hash.to_hex head_hash));
379379- (* Get all commits from HEAD *)
380423 let commits =
381424 match
382425 Git.Rev_list.topo_sort_reverse repo head_hash ~stop:(fun _ ->
···390433 Log.debug (fun m -> m "check_ai_attribution: error %s" e);
391434 []
392435 in
393393- (* Find commits with AI attribution in message, only from current user *)
394394- let found = ref 0 in
395395- let skipped_email = ref 0 in
396396- let skipped_no_ai = ref 0 in
397397- let result =
398398- List.filter_map
399399- (fun (info : Git.Rev_list.commit_info) ->
400400- match Git.Repository.read repo info.hash with
401401- | Ok (Git.Value.Commit c) ->
402402- if not (is_my_commit ~user_email c) then begin
403403- incr skipped_email;
404404- None
405405- end
406406- else
407407- let msg = Git.Commit.message c in
408408- let has_ai =
409409- match msg with
410410- | Some m -> message_has_ai_attribution m
411411- | None -> false
412412- in
413413- if has_ai then begin
414414- incr found;
415415- let hash = String.sub (Git.Hash.to_hex info.hash) 0 7 in
416416- let subject =
417417- match msg with
418418- | Some m -> (
419419- match String.split_on_char '\n' m with
420420- | subj :: _ -> String.trim subj
421421- | [] -> "")
422422- | None -> ""
423423- in
424424- Some { hash; subject }
425425- end
426426- else begin
427427- incr skipped_no_ai;
428428- None
429429- end
430430- | _ -> None)
431431- commits
432432- in
433433- Log.debug (fun m ->
434434- m
435435- "check_ai_attribution: found=%d skipped_email=%d \
436436- skipped_no_ai=%d"
437437- !found !skipped_email !skipped_no_ai);
438438- result)
436436+ scan_commits_for_ai_attribution repo commits user_email)
439437440438let current_branch ctx dir =
441439 match git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with
···467465 | None -> ());
468466 backup_name
469467468468+let mark_commits_needing_rewrite repo commits user_email =
469469+ let needs_rewrite = Hashtbl.create 64 in
470470+ List.iter
471471+ (fun (info : Git.Rev_list.commit_info) ->
472472+ match Git.Repository.read repo info.hash with
473473+ | Ok (Git.Value.Commit c) when is_my_commit ~user_email c -> (
474474+ match Git.Commit.message c with
475475+ | Some msg when message_has_ai_attribution msg ->
476476+ Hashtbl.add needs_rewrite info.hash true
477477+ | _ -> ())
478478+ | _ -> ())
479479+ commits;
480480+ needs_rewrite
481481+482482+let rewrite_commit_history repo commits hash_map =
483483+ List.iter
484484+ (fun (info : Git.Rev_list.commit_info) ->
485485+ match Git.Repository.read repo info.hash with
486486+ | Ok (Git.Value.Commit c) ->
487487+ let new_parents =
488488+ List.map
489489+ (fun p ->
490490+ match Hashtbl.find_opt hash_map p with
491491+ | Some new_p -> new_p
492492+ | None -> p)
493493+ (Git.Commit.parents c)
494494+ in
495495+ let parents_changed =
496496+ not (List.equal Git.Hash.equal new_parents (Git.Commit.parents c))
497497+ in
498498+ let msg = Git.Commit.message c in
499499+ let needs_msg_rewrite =
500500+ match msg with
501501+ | Some m -> message_has_ai_attribution m
502502+ | None -> false
503503+ in
504504+ if parents_changed || needs_msg_rewrite then begin
505505+ let new_msg =
506506+ match msg with Some m -> Some (filter_message m) | None -> None
507507+ in
508508+ let new_commit =
509509+ Git.Commit.v ~tree:(Git.Commit.tree c)
510510+ ~author:(Git.Commit.author c)
511511+ ~committer:(Git.Commit.committer c) ~parents:new_parents
512512+ ~extra:(Git.Commit.extra c) new_msg
513513+ in
514514+ let new_hash = Git.Repository.write_commit repo new_commit in
515515+ Hashtbl.add hash_map info.hash new_hash
516516+ end
517517+ | _ -> ())
518518+ commits
519519+470520let rewrite_ai_attribution ctx dir =
471521 match git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with
472522 | None -> err_no_git_dir dir
···476526 match Git.Repository.head repo with
477527 | None -> Ok 0
478528 | Some head_hash ->
479479- (* Get all commits from HEAD in topological order (oldest first) *)
480529 let commits =
481530 match
482531 Git.Rev_list.topo_sort_reverse repo head_hash ~stop:(fun _ ->
···485534 | Ok cs -> cs
486535 | Error _ -> []
487536 in
488488- (* Find which commits need rewriting (only from current user) *)
489489- let needs_rewrite = Hashtbl.create 64 in
490490- List.iter
491491- (fun (info : Git.Rev_list.commit_info) ->
492492- match Git.Repository.read repo info.hash with
493493- | Ok (Git.Value.Commit c) when is_my_commit ~user_email c -> (
494494- match Git.Commit.message c with
495495- | Some msg when message_has_ai_attribution msg ->
496496- Hashtbl.add needs_rewrite info.hash true
497497- | _ -> ())
498498- | _ -> ())
499499- commits;
537537+ let needs_rewrite =
538538+ mark_commits_needing_rewrite repo commits user_email
539539+ in
500540 if Hashtbl.length needs_rewrite = 0 then Ok 0
501541 else
502502- (* Rewrite commits, building mapping of old -> new hashes *)
503542 let hash_map = Hashtbl.create 64 in
504504- List.iter
505505- (fun (info : Git.Rev_list.commit_info) ->
506506- match Git.Repository.read repo info.hash with
507507- | Ok (Git.Value.Commit c) ->
508508- (* Update parent references *)
509509- let new_parents =
510510- List.map
511511- (fun p ->
512512- match Hashtbl.find_opt hash_map p with
513513- | Some new_p -> new_p
514514- | None -> p)
515515- (Git.Commit.parents c)
516516- in
517517- let parents_changed =
518518- not
519519- (List.equal Git.Hash.equal new_parents
520520- (Git.Commit.parents c))
521521- in
522522- let msg = Git.Commit.message c in
523523- let needs_msg_rewrite =
524524- match msg with
525525- | Some m -> message_has_ai_attribution m
526526- | None -> false
527527- in
528528- if parents_changed || needs_msg_rewrite then begin
529529- let new_msg =
530530- match msg with
531531- | Some m -> Some (filter_message m)
532532- | None -> None
533533- in
534534- let new_commit =
535535- Git.Commit.v ~tree:(Git.Commit.tree c)
536536- ~author:(Git.Commit.author c)
537537- ~committer:(Git.Commit.committer c)
538538- ~parents:new_parents ~extra:(Git.Commit.extra c)
539539- new_msg
540540- in
541541- let new_hash =
542542- Git.Repository.write_commit repo new_commit
543543- in
544544- Hashtbl.add hash_map info.hash new_hash
545545- end
546546- | _ -> ())
547547- commits;
548548- (* Update HEAD to point to the new tip *)
543543+ rewrite_commit_history repo commits hash_map;
549544 (match Hashtbl.find_opt hash_map head_hash with
550545 | Some new_head -> Git.Repository.advance_head repo new_head
551546 | None -> ());