610 nl.append(n) |
610 nl.append(n) |
611 |
611 |
612 return nl |
612 return nl |
613 |
613 |
614 def getchangegroup(self, remote): |
614 def getchangegroup(self, remote): |
615 tip = remote.branches([]) |
615 tip = remote.branches([])[0] |
616 cl = self.changelog |
616 cl = self.changelog |
617 unknown = tip |
617 unknown = [tip] |
618 search = [] |
618 search = [] |
619 fetch = [] |
619 fetch = [] |
620 |
620 |
621 if tip[0] == self.changelog.tip(): |
621 if tip[0] == self.changelog.tip(): |
622 return "" |
622 return None |
623 |
623 |
624 while unknown: |
624 while unknown: |
625 n = unknown.pop(0) |
625 n = unknown.pop(0) |
626 if n == nullid: break |
626 if n == nullid: break |
627 if n[1] and cl.nodemap.has_key(n[1]): # do we know the base? |
627 if n[1] and cl.nodemap.has_key(n[1]): # do we know the base? |
628 search.append(n) # schedule branch range for scanning |
628 search.append(n) # schedule branch range for scanning |
664 changed[f] = 1 |
664 changed[f] = 1 |
665 changed = changed.keys() |
665 changed = changed.keys() |
666 changed.sort() |
666 changed.sort() |
667 |
667 |
668 # the changegroup is changesets + manifests + all file revs |
668 # the changegroup is changesets + manifests + all file revs |
669 cg = [] |
|
670 revs = [ self.changelog.rev(n) for n in nodes ] |
669 revs = [ self.changelog.rev(n) for n in nodes ] |
671 |
670 |
672 g = self.changelog.group(linkmap) |
671 yield self.changelog.group(linkmap) |
673 cg.append(g) |
672 yield self.manifest.group(linkmap) |
674 g = self.manifest.group(linkmap) |
|
675 cg.append(g) |
|
676 |
673 |
677 for f in changed: |
674 for f in changed: |
678 g = self.file(f).group(linkmap) |
675 g = self.file(f).group(linkmap) |
679 if not g: raise "couldn't find change to %s" % f |
676 if not g: raise "couldn't find change to %s" % f |
680 l = struct.pack(">l", len(f)) |
677 l = struct.pack(">l", len(f)) |
681 cg += [l, f, g] |
678 yield "".join([l, f, g]) |
682 |
|
683 return "".join(cg) |
|
684 |
679 |
685 def addchangegroup(self, data): |
680 def addchangegroup(self, data): |
686 def getlen(data, pos): |
681 def getlen(data, pos): |
687 return struct.unpack(">l", data[pos:pos + 4])[0] |
682 return struct.unpack(">l", data[pos:pos + 4])[0] |
|
683 |
|
684 if not data: return |
688 |
685 |
689 tr = self.transaction() |
686 tr = self.transaction() |
690 simple = True |
687 simple = True |
691 |
688 |
692 print "merging changesets" |
689 print "merging changesets" |
784 edittext = "\n"+"".join(["HG: changed %s\n" % f for f in new]) |
781 edittext = "\n"+"".join(["HG: changed %s\n" % f for f in new]) |
785 edittext = self.ui.edit(edittext) |
782 edittext = self.ui.edit(edittext) |
786 n = self.changelog.add(node, new, edittext, tr, co, cn) |
783 n = self.changelog.add(node, new, edittext, tr, co, cn) |
787 |
784 |
788 tr.close() |
785 tr.close() |
|
786 |
|
787 class remoterepository: |
|
788 def __init__(self, ui, path): |
|
789 self.url = path.replace("hg://", "http://", 1) |
|
790 self.ui = ui |
|
791 |
|
792 def do_cmd(self, cmd, **args): |
|
793 q = {"cmd": cmd} |
|
794 q.update(args) |
|
795 qs = urllib.urlencode(q) |
|
796 cu = "%s?%s" % (self.url, qs) |
|
797 return urllib.urlopen(cu).read() |
|
798 |
|
799 def branches(self, nodes): |
|
800 n = " ".join(map(hex, nodes)) |
|
801 d = self.do_cmd("branches", nodes=n) |
|
802 br = [ map(bin, b.split(" ")) for b in d.splitlines() ] |
|
803 return br |
|
804 |
|
805 def between(self, pairs): |
|
806 n = "\n".join(["-".join(map(hex, p)) for p in pairs]) |
|
807 d = self.do_cmd("between", pairs=n) |
|
808 p = [ map(bin, l.split(" ")) for l in d.splitlines() ] |
|
809 return p |
|
810 |
|
811 def changegroup(self, nodes): |
|
812 n = " ".join(map(hex, nodes)) |
|
813 d = self.do_cmd("changegroup", roots=n) |
|
814 return zlib.decompress(d) |
|
815 |
|
816 def repository(ui, path=None, create=0): |
|
817 if path and path[:5] == "hg://": |
|
818 return remoterepository(ui, path) |
|
819 else: |
|
820 return localrepository(ui, path, create) |
789 |
821 |
790 class ui: |
822 class ui: |
791 def __init__(self, verbose=False, debug=False): |
823 def __init__(self, verbose=False, debug=False): |
792 self.verbose = verbose |
824 self.verbose = verbose |
793 def write(self, *args): |
825 def write(self, *args): |