726 # (The cache warming setup by localrepo will update the file later.) |
726 # (The cache warming setup by localrepo will update the file later.) |
727 self.write(repo) |
727 self.write(repo) |
728 |
728 |
729 |
729 |
730 def branch_cache_from_file(repo) -> Optional[_LocalBranchCache]: |
730 def branch_cache_from_file(repo) -> Optional[_LocalBranchCache]: |
731 """Build a branch cache from on-disk data if possible""" |
731 """Build a branch cache from on-disk data if possible |
732 return BranchCacheV2.fromfile(repo) |
732 |
|
733 Return a branch cache of the right format depending of the repository. |
|
734 """ |
|
735 if repo.ui.configbool(b"experimental", b"branch-cache-v3"): |
|
736 return BranchCacheV3.fromfile(repo) |
|
737 else: |
|
738 return BranchCacheV2.fromfile(repo) |
733 |
739 |
734 |
740 |
735 def new_branch_cache(repo, *args, **kwargs): |
741 def new_branch_cache(repo, *args, **kwargs): |
736 """Build a new branch cache from argument""" |
742 """Build a new branch cache from argument |
737 return BranchCacheV2(repo, *args, **kwargs) |
743 |
|
744 Return a branch cache of the right format depending of the repository. |
|
745 """ |
|
746 if repo.ui.configbool(b"experimental", b"branch-cache-v3"): |
|
747 return BranchCacheV3(repo, *args, **kwargs) |
|
748 else: |
|
749 return BranchCacheV2(repo, *args, **kwargs) |
738 |
750 |
739 |
751 |
740 class BranchCacheV2(_LocalBranchCache): |
752 class BranchCacheV2(_LocalBranchCache): |
741 """a branch cache using version 2 of the format on disk |
753 """a branch cache using version 2 of the format on disk |
742 |
754 |
755 This field can be used to avoid changelog reads when determining if a |
767 This field can be used to avoid changelog reads when determining if a |
756 branch head closes a branch or not. |
768 branch head closes a branch or not. |
757 """ |
769 """ |
758 |
770 |
759 _base_filename = b"branch2" |
771 _base_filename = b"branch2" |
|
772 |
|
773 |
|
774 class BranchCacheV3(_LocalBranchCache): |
|
775 """a branch cache using version 3 of the format on disk |
|
776 |
|
777 This version is still EXPERIMENTAL and the format is subject to changes. |
|
778 |
|
779 The cache is serialized on disk in the following format: |
|
780 |
|
781 <tip hex node> <tip rev number> [optional filtered repo hex hash] |
|
782 <branch head hex node> <open/closed state> <branch name> |
|
783 <branch head hex node> <open/closed state> <branch name> |
|
784 ... |
|
785 |
|
786 The first line is used to check if the cache is still valid. If the |
|
787 branch cache is for a filtered repo view, an optional third hash is |
|
788 included that hashes the hashes of all filtered and obsolete revisions. |
|
789 |
|
790 The open/closed state is represented by a single letter 'o' or 'c'. |
|
791 This field can be used to avoid changelog reads when determining if a |
|
792 branch head closes a branch or not. |
|
793 """ |
|
794 |
|
795 _base_filename = b"branch3" |
760 |
796 |
761 |
797 |
762 class remotebranchcache(_BaseBranchCache): |
798 class remotebranchcache(_BaseBranchCache): |
763 """Branchmap info for a remote connection, should not write locally""" |
799 """Branchmap info for a remote connection, should not write locally""" |
764 |
800 |