comparison mercurial/localrepo.py @ 28813:d77b790bd8d6

localrepo: refactor commit argument check as checkcommitpatterns
author timeless <timeless@mozdev.org>
date Wed, 06 Apr 2016 17:52:17 +0000
parents ddc07ddcca94
children 1f65f291a5b7
comparison
equal deleted inserted replaced
28812:f1de5a612a74 28813:d77b790bd8d6
1475 elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): 1475 elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
1476 changelist.append(fname) 1476 changelist.append(fname)
1477 1477
1478 return fparent1 1478 return fparent1
1479 1479
1480 def checkcommitpatterns(self, wctx, vdirs, match, status, fail):
1481 """check for commit arguments that aren't commitable"""
1482 force = False
1483 if not force and (match.isexact() or match.prefix()):
1484 matched = set(status.modified + status.added + status.removed)
1485
1486 for f in match.files():
1487 f = self.dirstate.normalize(f)
1488 if f == '.' or f in matched or f in wctx.substate:
1489 continue
1490 if f in status.deleted:
1491 fail(f, _('file not found!'))
1492 if f in vdirs: # visited directory
1493 d = f + '/'
1494 for mf in matched:
1495 if mf.startswith(d):
1496 break
1497 else:
1498 fail(f, _("no match under directory!"))
1499 elif f not in self.dirstate:
1500 fail(f, _("file not tracked!"))
1501
1480 @unfilteredmethod 1502 @unfilteredmethod
1481 def commit(self, text="", user=None, date=None, match=None, force=False, 1503 def commit(self, text="", user=None, date=None, match=None, force=False,
1482 editor=False, extra=None): 1504 editor=False, extra=None):
1483 """Add a new revision to current repository. 1505 """Add a new revision to current repository.
1484 1506
1569 '.hgsubstate' not in (status.modified + status.added + 1591 '.hgsubstate' not in (status.modified + status.added +
1570 status.removed)): 1592 status.removed)):
1571 status.removed.insert(0, '.hgsubstate') 1593 status.removed.insert(0, '.hgsubstate')
1572 1594
1573 # make sure all explicit patterns are matched 1595 # make sure all explicit patterns are matched
1574 if not force and (match.isexact() or match.prefix()): 1596 if not force:
1575 matched = set(status.modified + status.added + status.removed) 1597 self.checkcommitpatterns(wctx, vdirs, match, status, fail)
1576
1577 for f in match.files():
1578 f = self.dirstate.normalize(f)
1579 if f == '.' or f in matched or f in wctx.substate:
1580 continue
1581 if f in status.deleted:
1582 fail(f, _('file not found!'))
1583 if f in vdirs: # visited directory
1584 d = f + '/'
1585 for mf in matched:
1586 if mf.startswith(d):
1587 break
1588 else:
1589 fail(f, _("no match under directory!"))
1590 elif f not in self.dirstate:
1591 fail(f, _("file not tracked!"))
1592 1598
1593 cctx = context.workingcommitctx(self, status, 1599 cctx = context.workingcommitctx(self, status,
1594 text, user, date, extra) 1600 text, user, date, extra)
1595 1601
1596 # internal config: ui.allowemptycommit 1602 # internal config: ui.allowemptycommit