Show More
@@ -867,18 +867,21 b' def serve(ui, repo, **opts):' | |||||
867 | """export the repository via HTTP""" |
|
867 | """export the repository via HTTP""" | |
868 |
|
868 | |||
869 | if opts["stdio"]: |
|
869 | if opts["stdio"]: | |
|
870 | fin, fout = sys.stdin, sys.stdout | |||
|
871 | sys.stdout = sys.stderr | |||
|
872 | ||||
870 | def getarg(): |
|
873 | def getarg(): | |
871 |
argline = |
|
874 | argline = fin.readline()[:-1] | |
872 | arg, l = argline.split() |
|
875 | arg, l = argline.split() | |
873 |
val = |
|
876 | val = fin.read(int(l)) | |
874 | return arg, val |
|
877 | return arg, val | |
875 | def respond(v): |
|
878 | def respond(v): | |
876 |
|
|
879 | fout.write("%d\n" % len(v)) | |
877 |
|
|
880 | fout.write(v) | |
878 |
|
|
881 | fout.flush() | |
879 |
|
882 | |||
880 | while 1: |
|
883 | while 1: | |
881 |
cmd = |
|
884 | cmd = fin.readline()[:-1] | |
882 | if cmd == '': |
|
885 | if cmd == '': | |
883 | return |
|
886 | return | |
884 | if cmd == "heads": |
|
887 | if cmd == "heads": | |
@@ -903,24 +906,13 b' def serve(ui, repo, **opts):' | |||||
903 | arg, roots = getarg() |
|
906 | arg, roots = getarg() | |
904 | nodes = map(hg.bin, roots.split(" ")) |
|
907 | nodes = map(hg.bin, roots.split(" ")) | |
905 |
|
908 | |||
906 | b = [] |
|
909 | cg = repo.changegroup(nodes) | |
907 |
|
|
910 | while 1: | |
908 | for chunk in repo.changegroup(nodes): |
|
911 | d = cg.read(4096) | |
909 |
|
|
912 | if not d: break | |
910 |
|
|
913 | fout.write(d) | |
911 | if t > 4096: |
|
|||
912 | sys.stdout.write(struct.pack(">l", t)) |
|
|||
913 | for c in b: |
|
|||
914 | sys.stdout.write(c) |
|
|||
915 | t = 0 |
|
|||
916 | b = [] |
|
|||
917 |
|
914 | |||
918 | sys.stdout.write(struct.pack(">l", t)) |
|
915 | out.flush() | |
919 | for c in b: |
|
|||
920 | sys.stdout.write(c) |
|
|||
921 |
|
||||
922 | sys.stdout.write(struct.pack(">l", -1)) |
|
|||
923 | sys.stdout.flush() |
|
|||
924 |
|
916 | |||
925 | def openlog(opt, default): |
|
917 | def openlog(opt, default): | |
926 | if opts[opt] and opts[opt] != '-': return open(opts[opt], 'w') |
|
918 | if opts[opt] and opts[opt] != '-': return open(opts[opt], 'w') |
@@ -1025,35 +1025,6 b' class localrepository:' | |||||
1025 | return remote.addchangegroup(cg) |
|
1025 | return remote.addchangegroup(cg) | |
1026 |
|
1026 | |||
1027 | def changegroup(self, basenodes): |
|
1027 | def changegroup(self, basenodes): | |
1028 | nodes = self.newer(basenodes) |
|
|||
1029 |
|
||||
1030 | # construct the link map |
|
|||
1031 | linkmap = {} |
|
|||
1032 | for n in nodes: |
|
|||
1033 | linkmap[self.changelog.rev(n)] = n |
|
|||
1034 |
|
||||
1035 | # construct a list of all changed files |
|
|||
1036 | changed = {} |
|
|||
1037 | for n in nodes: |
|
|||
1038 | c = self.changelog.read(n) |
|
|||
1039 | for f in c[3]: |
|
|||
1040 | changed[f] = 1 |
|
|||
1041 | changed = changed.keys() |
|
|||
1042 | changed.sort() |
|
|||
1043 |
|
||||
1044 | # the changegroup is changesets + manifests + all file revs |
|
|||
1045 | revs = [ self.changelog.rev(n) for n in nodes ] |
|
|||
1046 |
|
||||
1047 | for y in self.changelog.group(linkmap): yield y |
|
|||
1048 | for y in self.manifest.group(linkmap): yield y |
|
|||
1049 | for f in changed: |
|
|||
1050 | yield struct.pack(">l", len(f) + 4) + f |
|
|||
1051 | g = self.file(f).group(linkmap) |
|
|||
1052 | for y in g: |
|
|||
1053 | yield y |
|
|||
1054 |
|
||||
1055 | def addchangegroup(self, generator): |
|
|||
1056 |
|
||||
1057 | class genread: |
|
1028 | class genread: | |
1058 | def __init__(self, generator): |
|
1029 | def __init__(self, generator): | |
1059 | self.g = generator |
|
1030 | self.g = generator | |
@@ -1067,6 +1038,40 b' class localrepository:' | |||||
1067 | d, self.buf = self.buf[:l], self.buf[l:] |
|
1038 | d, self.buf = self.buf[:l], self.buf[l:] | |
1068 | return d |
|
1039 | return d | |
1069 |
|
1040 | |||
|
1041 | def gengroup(): | |||
|
1042 | nodes = self.newer(basenodes) | |||
|
1043 | ||||
|
1044 | # construct the link map | |||
|
1045 | linkmap = {} | |||
|
1046 | for n in nodes: | |||
|
1047 | linkmap[self.changelog.rev(n)] = n | |||
|
1048 | ||||
|
1049 | # construct a list of all changed files | |||
|
1050 | changed = {} | |||
|
1051 | for n in nodes: | |||
|
1052 | c = self.changelog.read(n) | |||
|
1053 | for f in c[3]: | |||
|
1054 | changed[f] = 1 | |||
|
1055 | changed = changed.keys() | |||
|
1056 | changed.sort() | |||
|
1057 | ||||
|
1058 | # the changegroup is changesets + manifests + all file revs | |||
|
1059 | revs = [ self.changelog.rev(n) for n in nodes ] | |||
|
1060 | ||||
|
1061 | for y in self.changelog.group(linkmap): yield y | |||
|
1062 | for y in self.manifest.group(linkmap): yield y | |||
|
1063 | for f in changed: | |||
|
1064 | yield struct.pack(">l", len(f) + 4) + f | |||
|
1065 | g = self.file(f).group(linkmap) | |||
|
1066 | for y in g: | |||
|
1067 | yield y | |||
|
1068 | ||||
|
1069 | yield struct.pack(">l", 0) | |||
|
1070 | ||||
|
1071 | return genread(gengroup()) | |||
|
1072 | ||||
|
1073 | def addchangegroup(self, source): | |||
|
1074 | ||||
1070 | def getchunk(): |
|
1075 | def getchunk(): | |
1071 | d = source.read(4) |
|
1076 | d = source.read(4) | |
1072 | if not d: return "" |
|
1077 | if not d: return "" | |
@@ -1087,10 +1092,9 b' class localrepository:' | |||||
1087 | def revmap(x): |
|
1092 | def revmap(x): | |
1088 | return self.changelog.rev(x) |
|
1093 | return self.changelog.rev(x) | |
1089 |
|
1094 | |||
1090 |
if not |
|
1095 | if not source: return | |
1091 | changesets = files = revisions = 0 |
|
1096 | changesets = files = revisions = 0 | |
1092 |
|
1097 | |||
1093 | source = genread(generator) |
|
|||
1094 | tr = self.transaction() |
|
1098 | tr = self.transaction() | |
1095 |
|
1099 | |||
1096 | # pull off the changeset group |
|
1100 | # pull off the changeset group | |
@@ -1592,17 +1596,27 b' class httprepository:' | |||||
1592 |
|
1596 | |||
1593 | def changegroup(self, nodes): |
|
1597 | def changegroup(self, nodes): | |
1594 | n = " ".join(map(hex, nodes)) |
|
1598 | n = " ".join(map(hex, nodes)) | |
1595 | zd = zlib.decompressobj() |
|
|||
1596 | f = self.do_cmd("changegroup", roots=n) |
|
1599 | f = self.do_cmd("changegroup", roots=n) | |
1597 | bytes = 0 |
|
1600 | bytes = 0 | |
1598 | while 1: |
|
1601 | ||
1599 | d = f.read(4096) |
|
1602 | class zread: | |
1600 | bytes += len(d) |
|
1603 | def __init__(self, f): | |
1601 | if not d: |
|
1604 | self.zd = zlib.decompressobj() | |
1602 |
|
|
1605 | self.f = f | |
1603 |
|
|
1606 | self.buf = "" | |
1604 | yield zd.decompress(d) |
|
1607 | def read(self, l): | |
1605 | self.ui.note("%d bytes of data transfered\n" % bytes) |
|
1608 | while l > len(self.buf): | |
|
1609 | r = f.read(4096) | |||
|
1610 | if r: | |||
|
1611 | self.buf += self.zd.decompress(r) | |||
|
1612 | else: | |||
|
1613 | self.buf += self.zd.flush() | |||
|
1614 | break | |||
|
1615 | d, self.buf = self.buf[:l], self.buf[l:] | |||
|
1616 | return d | |||
|
1617 | ||||
|
1618 | return zread(f) | |||
|
1619 | ||||
1606 |
|
1620 | |||
1607 | class sshrepository: |
|
1621 | class sshrepository: | |
1608 | def __init__(self, ui, path): |
|
1622 | def __init__(self, ui, path): | |
@@ -1680,14 +1694,7 b' class sshrepository:' | |||||
1680 | def changegroup(self, nodes): |
|
1694 | def changegroup(self, nodes): | |
1681 | n = " ".join(map(hex, nodes)) |
|
1695 | n = " ".join(map(hex, nodes)) | |
1682 | f = self.do_cmd("changegroup", roots=n) |
|
1696 | f = self.do_cmd("changegroup", roots=n) | |
1683 | bytes = 0 |
|
1697 | return self.pipei | |
1684 | while 1: |
|
|||
1685 | l = struct.unpack(">l", f.read(4))[0] |
|
|||
1686 | if l == -1: break |
|
|||
1687 | d = f.read(l) |
|
|||
1688 | bytes += len(d) |
|
|||
1689 | yield d |
|
|||
1690 | self.ui.note("%d bytes of data transfered\n" % bytes) |
|
|||
1691 |
|
1698 | |||
1692 | def repository(ui, path=None, create=0): |
|
1699 | def repository(ui, path=None, create=0): | |
1693 | if path: |
|
1700 | if path: |
@@ -687,7 +687,10 b' class hgweb:' | |||||
687 | nodes = map(bin, args['roots'][0].split(" ")) |
|
687 | nodes = map(bin, args['roots'][0].split(" ")) | |
688 |
|
688 | |||
689 | z = zlib.compressobj() |
|
689 | z = zlib.compressobj() | |
690 |
f |
|
690 | f = self.repo.changegroup(nodes) | |
|
691 | while 1: | |||
|
692 | chunk = f.read(4096) | |||
|
693 | if not chunk: break | |||
691 | sys.stdout.write(z.compress(chunk)) |
|
694 | sys.stdout.write(z.compress(chunk)) | |
692 |
|
695 | |||
693 | sys.stdout.write(z.flush()) |
|
696 | sys.stdout.write(z.flush()) |
General Comments 0
You need to be logged in to leave comments.
Login now