Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 8469:cb897f10e54a
localrepo: use set instead of dict
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Sun, 17 May 2009 04:33:39 +0200 |
parents | 9dfee83c93c8 |
children | a9dab5a0f85b |
comparison
equal
deleted
inserted
replaced
8468:b35d11d10646 | 8469:cb897f10e54a |
---|---|
1380 remove.append(p) | 1380 remove.append(p) |
1381 | 1381 |
1382 # find every node whose parents have been pruned | 1382 # find every node whose parents have been pruned |
1383 subset = [] | 1383 subset = [] |
1384 # find every remote head that will get new children | 1384 # find every remote head that will get new children |
1385 updated_heads = {} | 1385 updated_heads = set() |
1386 for n in remain: | 1386 for n in remain: |
1387 p1, p2 = self.changelog.parents(n) | 1387 p1, p2 = self.changelog.parents(n) |
1388 if p1 not in remain and p2 not in remain: | 1388 if p1 not in remain and p2 not in remain: |
1389 subset.append(n) | 1389 subset.append(n) |
1390 if heads: | 1390 if heads: |
1391 if p1 in heads: | 1391 if p1 in heads: |
1392 updated_heads[p1] = True | 1392 updated_heads.add(p1) |
1393 if p2 in heads: | 1393 if p2 in heads: |
1394 updated_heads[p2] = True | 1394 updated_heads.add(p2) |
1395 | 1395 |
1396 # this is the set of all roots we have to push | 1396 # this is the set of all roots we have to push |
1397 if heads: | 1397 if heads: |
1398 return subset, updated_heads.keys() | 1398 return subset, list(updated_heads) |
1399 else: | 1399 else: |
1400 return subset | 1400 return subset |
1401 | 1401 |
1402 def pull(self, remote, heads=None, force=False): | 1402 def pull(self, remote, heads=None, force=False): |
1403 lock = self.lock() | 1403 lock = self.lock() |
1573 # too. nodesbetween will return the minimal set of bases and heads | 1573 # too. nodesbetween will return the minimal set of bases and heads |
1574 # necessary to re-create the changegroup. | 1574 # necessary to re-create the changegroup. |
1575 | 1575 |
1576 # Known heads are the list of heads that it is assumed the recipient | 1576 # Known heads are the list of heads that it is assumed the recipient |
1577 # of this changegroup will know about. | 1577 # of this changegroup will know about. |
1578 knownheads = {} | 1578 knownheads = set() |
1579 # We assume that all parents of bases are known heads. | 1579 # We assume that all parents of bases are known heads. |
1580 for n in bases: | 1580 for n in bases: |
1581 for p in cl.parents(n): | 1581 for p in cl.parents(n): |
1582 if p != nullid: | 1582 if p != nullid: |
1583 knownheads[p] = 1 | 1583 knownheads.add(p) |
1584 knownheads = knownheads.keys() | 1584 knownheads = list(knownheads) |
1585 if knownheads: | 1585 if knownheads: |
1586 # Now that we know what heads are known, we can compute which | 1586 # Now that we know what heads are known, we can compute which |
1587 # changesets are known. The recipient must know about all | 1587 # changesets are known. The recipient must know about all |
1588 # changesets required to reach the known heads from the null | 1588 # changesets required to reach the known heads from the null |
1589 # changeset. | 1589 # changeset. |
1625 # If we determine that a particular file or manifest node must be a | 1625 # If we determine that a particular file or manifest node must be a |
1626 # node that the recipient of the changegroup will already have, we can | 1626 # node that the recipient of the changegroup will already have, we can |
1627 # also assume the recipient will have all the parents. This function | 1627 # also assume the recipient will have all the parents. This function |
1628 # prunes them from the set of missing nodes. | 1628 # prunes them from the set of missing nodes. |
1629 def prune_parents(revlog, hasset, msngset): | 1629 def prune_parents(revlog, hasset, msngset): |
1630 haslst = hasset.keys() | 1630 haslst = list(hasset) |
1631 haslst.sort(cmp_by_rev_func(revlog)) | 1631 haslst.sort(cmp_by_rev_func(revlog)) |
1632 for node in haslst: | 1632 for node in haslst: |
1633 parentlst = [p for p in revlog.parents(node) if p != nullid] | 1633 parentlst = [p for p in revlog.parents(node) if p != nullid] |
1634 while parentlst: | 1634 while parentlst: |
1635 n = parentlst.pop() | 1635 n = parentlst.pop() |
1636 if n not in hasset: | 1636 if n not in hasset: |
1637 hasset[n] = 1 | 1637 hasset.add(n) |
1638 p = [p for p in revlog.parents(n) if p != nullid] | 1638 p = [p for p in revlog.parents(n) if p != nullid] |
1639 parentlst.extend(p) | 1639 parentlst.extend(p) |
1640 for n in hasset: | 1640 for n in hasset: |
1641 msngset.pop(n, None) | 1641 msngset.pop(n, None) |
1642 | 1642 |
1664 | 1664 |
1665 # Figure out which manifest nodes (of the ones we think might be part | 1665 # Figure out which manifest nodes (of the ones we think might be part |
1666 # of the changegroup) the recipient must know about and remove them | 1666 # of the changegroup) the recipient must know about and remove them |
1667 # from the changegroup. | 1667 # from the changegroup. |
1668 def prune_manifests(): | 1668 def prune_manifests(): |
1669 has_mnfst_set = {} | 1669 has_mnfst_set = set() |
1670 for n in msng_mnfst_set: | 1670 for n in msng_mnfst_set: |
1671 # If a 'missing' manifest thinks it belongs to a changenode | 1671 # If a 'missing' manifest thinks it belongs to a changenode |
1672 # the recipient is assumed to have, obviously the recipient | 1672 # the recipient is assumed to have, obviously the recipient |
1673 # must have that manifest. | 1673 # must have that manifest. |
1674 linknode = cl.node(mnfst.linkrev(mnfst.rev(n))) | 1674 linknode = cl.node(mnfst.linkrev(mnfst.rev(n))) |
1675 if linknode in has_cl_set: | 1675 if linknode in has_cl_set: |
1676 has_mnfst_set[n] = 1 | 1676 has_mnfst_set.add(n) |
1677 prune_parents(mnfst, has_mnfst_set, msng_mnfst_set) | 1677 prune_parents(mnfst, has_mnfst_set, msng_mnfst_set) |
1678 | 1678 |
1679 # Use the information collected in collect_manifests_and_files to say | 1679 # Use the information collected in collect_manifests_and_files to say |
1680 # which changenode any manifestnode belongs to. | 1680 # which changenode any manifestnode belongs to. |
1681 def lookup_manifest_link(mnfstnode): | 1681 def lookup_manifest_link(mnfstnode): |
1730 | 1730 |
1731 # We have a list of filenodes we think we need for a file, lets remove | 1731 # We have a list of filenodes we think we need for a file, lets remove |
1732 # all those we know the recipient must have. | 1732 # all those we know the recipient must have. |
1733 def prune_filenodes(f, filerevlog): | 1733 def prune_filenodes(f, filerevlog): |
1734 msngset = msng_filenode_set[f] | 1734 msngset = msng_filenode_set[f] |
1735 hasset = {} | 1735 hasset = set() |
1736 # If a 'missing' filenode thinks it belongs to a changenode we | 1736 # If a 'missing' filenode thinks it belongs to a changenode we |
1737 # assume the recipient must have, then the recipient must have | 1737 # assume the recipient must have, then the recipient must have |
1738 # that filenode. | 1738 # that filenode. |
1739 for n in msngset: | 1739 for n in msngset: |
1740 clnode = cl.node(filerevlog.linkrev(filerevlog.rev(n))) | 1740 clnode = cl.node(filerevlog.linkrev(filerevlog.rev(n))) |
1741 if clnode in has_cl_set: | 1741 if clnode in has_cl_set: |
1742 hasset[n] = 1 | 1742 hasset.add(n) |
1743 prune_parents(filerevlog, hasset, msngset) | 1743 prune_parents(filerevlog, hasset, msngset) |
1744 | 1744 |
1745 # A function generator function that sets up the a context for the | 1745 # A function generator function that sets up the a context for the |
1746 # inner function. | 1746 # inner function. |
1747 def lookup_filenode_link_func(fname): | 1747 def lookup_filenode_link_func(fname): |
1865 | 1865 |
1866 def changed_file_collector(changedfileset): | 1866 def changed_file_collector(changedfileset): |
1867 def collect_changed_files(clnode): | 1867 def collect_changed_files(clnode): |
1868 c = cl.read(clnode) | 1868 c = cl.read(clnode) |
1869 for fname in c[3]: | 1869 for fname in c[3]: |
1870 changedfileset[fname] = 1 | 1870 changedfileset.add(fname) |
1871 return collect_changed_files | 1871 return collect_changed_files |
1872 | 1872 |
1873 def lookuprevlink_func(revlog): | 1873 def lookuprevlink_func(revlog): |
1874 def lookuprevlink(n): | 1874 def lookuprevlink(n): |
1875 return cl.node(revlog.linkrev(revlog.rev(n))) | 1875 return cl.node(revlog.linkrev(revlog.rev(n))) |
1876 return lookuprevlink | 1876 return lookuprevlink |
1877 | 1877 |
1878 def gengroup(): | 1878 def gengroup(): |
1879 # construct a list of all changed files | 1879 # construct a list of all changed files |
1880 changedfiles = {} | 1880 changedfiles = set() |
1881 | 1881 |
1882 for chnk in cl.group(nodes, identity, | 1882 for chnk in cl.group(nodes, identity, |
1883 changed_file_collector(changedfiles)): | 1883 changed_file_collector(changedfiles)): |
1884 yield chnk | 1884 yield chnk |
1885 | 1885 |