Mercurial > public > mercurial-scm > hg
comparison mercurial/context.py @ 11303:a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Mon, 07 Jun 2010 20:03:32 +0200 |
parents | c5c190822501 |
children | 2ee26044d846 |
comparison
equal
deleted
inserted
replaced
11302:e1dde7363601 | 11303:a1aad8333864 |
---|---|
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from node import nullid, nullrev, short, hex | 8 from node import nullid, nullrev, short, hex |
9 from i18n import _ | 9 from i18n import _ |
10 import ancestor, bdiff, error, util, subrepo, patch | 10 import ancestor, bdiff, error, util, subrepo, patch |
11 import os, errno | 11 import os, errno, stat |
12 | 12 |
13 propertycache = util.propertycache | 13 propertycache = util.propertycache |
14 | 14 |
15 class changectx(object): | 15 class changectx(object): |
16 """A changecontext object makes access to data related to a particular | 16 """A changecontext object makes access to data related to a particular |
759 # check current working dir | 759 # check current working dir |
760 return (self.p2() or self.branch() != self.p1().branch() or | 760 return (self.p2() or self.branch() != self.p1().branch() or |
761 self.modified() or self.added() or self.removed() or | 761 self.modified() or self.added() or self.removed() or |
762 (missing and self.deleted())) | 762 (missing and self.deleted())) |
763 | 763 |
764 def add(self, list): | |
765 wlock = self._repo.wlock() | |
766 ui, ds = self._repo.ui, self._repo.dirstate | |
767 try: | |
768 rejected = [] | |
769 for f in list: | |
770 p = self._repo.wjoin(f) | |
771 try: | |
772 st = os.lstat(p) | |
773 except: | |
774 ui.warn(_("%s does not exist!\n") % f) | |
775 rejected.append(f) | |
776 continue | |
777 if st.st_size > 10000000: | |
778 ui.warn(_("%s: up to %d MB of RAM may be required " | |
779 "to manage this file\n" | |
780 "(use 'hg revert %s' to cancel the " | |
781 "pending addition)\n") | |
782 % (f, 3 * st.st_size // 1000000, f)) | |
783 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
784 ui.warn(_("%s not added: only files and symlinks " | |
785 "supported currently\n") % f) | |
786 rejected.append(p) | |
787 elif ds[f] in 'amn': | |
788 ui.warn(_("%s already tracked!\n") % f) | |
789 elif ds[f] == 'r': | |
790 ds.normallookup(f) | |
791 else: | |
792 ds.add(f) | |
793 return rejected | |
794 finally: | |
795 wlock.release() | |
796 | |
797 def forget(self, list): | |
798 wlock = self._repo.wlock() | |
799 try: | |
800 for f in list: | |
801 if self._repo.dirstate[f] != 'a': | |
802 self._repo.ui.warn(_("%s not added!\n") % f) | |
803 else: | |
804 self._repo.dirstate.forget(f) | |
805 finally: | |
806 wlock.release() | |
807 | |
808 def remove(self, list, unlink=False): | |
809 if unlink: | |
810 for f in list: | |
811 try: | |
812 util.unlink(self._repo.wjoin(f)) | |
813 except OSError, inst: | |
814 if inst.errno != errno.ENOENT: | |
815 raise | |
816 wlock = self._repo.wlock() | |
817 try: | |
818 for f in list: | |
819 if unlink and os.path.exists(self._repo.wjoin(f)): | |
820 self._repo.ui.warn(_("%s still exists!\n") % f) | |
821 elif self._repo.dirstate[f] == 'a': | |
822 self._repo.dirstate.forget(f) | |
823 elif f not in self._repo.dirstate: | |
824 self._repo.ui.warn(_("%s not tracked!\n") % f) | |
825 else: | |
826 self._repo.dirstate.remove(f) | |
827 finally: | |
828 wlock.release() | |
829 | |
830 def undelete(self, list): | |
831 pctxs = self.parents() | |
832 wlock = self._repo.wlock() | |
833 try: | |
834 for f in list: | |
835 if self._repo.dirstate[f] != 'r': | |
836 self._repo.ui.warn(_("%s not removed!\n") % f) | |
837 else: | |
838 fctx = f in pctxs[0] and pctxs[0] or pctxs[1] | |
839 t = fctx.data() | |
840 self._repo.wwrite(f, t, fctx.flags()) | |
841 self._repo.dirstate.normal(f) | |
842 finally: | |
843 wlock.release() | |
844 | |
845 def copy(self, source, dest): | |
846 p = self._repo.wjoin(dest) | |
847 if not (os.path.exists(p) or os.path.islink(p)): | |
848 self._repo.ui.warn(_("%s does not exist!\n") % dest) | |
849 elif not (os.path.isfile(p) or os.path.islink(p)): | |
850 self._repo.ui.warn(_("copy failed: %s is not a file or a " | |
851 "symbolic link\n") % dest) | |
852 else: | |
853 wlock = self._repo.wlock() | |
854 try: | |
855 if self._repo.dirstate[dest] in '?r': | |
856 self._repo.dirstate.add(dest) | |
857 self._repo.dirstate.copy(source, dest) | |
858 finally: | |
859 wlock.release() | |
860 | |
764 class workingfilectx(filectx): | 861 class workingfilectx(filectx): |
765 """A workingfilectx object makes access to data related to a particular | 862 """A workingfilectx object makes access to data related to a particular |
766 file in the working directory convenient.""" | 863 file in the working directory convenient.""" |
767 def __init__(self, repo, path, filelog=None, workingctx=None): | 864 def __init__(self, repo, path, filelog=None, workingctx=None): |
768 """changeid can be a changeset revision, node, or tag. | 865 """changeid can be a changeset revision, node, or tag. |