Mercurial > hg
comparison mercurial/localrepo.py @ 14268:a55a0045704c
merge with stable
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 08 May 2011 16:16:41 -0500 |
parents | df2399663392 89e7d35e0ef0 |
children | 01472f8f5429 |
comparison
equal
deleted
inserted
replaced
14267:6332c02b3d68 | 14268:a55a0045704c |
---|---|
672 # abort here if the journal already exists | 672 # abort here if the journal already exists |
673 if os.path.exists(self.sjoin("journal")): | 673 if os.path.exists(self.sjoin("journal")): |
674 raise error.RepoError( | 674 raise error.RepoError( |
675 _("abandoned transaction found - run hg recover")) | 675 _("abandoned transaction found - run hg recover")) |
676 | 676 |
677 journalfiles = self._writejournal(desc) | |
678 renames = [(x, undoname(x)) for x in journalfiles] | |
679 | |
680 tr = transaction.transaction(self.ui.warn, self.sopener, | |
681 self.sjoin("journal"), | |
682 aftertrans(renames), | |
683 self.store.createmode) | |
684 self._transref = weakref.ref(tr) | |
685 return tr | |
686 | |
687 def _writejournal(self, desc): | |
677 # save dirstate for rollback | 688 # save dirstate for rollback |
678 try: | 689 try: |
679 ds = self.opener.read("dirstate") | 690 ds = self.opener.read("dirstate") |
680 except IOError: | 691 except IOError: |
681 ds = "" | 692 ds = "" |
683 self.opener.write("journal.branch", | 694 self.opener.write("journal.branch", |
684 encoding.fromlocal(self.dirstate.branch())) | 695 encoding.fromlocal(self.dirstate.branch())) |
685 self.opener.write("journal.desc", | 696 self.opener.write("journal.desc", |
686 "%d\n%s\n" % (len(self), desc)) | 697 "%d\n%s\n" % (len(self), desc)) |
687 | 698 |
688 renames = [(self.sjoin("journal"), self.sjoin("undo")), | 699 bkname = self.join('bookmarks') |
689 (self.join("journal.dirstate"), self.join("undo.dirstate")), | 700 if os.path.exists(bkname): |
690 (self.join("journal.branch"), self.join("undo.branch")), | 701 util.copyfile(bkname, self.join('journal.bookmarks')) |
691 (self.join("journal.desc"), self.join("undo.desc"))] | 702 else: |
692 tr = transaction.transaction(self.ui.warn, self.sopener, | 703 self.opener('journal.bookmarks', 'w').write('') |
693 self.sjoin("journal"), | 704 |
694 aftertrans(renames), | 705 return (self.sjoin('journal'), self.join('journal.dirstate'), |
695 self.store.createmode) | 706 self.join('journal.branch'), self.join('journal.desc'), |
696 self._transref = weakref.ref(tr) | 707 self.join('journal.bookmarks')) |
697 return tr | |
698 | 708 |
699 def recover(self): | 709 def recover(self): |
700 lock = self.lock() | 710 lock = self.lock() |
701 try: | 711 try: |
702 if os.path.exists(self.sjoin("journal")): | 712 if os.path.exists(self.sjoin("journal")): |
1948 def a(): | 1958 def a(): |
1949 for src, dest in renamefiles: | 1959 for src, dest in renamefiles: |
1950 util.rename(src, dest) | 1960 util.rename(src, dest) |
1951 return a | 1961 return a |
1952 | 1962 |
1963 def undoname(fn): | |
1964 base, name = os.path.split(fn) | |
1965 assert name.startswith('journal') | |
1966 return os.path.join(base, name.replace('journal', 'undo', 1)) | |
1967 | |
1953 def instance(ui, path, create): | 1968 def instance(ui, path, create): |
1954 return localrepository(ui, util.localpath(path), create) | 1969 return localrepository(ui, util.localpath(path), create) |
1955 | 1970 |
1956 def islocal(path): | 1971 def islocal(path): |
1957 return True | 1972 return True |