Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/localrepo.py @ 1959:d53a18f592be
add -f/--force to pull, incoming, outgoing, to work on unrelated repo.
before this, push would not push from e.g. "hg" repo to "kernel" repo
but other commands worked. this was bad idea, could merge unrelated
projects by accident. i did this tonight.
now, all commands still work with unrelated repo but need
--force/-f. abort is default. this is safer.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Tue, 14 Mar 2006 22:58:14 -0800 |
parents | 65aff2ed61ae |
children | 72f7a335b955 |
comparison
equal
deleted
inserted
replaced
1954:34d0e2e559ff | 1959:d53a18f592be |
---|---|
783 | 783 |
784 r.append(l) | 784 r.append(l) |
785 | 785 |
786 return r | 786 return r |
787 | 787 |
788 def findincoming(self, remote, base=None, heads=None): | 788 def findincoming(self, remote, base=None, heads=None, force=False): |
789 m = self.changelog.nodemap | 789 m = self.changelog.nodemap |
790 search = [] | 790 search = [] |
791 fetch = {} | 791 fetch = {} |
792 seen = {} | 792 seen = {} |
793 seenbranch = {} | 793 seenbranch = {} |
896 for f in fetch.keys(): | 896 for f in fetch.keys(): |
897 if f in m: | 897 if f in m: |
898 raise repo.RepoError(_("already have changeset ") + short(f[:4])) | 898 raise repo.RepoError(_("already have changeset ") + short(f[:4])) |
899 | 899 |
900 if base.keys() == [nullid]: | 900 if base.keys() == [nullid]: |
901 self.ui.warn(_("warning: pulling from an unrelated repository!\n")) | 901 if force: |
902 self.ui.warn(_("warning: repository is unrelated\n")) | |
903 else: | |
904 raise util.Abort(_("repository is unrelated")) | |
902 | 905 |
903 self.ui.note(_("found new changesets starting at ") + | 906 self.ui.note(_("found new changesets starting at ") + |
904 " ".join([short(f) for f in fetch]) + "\n") | 907 " ".join([short(f) for f in fetch]) + "\n") |
905 | 908 |
906 self.ui.debug(_("%d total queries\n") % reqcnt) | 909 self.ui.debug(_("%d total queries\n") % reqcnt) |
907 | 910 |
908 return fetch.keys() | 911 return fetch.keys() |
909 | 912 |
910 def findoutgoing(self, remote, base=None, heads=None): | 913 def findoutgoing(self, remote, base=None, heads=None, force=False): |
911 if base == None: | 914 if base == None: |
912 base = {} | 915 base = {} |
913 self.findincoming(remote, base, heads) | 916 self.findincoming(remote, base, heads, force=force) |
914 | 917 |
915 self.ui.debug(_("common changesets up to ") | 918 self.ui.debug(_("common changesets up to ") |
916 + " ".join(map(short, base.keys())) + "\n") | 919 + " ".join(map(short, base.keys())) + "\n") |
917 | 920 |
918 remain = dict.fromkeys(self.changelog.nodemap) | 921 remain = dict.fromkeys(self.changelog.nodemap) |
935 subset.append(n) | 938 subset.append(n) |
936 | 939 |
937 # this is the set of all roots we have to push | 940 # this is the set of all roots we have to push |
938 return subset | 941 return subset |
939 | 942 |
940 def pull(self, remote, heads=None): | 943 def pull(self, remote, heads=None, force=False): |
941 l = self.lock() | 944 l = self.lock() |
942 | 945 |
943 # if we have an empty repo, fetch everything | 946 # if we have an empty repo, fetch everything |
944 if self.changelog.tip() == nullid: | 947 if self.changelog.tip() == nullid: |
945 self.ui.status(_("requesting all changes\n")) | 948 self.ui.status(_("requesting all changes\n")) |
946 fetch = [nullid] | 949 fetch = [nullid] |
947 else: | 950 else: |
948 fetch = self.findincoming(remote) | 951 fetch = self.findincoming(remote, force=force) |
949 | 952 |
950 if not fetch: | 953 if not fetch: |
951 self.ui.status(_("no changes found\n")) | 954 self.ui.status(_("no changes found\n")) |
952 return 1 | 955 return 1 |
953 | 956 |
960 def push(self, remote, force=False, revs=None): | 963 def push(self, remote, force=False, revs=None): |
961 lock = remote.lock() | 964 lock = remote.lock() |
962 | 965 |
963 base = {} | 966 base = {} |
964 heads = remote.heads() | 967 heads = remote.heads() |
965 inc = self.findincoming(remote, base, heads) | 968 inc = self.findincoming(remote, base, heads, force=force) |
966 if not force and inc: | 969 if not force and inc: |
967 self.ui.warn(_("abort: unsynced remote changes!\n")) | 970 self.ui.warn(_("abort: unsynced remote changes!\n")) |
968 self.ui.status(_("(did you forget to sync? use push -f to force)\n")) | 971 self.ui.status(_("(did you forget to sync? use push -f to force)\n")) |
969 return 1 | 972 return 1 |
970 | 973 |