mercurial/hg.py
changeset 83 9fd5b35cfc45
parent 79 837d473d54d5
child 85 58a1a0425c9b
equal deleted inserted replaced
82:7ed96baa7caa 83:9fd5b35cfc45
   466 
   466 
   467         # check in files
   467         # check in files
   468         new = {}
   468         new = {}
   469         linkrev = self.changelog.count()
   469         linkrev = self.changelog.count()
   470         for f in update:
   470         for f in update:
       
   471             self.ui.note(f + "\n")
   471             try:
   472             try:
   472                 t = file(f).read()
   473                 t = file(f).read()
   473             except IOError:
   474             except IOError:
   474                 remove.append(f)
   475                 remove.append(f)
   475                 continue
   476                 continue
   513 
   514 
   514         l = mmap.keys()
   515         l = mmap.keys()
   515         l.sort()
   516         l.sort()
   516         stats = []
   517         stats = []
   517         for f in l:
   518         for f in l:
       
   519             self.ui.note(f + "\n")
   518             r = self.file(f)
   520             r = self.file(f)
   519             t = r.revision(mmap[f])
   521             t = r.revision(mmap[f])
   520             try:
   522             try:
   521                 file(f, "w").write(t)
   523                 file(f, "w").write(t)
   522             except:
   524             except:
   654 
   656 
   655         return nl
   657         return nl
   656 
   658 
   657     def getchangegroup(self, remote):
   659     def getchangegroup(self, remote):
   658         tip = remote.branches([])[0]
   660         tip = remote.branches([])[0]
       
   661         self.ui.debug("remote tip branch is %s:%s\n" %
       
   662                       (short(tip[0]), short(tip[1])))
   659         m = self.changelog.nodemap
   663         m = self.changelog.nodemap
   660         unknown = [tip]
   664         unknown = [tip]
   661         search = []
   665         search = []
   662         fetch = []
   666         fetch = []
   663 
   667 
   664         if tip[0] in m:
   668         if tip[0] in m:
       
   669             self.ui.note("nothing to do!\n")
   665             return None
   670             return None
   666 
   671 
   667         while unknown:
   672         while unknown:
   668             n = unknown.pop(0)
   673             n = unknown.pop(0)
   669             if n == nullid: break
   674             if n == nullid: break
   670             if n[1] and n[1] in m: # do we know the base?
   675             if n[1] and n[1] in m: # do we know the base?
       
   676                 self.ui.debug("found incomplete branch %s\n" % short(n[1]))
   671                 search.append(n) # schedule branch range for scanning
   677                 search.append(n) # schedule branch range for scanning
   672             else:
   678             else:
   673                 for b in remote.branches([n[2], n[3]]):
   679                 for b in remote.branches([n[2], n[3]]):
   674                     if b[0] in m:
   680                     if b[0] in m:
   675                         if n[1] not in fetch:
   681                         if n[1] not in fetch:
       
   682                             self.ui.debug("found new changeset %s\n" %
       
   683                                           short(n[1]))
   676                             fetch.append(n[1]) # earliest unknown
   684                             fetch.append(n[1]) # earliest unknown
   677                     else:
   685                     else:
   678                         unknown.append(b)
   686                         unknown.append(b)
   679   
   687   
   680         while search:
   688         while search:
   683             p = n[0]
   691             p = n[0]
   684             f = 1
   692             f = 1
   685             for i in l + [n[1]]:
   693             for i in l + [n[1]]:
   686                 if i in m:
   694                 if i in m:
   687                     if f <= 4:
   695                     if f <= 4:
       
   696                         self.ui.debug("found new branch changeset %s\n" %
       
   697                                           short(p))
   688                         fetch.append(p)
   698                         fetch.append(p)
   689                     else:
   699                     else:
       
   700                         self.ui.debug("narrowed branch search to %s:%s\n"
       
   701                                       % (short(p), short(i)))
   690                         search.append((p, i))
   702                         search.append((p, i))
   691                     break
   703                     break
   692                 p, f = i, f * 2
   704                 p, f = i, f * 2
   693 
   705 
   694         for f in fetch:
   706         for f in fetch:
   695             if f in m:
   707             if f in m:
   696                 raise "already have", hex(f[:4])
   708                 raise "already have", short(f[:4])
       
   709 
       
   710         self.ui.note("merging new changesets starting at " +
       
   711                      " ".join([short(f) for f in fetch]) + "\n")
   697 
   712 
   698         return remote.changegroup(fetch)
   713         return remote.changegroup(fetch)
   699     
   714     
   700     def changegroup(self, basenodes):
   715     def changegroup(self, basenodes):
   701         nodes = self.newer(basenodes)
   716         nodes = self.newer(basenodes)
   750             return source.read(l - 4 + add)
   765             return source.read(l - 4 + add)
   751 
   766 
   752         tr = self.transaction()
   767         tr = self.transaction()
   753         simple = True
   768         simple = True
   754 
   769 
   755         print "merging changesets"
   770         self.ui.status("merging changesets\n")
   756         # pull off the changeset group
   771         # pull off the changeset group
   757         csg = getchunk()
   772         csg = getchunk()
   758         co = self.changelog.tip()
   773         co = self.changelog.tip()
   759         cn = self.changelog.addgroup(csg, lambda x: self.changelog.count(), tr)
   774         cn = self.changelog.addgroup(csg, lambda x: self.changelog.count(), tr)
   760 
   775 
   761         print "merging manifests"
   776         self.ui.status("merging manifests\n")
   762         # pull off the manifest group
   777         # pull off the manifest group
   763         mfg = getchunk()
   778         mfg = getchunk()
   764         mo = self.manifest.tip()
   779         mo = self.manifest.tip()
   765         mm = self.manifest.addgroup(mfg, lambda x: self.changelog.rev(x), tr)
   780         mm = self.manifest.addgroup(mfg, lambda x: self.changelog.rev(x), tr)
   766 
   781 
   768         if self.changelog.ancestor(co, cn) != co:
   783         if self.changelog.ancestor(co, cn) != co:
   769             simple = False
   784             simple = False
   770             resolverev = self.changelog.count()
   785             resolverev = self.changelog.count()
   771 
   786 
   772         # process the files
   787         # process the files
   773         print "merging files"
   788         self.ui.status("merging files\n")
   774         new = {}
   789         new = {}
   775         while 1:
   790         while 1:
   776             f = getchunk(4)
   791             f = getchunk(4)
   777             if not f: break
   792             if not f: break
   778             fg = getchunk()
   793             fg = getchunk()
   846     def __init__(self, ui, path):
   861     def __init__(self, ui, path):
   847         self.url = path.replace("hg://", "http://", 1)
   862         self.url = path.replace("hg://", "http://", 1)
   848         self.ui = ui
   863         self.ui = ui
   849 
   864 
   850     def do_cmd(self, cmd, **args):
   865     def do_cmd(self, cmd, **args):
       
   866         self.ui.debug("sending %s command\n" % cmd)
   851         q = {"cmd": cmd}
   867         q = {"cmd": cmd}
   852         q.update(args)
   868         q.update(args)
   853         qs = urllib.urlencode(q)
   869         qs = urllib.urlencode(q)
   854         cu = "%s?%s" % (self.url, qs)
   870         cu = "%s?%s" % (self.url, qs)
   855         return urllib.urlopen(cu)
   871         return urllib.urlopen(cu)
   882         return remoterepository(ui, path)
   898         return remoterepository(ui, path)
   883     else:
   899     else:
   884         return localrepository(ui, path, create)
   900         return localrepository(ui, path, create)
   885 
   901 
   886 class ui:
   902 class ui:
   887     def __init__(self, verbose=False, debug=False):
   903     def __init__(self, verbose=False, debug=False, quiet=False):
   888         self.verbose = verbose
   904         self.quiet = quiet and not verbose and not debug
       
   905         self.verbose = verbose or debug
       
   906         self.debugflag = debug
   889     def write(self, *args):
   907     def write(self, *args):
   890         for a in args:
   908         for a in args:
   891             sys.stdout.write(str(a))
   909             sys.stdout.write(str(a))
   892     def prompt(self, msg, pat):
   910     def prompt(self, msg, pat):
   893         while 1:
   911         while 1:
   894             sys.stdout.write(msg)
   912             sys.stdout.write(msg)
   895             r = sys.stdin.readline()[:-1]
   913             r = sys.stdin.readline()[:-1]
   896             if re.match(pat, r):
   914             if re.match(pat, r):
   897                 return r
   915                 return r
   898     def status(self, *msg):
   916     def status(self, *msg):
   899         self.write(*msg)
   917         if not self.quiet: self.write(*msg)
   900     def warn(self, msg):
   918     def warn(self, msg):
   901         self.write(*msg)
   919         self.write(*msg)
   902     def note(self, msg):
   920     def note(self, msg):
   903         if self.verbose: self.write(*msg)
   921         if self.verbose: self.write(*msg)
   904     def debug(self, msg):
   922     def debug(self, msg):
   905         if self.debug: self.write(*msg)
   923         if self.debugflag: self.write(*msg)
   906     def edit(self, text):
   924     def edit(self, text):
   907         (fd, name) = tempfile.mkstemp("hg")
   925         (fd, name) = tempfile.mkstemp("hg")
   908         f = os.fdopen(fd, "w")
   926         f = os.fdopen(fd, "w")
   909         f.write(text)
   927         f.write(text)
   910         f.close()
   928         f.close()