gitoxide icon indicating copy to clipboard operation
gitoxide copied to clipboard

Mergebase support

Open kalkin opened this issue 3 years ago • 0 comments

Should provide:

  • [ ] Given two commits a & b check if b is ancestor of a
  • [x] Given n commits, find the first common ancestor
  • [x] Given n commits, find their LCA
  • [ ] the equivalent of merge-base --independent (boils down to remove_redundant())

TODO

  • [ ] assure commit-graphs aren't used if grafts are present (like in shallow clones), or if object-replacements are active.

Open Questions:

  • How should the api look? Something like this?
    impl Commit {
        fn is_descendant(list: Vec<Id>) -> bool;
    }
    impl Repository {
        /// Return the first found common ancestor
        fn merge_base_first(one: Id, twos: Vec<Id>) -> Result<Option<Id>, Error>;
        /// Return the first least common ancestor
        fn merge_base(one: Id, twos: Vec<Id>) -> Result<Vec<Id>, Error>;
    }

Further reading:

  • https://github.com/git/git/blob/142430338477d9d1bb25be66267225fb58498d92/commit-reach.c#L434=
  • https://devblogs.microsoft.com/devops/supercharging-the-git-commit-graph-iii-generations/
  • https://web.archive.org/web/20190914030055/http://www.gghh.name:80/dibtp/2014/02/25/how-does-mercurial-select-the-greatest-common-ancestor.html
  • https://web.archive.org/web/20160730054028/https://selenic.com/hg/rev/2f7186400a07

kalkin avatar May 12 '22 11:05 kalkin