Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 4261:cd7b36b7869c
restructure changelog file appending
- make appending code proper part of changelog with delayupdate/finalize
- use simplified appender that tracks pending data in memory
- eliminate old appendfile and helper classes
- update addchangegroup to use new interface and reuse the existing changelog
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 22 Mar 2007 23:37:44 -0500 |
parents | b11a2fb59cf5 |
children | f38f90a177dc |
comparison
equal
deleted
inserted
replaced
4260:bdbfc2193524 | 4261:cd7b36b7869c |
---|---|
5 # This software may be used and distributed according to the terms | 5 # This software may be used and distributed according to the terms |
6 # of the GNU General Public License, incorporated herein by reference. | 6 # of the GNU General Public License, incorporated herein by reference. |
7 | 7 |
8 from node import * | 8 from node import * |
9 from i18n import _ | 9 from i18n import _ |
10 import repo, appendfile, changegroup | 10 import repo, changegroup |
11 import changelog, dirstate, filelog, manifest, context | 11 import changelog, dirstate, filelog, manifest, context |
12 import re, lock, transaction, tempfile, stat, mdiff, errno, ui | 12 import re, lock, transaction, tempfile, stat, mdiff, errno, ui |
13 import os, revlog, time, util | 13 import os, revlog, time, util |
14 | 14 |
15 class localrepository(repo.repository): | 15 class localrepository(repo.repository): |
1780 | 1780 |
1781 tr = self.transaction() | 1781 tr = self.transaction() |
1782 | 1782 |
1783 # write changelog data to temp files so concurrent readers will not see | 1783 # write changelog data to temp files so concurrent readers will not see |
1784 # inconsistent view | 1784 # inconsistent view |
1785 cl = None | 1785 cl = self.changelog |
1786 try: | 1786 cl.delayupdate() |
1787 cl = appendfile.appendchangelog(self.sopener) | 1787 oldheads = len(cl.heads()) |
1788 oldheads = len(cl.heads()) | 1788 |
1789 | 1789 # pull off the changeset group |
1790 # pull off the changeset group | 1790 self.ui.status(_("adding changesets\n")) |
1791 self.ui.status(_("adding changesets\n")) | 1791 cor = cl.count() - 1 |
1792 cor = cl.count() - 1 | 1792 chunkiter = changegroup.chunkiter(source) |
1793 if cl.addgroup(chunkiter, csmap, tr, 1) is None: | |
1794 raise util.Abort(_("received changelog group is empty")) | |
1795 cnr = cl.count() - 1 | |
1796 changesets = cnr - cor | |
1797 | |
1798 # pull off the manifest group | |
1799 self.ui.status(_("adding manifests\n")) | |
1800 chunkiter = changegroup.chunkiter(source) | |
1801 # no need to check for empty manifest group here: | |
1802 # if the result of the merge of 1 and 2 is the same in 3 and 4, | |
1803 # no new manifest will be created and the manifest group will | |
1804 # be empty during the pull | |
1805 self.manifest.addgroup(chunkiter, revmap, tr) | |
1806 | |
1807 # process the files | |
1808 self.ui.status(_("adding file changes\n")) | |
1809 while 1: | |
1810 f = changegroup.getchunk(source) | |
1811 if not f: | |
1812 break | |
1813 self.ui.debug(_("adding %s revisions\n") % f) | |
1814 fl = self.file(f) | |
1815 o = fl.count() | |
1793 chunkiter = changegroup.chunkiter(source) | 1816 chunkiter = changegroup.chunkiter(source) |
1794 if cl.addgroup(chunkiter, csmap, tr, 1) is None: | 1817 if fl.addgroup(chunkiter, revmap, tr) is None: |
1795 raise util.Abort(_("received changelog group is empty")) | 1818 raise util.Abort(_("received file revlog group is empty")) |
1796 cnr = cl.count() - 1 | 1819 revisions += fl.count() - o |
1797 changesets = cnr - cor | 1820 files += 1 |
1798 | |
1799 # pull off the manifest group | |
1800 self.ui.status(_("adding manifests\n")) | |
1801 chunkiter = changegroup.chunkiter(source) | |
1802 # no need to check for empty manifest group here: | |
1803 # if the result of the merge of 1 and 2 is the same in 3 and 4, | |
1804 # no new manifest will be created and the manifest group will | |
1805 # be empty during the pull | |
1806 self.manifest.addgroup(chunkiter, revmap, tr) | |
1807 | |
1808 # process the files | |
1809 self.ui.status(_("adding file changes\n")) | |
1810 while 1: | |
1811 f = changegroup.getchunk(source) | |
1812 if not f: | |
1813 break | |
1814 self.ui.debug(_("adding %s revisions\n") % f) | |
1815 fl = self.file(f) | |
1816 o = fl.count() | |
1817 chunkiter = changegroup.chunkiter(source) | |
1818 if fl.addgroup(chunkiter, revmap, tr) is None: | |
1819 raise util.Abort(_("received file revlog group is empty")) | |
1820 revisions += fl.count() - o | |
1821 files += 1 | |
1822 | |
1823 cl.writedata() | |
1824 finally: | |
1825 if cl: | |
1826 cl.cleanup() | |
1827 | 1821 |
1828 # make changelog see real files again | 1822 # make changelog see real files again |
1829 self.changelog = changelog.changelog(self.sopener) | 1823 cl.finalize(tr) |
1830 self.changelog.checkinlinesize(tr) | |
1831 | 1824 |
1832 newheads = len(self.changelog.heads()) | 1825 newheads = len(self.changelog.heads()) |
1833 heads = "" | 1826 heads = "" |
1834 if oldheads and newheads != oldheads: | 1827 if oldheads and newheads != oldheads: |
1835 heads = _(" (%+d heads)") % (newheads - oldheads) | 1828 heads = _(" (%+d heads)") % (newheads - oldheads) |