equal
deleted
inserted
replaced
850 |
850 |
851 def findincoming(self, remote): |
851 def findincoming(self, remote): |
852 m = self.changelog.nodemap |
852 m = self.changelog.nodemap |
853 search = [] |
853 search = [] |
854 fetch = [] |
854 fetch = [] |
|
855 base = {} |
855 seen = {} |
856 seen = {} |
856 seenbranch = {} |
857 seenbranch = {} |
857 |
858 |
858 # if we have an empty repo, fetch everything |
859 # if we have an empty repo, fetch everything |
859 if self.changelog.tip() == nullid: |
860 if self.changelog.tip() == nullid: |
860 self.ui.status("requesting all changes\n") |
861 self.ui.status("requesting all changes\n") |
861 return [nullid] |
862 return [nullid] |
862 |
863 |
863 # otherwise, assume we're closer to the tip than the root |
864 # otherwise, assume we're closer to the tip than the root |
|
865 # and start by examining the heads |
864 self.ui.status("searching for changes\n") |
866 self.ui.status("searching for changes\n") |
865 heads = remote.heads() |
867 heads = remote.heads() |
866 unknown = [] |
868 unknown = [] |
867 for h in heads: |
869 for h in heads: |
868 if h not in m: |
870 if h not in m: |
872 return None |
874 return None |
873 |
875 |
874 rep = {} |
876 rep = {} |
875 reqcnt = 0 |
877 reqcnt = 0 |
876 |
878 |
|
879 # search through remote branches |
|
880 # a 'branch' here is a linear segment of history, with four parts: |
|
881 # head, root, first parent, second parent |
|
882 # (a branch always has two parents (or none) by definition) |
877 unknown = remote.branches(unknown) |
883 unknown = remote.branches(unknown) |
878 while unknown: |
884 while unknown: |
879 r = [] |
885 r = [] |
880 while unknown: |
886 while unknown: |
881 n = unknown.pop(0) |
887 n = unknown.pop(0) |
897 if n[1] not in seen and n[1] not in fetch: |
903 if n[1] not in seen and n[1] not in fetch: |
898 if n[2] in m and n[3] in m: |
904 if n[2] in m and n[3] in m: |
899 self.ui.debug("found new changeset %s\n" % |
905 self.ui.debug("found new changeset %s\n" % |
900 short(n[1])) |
906 short(n[1])) |
901 fetch.append(n[1]) # earliest unknown |
907 fetch.append(n[1]) # earliest unknown |
|
908 base[n[2]] = 1 # latest known |
902 continue |
909 continue |
903 |
910 |
904 for a in n[2:4]: |
911 for a in n[2:4]: |
905 if a not in rep: |
912 if a not in rep: |
906 r.append(a) |
913 r.append(a) |
917 self.ui.debug("received %s:%s\n" % |
924 self.ui.debug("received %s:%s\n" % |
918 (short(b[0]), short(b[1]))) |
925 (short(b[0]), short(b[1]))) |
919 if b[0] not in m and b[0] not in seen: |
926 if b[0] not in m and b[0] not in seen: |
920 unknown.append(b) |
927 unknown.append(b) |
921 |
928 |
|
929 # do binary search on the branches we found |
922 while search: |
930 while search: |
923 n = search.pop(0) |
931 n = search.pop(0) |
924 reqcnt += 1 |
932 reqcnt += 1 |
925 l = remote.between([(n[0], n[1])])[0] |
933 l = remote.between([(n[0], n[1])])[0] |
926 l.append(n[1]) |
934 l.append(n[1]) |
931 if i in m: |
939 if i in m: |
932 if f <= 2: |
940 if f <= 2: |
933 self.ui.debug("found new branch changeset %s\n" % |
941 self.ui.debug("found new branch changeset %s\n" % |
934 short(p)) |
942 short(p)) |
935 fetch.append(p) |
943 fetch.append(p) |
|
944 base[i] = 1 |
936 else: |
945 else: |
937 self.ui.debug("narrowed branch search to %s:%s\n" |
946 self.ui.debug("narrowed branch search to %s:%s\n" |
938 % (short(p), short(i))) |
947 % (short(p), short(i))) |
939 search.append((p, i)) |
948 search.append((p, i)) |
940 break |
949 break |
941 p, f = i, f * 2 |
950 p, f = i, f * 2 |
942 |
951 |
|
952 # sanity check our fetch list |
943 for f in fetch: |
953 for f in fetch: |
944 if f in m: |
954 if f in m: |
945 raise RepoError("already have changeset " + short(f[:4])) |
955 raise RepoError("already have changeset " + short(f[:4])) |
946 |
956 |
947 if fetch == [nullid]: |
957 if base.keys() == [nullid]: |
948 self.ui.warn("warning: pulling from an unrelated repository!\n") |
958 self.ui.warn("warning: pulling from an unrelated repository!\n") |
949 |
959 |
950 self.ui.note("adding new changesets starting at " + |
960 self.ui.note("adding new changesets starting at " + |
951 " ".join([short(f) for f in fetch]) + "\n") |
961 " ".join([short(f) for f in fetch]) + "\n") |
952 |
962 |