Mercurial > hg
comparison hgext/mq.py @ 19812:5d6cfdc38a3d
mq: simplifies the refresh hint in checklocalchanges
The `checklocalchanges` function in the `mq.queue` class takes a `refresh` argument that
changes the error message of raised exception. When refresh is
`True` the exception message is "local changes found, refresh first" otherwise,
the message is just "local changes found".
This changeset is the first of a series that extract `strip` into a standalone
extension (as discussed in issue3824). This `checklocalchanges` function is
indirectly used by the strip command. But in a standalone strip extension the
concept of "refresh first" has no sense. In practice, When used in the context
of the strip commands `refresh`'s value is always `False`.
So my final goal is a be able to extract the `checklocalchanges` logic in a
standalone extension but to keep the part related to "refresh first" in the mq
extension. However the refresh handling is deeply entangled into the
`checklocalchanges` code. It is handled as low a possible at the point we raise
the exception.
So we moves handling of refresh upper in the `checklocalchanges` code. This will
allow the extraction of a simple version in the strip extension while mq can
still inject its logic when needed.
Two helper functions `localchangesfound` and `localchangedsubreposfound` died in
the process they are replaced by simple raise lines.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Wed, 25 Sep 2013 12:28:40 +0200 |
parents | ea35caf324bb |
children | 76796fe65bad |
comparison
equal
deleted
inserted
replaced
19811:5e10d41e7b9c | 19812:5d6cfdc38a3d |
---|---|
972 elif substatestate in 'r': | 972 elif substatestate in 'r': |
973 changes[2].append('.hgsubstate') | 973 changes[2].append('.hgsubstate') |
974 else: # modified | 974 else: # modified |
975 changes[0].append('.hgsubstate') | 975 changes[0].append('.hgsubstate') |
976 | 976 |
977 def localchangesfound(self, refresh=True): | 977 def checklocalchanges(self, repo, force=False, refresh=True): |
978 excsuffix = '' | |
978 if refresh: | 979 if refresh: |
979 raise util.Abort(_("local changes found, refresh first")) | 980 excsuffix = ', refresh first' |
980 else: | 981 # plain versions for i18n tool to detect them |
981 raise util.Abort(_("local changes found")) | 982 _("local changes found, refresh first") |
982 | 983 _("local changed subrepos found, refresh first") |
983 def localchangedsubreposfound(self, refresh=True): | |
984 if refresh: | |
985 raise util.Abort(_("local changed subrepos found, refresh first")) | |
986 else: | |
987 raise util.Abort(_("local changed subrepos found")) | |
988 | |
989 def checklocalchanges(self, repo, force=False, refresh=True): | |
990 cmdutil.checkunfinished(repo) | 984 cmdutil.checkunfinished(repo) |
991 m, a, r, d = repo.status()[:4] | 985 m, a, r, d = repo.status()[:4] |
992 if not force: | 986 if not force: |
993 if (m or a or r or d): | 987 if (m or a or r or d): |
994 self.localchangesfound(refresh) | 988 _("local changes found") # i18n tool detection |
989 raise util.Abort(_("local changes found" + excsuffix)) | |
995 if self.checksubstate(repo): | 990 if self.checksubstate(repo): |
996 self.localchangedsubreposfound(refresh) | 991 _("local changed subrepos found") # i18n tool detection |
992 raise util.Abort(_("local changed subrepos found" + excsuffix)) | |
997 return m, a, r, d | 993 return m, a, r, d |
998 | 994 |
999 _reserved = ('series', 'status', 'guards', '.', '..') | 995 _reserved = ('series', 'status', 'guards', '.', '..') |
1000 def checkreservedname(self, name): | 996 def checkreservedname(self, name): |
1001 if name in self._reserved: | 997 if name in self._reserved: |
1447 if d: | 1443 if d: |
1448 raise util.Abort(_("deletions found between repo revs")) | 1444 raise util.Abort(_("deletions found between repo revs")) |
1449 | 1445 |
1450 tobackup = set(a + m + r) & tobackup | 1446 tobackup = set(a + m + r) & tobackup |
1451 if keepchanges and tobackup: | 1447 if keepchanges and tobackup: |
1452 self.localchangesfound() | 1448 raise util.Abort(_("local changes found, refresh first")) |
1453 self.backup(repo, tobackup) | 1449 self.backup(repo, tobackup) |
1454 | 1450 |
1455 for f in a: | 1451 for f in a: |
1456 util.unlinkpath(repo.wjoin(f), ignoremissing=True) | 1452 util.unlinkpath(repo.wjoin(f), ignoremissing=True) |
1457 repo.dirstate.drop(f) | 1453 repo.dirstate.drop(f) |