Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/context.py @ 19669:8120ea4b87f5
commitablectx: move _buildflagfunc from workingctx
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Wed, 14 Aug 2013 15:29:48 -0500 |
parents | 9d56a3359011 |
children | 6ac735fbea50 |
comparison
equal
deleted
inserted
replaced
19668:9d56a3359011 | 19669:8120ea4b87f5 |
---|---|
863 return True | 863 return True |
864 | 864 |
865 def __contains__(self, key): | 865 def __contains__(self, key): |
866 return self._repo.dirstate[key] not in "?r" | 866 return self._repo.dirstate[key] not in "?r" |
867 | 867 |
868 def _buildflagfunc(self): | |
869 # Create a fallback function for getting file flags when the | |
870 # filesystem doesn't support them | |
871 | |
872 copiesget = self._repo.dirstate.copies().get | |
873 | |
874 if len(self._parents) < 2: | |
875 # when we have one parent, it's easy: copy from parent | |
876 man = self._parents[0].manifest() | |
877 def func(f): | |
878 f = copiesget(f, f) | |
879 return man.flags(f) | |
880 else: | |
881 # merges are tricky: we try to reconstruct the unstored | |
882 # result from the merge (issue1802) | |
883 p1, p2 = self._parents | |
884 pa = p1.ancestor(p2) | |
885 m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() | |
886 | |
887 def func(f): | |
888 f = copiesget(f, f) # may be wrong for merges with copies | |
889 fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) | |
890 if fl1 == fl2: | |
891 return fl1 | |
892 if fl1 == fla: | |
893 return fl2 | |
894 if fl2 == fla: | |
895 return fl1 | |
896 return '' # punt for conflicts | |
897 | |
898 return func | |
899 | |
868 class workingctx(commitablectx): | 900 class workingctx(commitablectx): |
869 """A workingctx object makes access to data related to | 901 """A workingctx object makes access to data related to |
870 the current working directory convenient. | 902 the current working directory convenient. |
871 date - any valid date string or (unixtime, offset), or None. | 903 date - any valid date string or (unixtime, offset), or None. |
872 user - username string, or None. | 904 user - username string, or None. |
875 or None to use the repository status. | 907 or None to use the repository status. |
876 """ | 908 """ |
877 def __init__(self, repo, text="", user=None, date=None, extra=None, | 909 def __init__(self, repo, text="", user=None, date=None, extra=None, |
878 changes=None): | 910 changes=None): |
879 super(workingctx, self).__init__(repo, text, user, date, extra, changes) | 911 super(workingctx, self).__init__(repo, text, user, date, extra, changes) |
880 | |
881 def _buildflagfunc(self): | |
882 # Create a fallback function for getting file flags when the | |
883 # filesystem doesn't support them | |
884 | |
885 copiesget = self._repo.dirstate.copies().get | |
886 | |
887 if len(self._parents) < 2: | |
888 # when we have one parent, it's easy: copy from parent | |
889 man = self._parents[0].manifest() | |
890 def func(f): | |
891 f = copiesget(f, f) | |
892 return man.flags(f) | |
893 else: | |
894 # merges are tricky: we try to reconstruct the unstored | |
895 # result from the merge (issue1802) | |
896 p1, p2 = self._parents | |
897 pa = p1.ancestor(p2) | |
898 m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() | |
899 | |
900 def func(f): | |
901 f = copiesget(f, f) # may be wrong for merges with copies | |
902 fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) | |
903 if fl1 == fl2: | |
904 return fl1 | |
905 if fl1 == fla: | |
906 return fl2 | |
907 if fl2 == fla: | |
908 return fl1 | |
909 return '' # punt for conflicts | |
910 | |
911 return func | |
912 | 912 |
913 @propertycache | 913 @propertycache |
914 def _flagfunc(self): | 914 def _flagfunc(self): |
915 return self._repo.dirstate.flagfunc(self._buildflagfunc) | 915 return self._repo.dirstate.flagfunc(self._buildflagfunc) |
916 | 916 |