comparison mercurial/context.py @ 33501:7008f6819002

context: name files relative to cwd in warning messages I was several directories deep in the kernel tree, ran `hg add`, and got the warning about the size of one of the files. I noticed that it suggested undoing the add with a specific revert command. The problem is, it would have failed since the path printed was relative to the repo root instead of cwd. While here, I just fixed the other messages too. As an added benefit, these messages now look the same as the verbose/inexact messages for the corresponding command. I don't think most of these messages are reachable (typically the corresponding cmdutil function does the check). I wasn't able to figure out why the keyword tests were failing when using pathto()- I couldn't cause an absolute path to be used by manipulating the --cwd flag on a regular add. (I did notice that keyword is adding the file without holding wlock.)
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 11 Jul 2017 00:40:29 -0400
parents 0407a51b9d8c
children 03039ff3082b
comparison
equal deleted inserted replaced
33500:9c6e64911de0 33501:7008f6819002
31 fileset, 31 fileset,
32 match as matchmod, 32 match as matchmod,
33 mdiff, 33 mdiff,
34 obsolete as obsmod, 34 obsolete as obsmod,
35 patch, 35 patch,
36 pathutil,
36 phases, 37 phases,
37 pycompat, 38 pycompat,
38 repoview, 39 repoview,
39 revlog, 40 revlog,
40 scmutil, 41 scmutil,
1516 (branch and self.branch() != self.p1().branch()) or 1517 (branch and self.branch() != self.p1().branch()) or
1517 self.modified() or self.added() or self.removed() or 1518 self.modified() or self.added() or self.removed() or
1518 (missing and self.deleted())) 1519 (missing and self.deleted()))
1519 1520
1520 def add(self, list, prefix=""): 1521 def add(self, list, prefix=""):
1521 join = lambda f: os.path.join(prefix, f)
1522 with self._repo.wlock(): 1522 with self._repo.wlock():
1523 ui, ds = self._repo.ui, self._repo.dirstate 1523 ui, ds = self._repo.ui, self._repo.dirstate
1524 uipath = lambda f: ds.pathto(pathutil.join(prefix, f))
1524 rejected = [] 1525 rejected = []
1525 lstat = self._repo.wvfs.lstat 1526 lstat = self._repo.wvfs.lstat
1526 for f in list: 1527 for f in list:
1527 scmutil.checkportable(ui, join(f)) 1528 # ds.pathto() returns an absolute file when this is invoked from
1529 # the keyword extension. That gets flagged as non-portable on
1530 # Windows, since it contains the drive letter and colon.
1531 scmutil.checkportable(ui, os.path.join(prefix, f))
1528 try: 1532 try:
1529 st = lstat(f) 1533 st = lstat(f)
1530 except OSError: 1534 except OSError:
1531 ui.warn(_("%s does not exist!\n") % join(f)) 1535 ui.warn(_("%s does not exist!\n") % uipath(f))
1532 rejected.append(f) 1536 rejected.append(f)
1533 continue 1537 continue
1534 if st.st_size > 10000000: 1538 if st.st_size > 10000000:
1535 ui.warn(_("%s: up to %d MB of RAM may be required " 1539 ui.warn(_("%s: up to %d MB of RAM may be required "
1536 "to manage this file\n" 1540 "to manage this file\n"
1537 "(use 'hg revert %s' to cancel the " 1541 "(use 'hg revert %s' to cancel the "
1538 "pending addition)\n") 1542 "pending addition)\n")
1539 % (f, 3 * st.st_size // 1000000, join(f))) 1543 % (f, 3 * st.st_size // 1000000, uipath(f)))
1540 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): 1544 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1541 ui.warn(_("%s not added: only files and symlinks " 1545 ui.warn(_("%s not added: only files and symlinks "
1542 "supported currently\n") % join(f)) 1546 "supported currently\n") % uipath(f))
1543 rejected.append(f) 1547 rejected.append(f)
1544 elif ds[f] in 'amn': 1548 elif ds[f] in 'amn':
1545 ui.warn(_("%s already tracked!\n") % join(f)) 1549 ui.warn(_("%s already tracked!\n") % uipath(f))
1546 elif ds[f] == 'r': 1550 elif ds[f] == 'r':
1547 ds.normallookup(f) 1551 ds.normallookup(f)
1548 else: 1552 else:
1549 ds.add(f) 1553 ds.add(f)
1550 return rejected 1554 return rejected
1551 1555
1552 def forget(self, files, prefix=""): 1556 def forget(self, files, prefix=""):
1553 join = lambda f: os.path.join(prefix, f)
1554 with self._repo.wlock(): 1557 with self._repo.wlock():
1558 ds = self._repo.dirstate
1559 uipath = lambda f: ds.pathto(pathutil.join(prefix, f))
1555 rejected = [] 1560 rejected = []
1556 for f in files: 1561 for f in files:
1557 if f not in self._repo.dirstate: 1562 if f not in self._repo.dirstate:
1558 self._repo.ui.warn(_("%s not tracked!\n") % join(f)) 1563 self._repo.ui.warn(_("%s not tracked!\n") % uipath(f))
1559 rejected.append(f) 1564 rejected.append(f)
1560 elif self._repo.dirstate[f] != 'a': 1565 elif self._repo.dirstate[f] != 'a':
1561 self._repo.dirstate.remove(f) 1566 self._repo.dirstate.remove(f)
1562 else: 1567 else:
1563 self._repo.dirstate.drop(f) 1568 self._repo.dirstate.drop(f)
1564 return rejected 1569 return rejected
1565 1570
1566 def undelete(self, list): 1571 def undelete(self, list):
1567 pctxs = self.parents() 1572 pctxs = self.parents()
1568 with self._repo.wlock(): 1573 with self._repo.wlock():
1574 ds = self._repo.dirstate
1569 for f in list: 1575 for f in list:
1570 if self._repo.dirstate[f] != 'r': 1576 if self._repo.dirstate[f] != 'r':
1571 self._repo.ui.warn(_("%s not removed!\n") % f) 1577 self._repo.ui.warn(_("%s not removed!\n") % ds.pathto(f))
1572 else: 1578 else:
1573 fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] 1579 fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f]
1574 t = fctx.data() 1580 t = fctx.data()
1575 self._repo.wwrite(f, t, fctx.flags()) 1581 self._repo.wwrite(f, t, fctx.flags())
1576 self._repo.dirstate.normal(f) 1582 self._repo.dirstate.normal(f)
1579 try: 1585 try:
1580 st = self._repo.wvfs.lstat(dest) 1586 st = self._repo.wvfs.lstat(dest)
1581 except OSError as err: 1587 except OSError as err:
1582 if err.errno != errno.ENOENT: 1588 if err.errno != errno.ENOENT:
1583 raise 1589 raise
1584 self._repo.ui.warn(_("%s does not exist!\n") % dest) 1590 self._repo.ui.warn(_("%s does not exist!\n")
1591 % self._repo.dirstate.pathto(dest))
1585 return 1592 return
1586 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): 1593 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1587 self._repo.ui.warn(_("copy failed: %s is not a file or a " 1594 self._repo.ui.warn(_("copy failed: %s is not a file or a "
1588 "symbolic link\n") % dest) 1595 "symbolic link\n")
1596 % self._repo.dirstate.pathto(dest))
1589 else: 1597 else:
1590 with self._repo.wlock(): 1598 with self._repo.wlock():
1591 if self._repo.dirstate[dest] in '?': 1599 if self._repo.dirstate[dest] in '?':
1592 self._repo.dirstate.add(dest) 1600 self._repo.dirstate.add(dest)
1593 elif self._repo.dirstate[dest] in 'r': 1601 elif self._repo.dirstate[dest] in 'r':