mercurial/commands.py
changeset 500 ebc4714a7632
parent 499 81c563a254be
child 503 c6a2e41c8c60
equal deleted inserted replaced
499:81c563a254be 500:ebc4714a7632
   232             f = name.find('@')
   232             f = name.find('@')
   233             if f >= 0:
   233             if f >= 0:
   234                 name = name[:f]
   234                 name = name[:f]
   235             bcache[rev] = name
   235             bcache[rev] = name
   236             return name
   236             return name
   237     
   237 
   238     bcache = {}
   238     bcache = {}
   239     opmap = [['user', getname], ['number', str], ['changeset', getnode]]
   239     opmap = [['user', getname], ['number', str], ['changeset', getnode]]
   240     if not ops['user'] and not ops['changeset']:
   240     if not ops['user'] and not ops['changeset']:
   241         ops['number'] = 1
   241         ops['number'] = 1
   242 
   242 
   271     for name, path in ui.configitems("paths"):
   271     for name, path in ui.configitems("paths"):
   272         paths[name] = path
   272         paths[name] = path
   273 
   273 
   274     if source in paths: source = paths[source]
   274     if source in paths: source = paths[source]
   275 
   275 
       
   276     created = False
       
   277 
   276     if dest is None:
   278     if dest is None:
   277         dest = os.getcwd()
   279         dest = os.getcwd()
   278     elif not os.path.exists(dest):
   280     elif not os.path.exists(dest):
   279         os.makedirs(dest)
   281         os.mkdir(dest)
   280 
   282         created = True
   281     link = 0
   283 
   282     if not source.startswith("http://"):
   284     try:
   283         source = os.path.realpath(source)
   285         dest = os.path.realpath(dest)
   284         d1 = os.stat(dest).st_dev
   286 
   285         d2 = os.stat(source).st_dev
   287         link = 0
   286         if d1 == d2: link = 1
   288         if not source.startswith("http://"):
   287 
   289             source = os.path.realpath(source)
   288     os.chdir(dest)
   290             d1 = os.stat(dest).st_dev
   289 
   291             d2 = os.stat(source).st_dev
   290     if link:
   292             if d1 == d2: link = 1
   291         ui.debug("copying by hardlink\n")
   293 
   292         os.system("cp -al %s/.hg .hg" % source)
   294         os.chdir(dest)
   293         try:
   295 
   294             os.remove(".hg/dirstate")
   296         if link:
   295         except: pass
   297             ui.debug("copying by hardlink\n")
   296 
   298             os.system("cp -al %s/.hg .hg" % source)
   297         repo = hg.repository(ui, ".")
   299             try:
   298 
   300                 os.remove(".hg/dirstate")
   299     else:
   301             except: pass
   300         repo = hg.repository(ui, ".", create=1)
   302 
   301         other = hg.repository(ui, source)
   303             repo = hg.repository(ui, ".")
   302         cg = repo.getchangegroup(other)
   304 
   303         repo.addchangegroup(cg)
   305         else:
   304 
   306             repo = hg.repository(ui, ".", create=1)
   305     f = repo.opener("hgrc", "w")
   307             other = hg.repository(ui, source)
   306     f.write("[paths]\n")
   308             cg = repo.getchangegroup(other)
   307     f.write("default = %s\n" % source)
   309             repo.addchangegroup(cg)
   308 
   310 
   309     if not opts['no-update']:
   311         f = repo.opener("hgrc", "w")
   310         update(ui, repo)
   312         f.write("[paths]\n")
   311     
   313         f.write("default = %s\n" % source)
       
   314 
       
   315         if not opts['no-update']:
       
   316             update(ui, repo)
       
   317     except:
       
   318         if created:
       
   319             import shutil
       
   320             shutil.rmtree(dest, True)
       
   321         raise
       
   322 
   312 def commit(ui, repo, *files, **opts):
   323 def commit(ui, repo, *files, **opts):
   313     """commit the specified files or all outstanding changes"""
   324     """commit the specified files or all outstanding changes"""
   314     text = opts['text']
   325     text = opts['text']
   315     if not text and opts['logfile']:
   326     if not text and opts['logfile']:
   316         try: text = open(opts['logfile']).read()
   327         try: text = open(opts['logfile']).read()
   457         psyco.full()
   468         psyco.full()
   458     except:
   469     except:
   459         pass
   470         pass
   460 
   471 
   461     patches = (patch1,) + patches
   472     patches = (patch1,) + patches
   462     
   473 
   463     d = opts["base"]
   474     d = opts["base"]
   464     strip = opts["strip"]
   475     strip = opts["strip"]
   465 
   476 
   466     for patch in patches:
   477     for patch in patches:
   467         ui.status("applying %s\n" % patch)
   478         ui.status("applying %s\n" % patch)
   541 
   552 
   542     if source in paths:
   553     if source in paths:
   543         source = paths[source]
   554         source = paths[source]
   544 
   555 
   545     ui.status('pulling from %s\n' % (source))
   556     ui.status('pulling from %s\n' % (source))
   546     
   557 
   547     other = hg.repository(ui, source)
   558     other = hg.repository(ui, source)
   548     cg = repo.getchangegroup(other)
   559     cg = repo.getchangegroup(other)
   549     r = repo.addchangegroup(cg)
   560     r = repo.addchangegroup(cg)
   550     if cg and not r:
   561     if cg and not r:
   551         if opts['update']:
   562         if opts['update']:
   560     paths = {}
   571     paths = {}
   561     for name, path in ui.configitems("paths"):
   572     for name, path in ui.configitems("paths"):
   562         paths[name] = path
   573         paths[name] = path
   563 
   574 
   564     if dest in paths: dest = paths[dest]
   575     if dest in paths: dest = paths[dest]
   565     
   576 
   566     if not dest.startswith("ssh://"):
   577     if not dest.startswith("ssh://"):
   567         ui.warn("abort: can only push to ssh:// destinations currently\n")
   578         ui.warn("abort: can only push to ssh:// destinations currently\n")
   568         return 1
   579         return 1
   569 
   580 
   570     m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', dest)
   581     m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', dest)
   605     files = relpath(repo, list(flist))
   616     files = relpath(repo, list(flist))
   606     if rc['files']:
   617     if rc['files']:
   607         files += open(rc['files']).read().splitlines()
   618         files += open(rc['files']).read().splitlines()
   608 
   619 
   609     rc['parent'] = map(repo.lookup, rc['parent'])
   620     rc['parent'] = map(repo.lookup, rc['parent'])
   610     
   621 
   611     repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent'])
   622     repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent'])
   612  
   623 
   613 def recover(ui, repo):
   624 def recover(ui, repo):
   614     """roll back an interrupted transaction"""
   625     """roll back an interrupted transaction"""
   615     repo.recover()
   626     repo.recover()
   616 
   627 
   617 def remove(ui, repo, file, *files):
   628 def remove(ui, repo, file, *files):
   624 
   635 
   625 def serve(ui, repo, **opts):
   636 def serve(ui, repo, **opts):
   626     """export the repository via HTTP"""
   637     """export the repository via HTTP"""
   627     hgweb.server(repo.root, opts["name"], opts["templates"],
   638     hgweb.server(repo.root, opts["name"], opts["templates"],
   628                  opts["address"], opts["port"])
   639                  opts["address"], opts["port"])
   629     
   640 
   630 def status(ui, repo):
   641 def status(ui, repo):
   631     '''show changed files in the working directory
   642     '''show changed files in the working directory
   632 
   643 
   633     C = changed
   644     C = changed
   634     A = added
   645     A = added
   643     for f in d: print "R", f
   654     for f in d: print "R", f
   644     for f in u: print "?", f
   655     for f in u: print "?", f
   645 
   656 
   646 def tag(ui, repo, name, rev = None, **opts):
   657 def tag(ui, repo, name, rev = None, **opts):
   647     """add a tag for the current tip or a given revision"""
   658     """add a tag for the current tip or a given revision"""
   648     
   659 
   649     if name == "tip":
   660     if name == "tip":
   650 	ui.warn("abort: 'tip' is a reserved name!\n")
   661 	ui.warn("abort: 'tip' is a reserved name!\n")
   651 	return -1
   662 	return -1
   652 
   663 
   653     (c, a, d, u) = repo.diffdir(repo.root)
   664     (c, a, d, u) = repo.diffdir(repo.root)
   753                      "hg import [options] <patches>"),
   764                      "hg import [options] <patches>"),
   754     "init": (init, [], 'hg init'),
   765     "init": (init, [], 'hg init'),
   755     "log": (log, [], 'hg log <file>'),
   766     "log": (log, [], 'hg log <file>'),
   756     "manifest": (manifest, [], 'hg manifest [rev]'),
   767     "manifest": (manifest, [], 'hg manifest [rev]'),
   757     "parents": (parents, [], 'hg parents [node]'),
   768     "parents": (parents, [], 'hg parents [node]'),
   758     "pull": (pull, 
   769     "pull": (pull,
   759                   [('u', 'update', None, 'update working directory')],
   770                   [('u', 'update', None, 'update working directory')],
   760 		  'hg pull [options] [source]'),
   771 		  'hg pull [options] [source]'),
   761     "push": (push, [], 'hg push <destination>'),
   772     "push": (push, [], 'hg push <destination>'),
   762     "rawcommit": (rawcommit,
   773     "rawcommit": (rawcommit,
   763                   [('p', 'parent', [], 'parent'),
   774                   [('p', 'parent', [], 'parent'),