mercurial/commands.py
changeset 762 312b4a10d862
parent 761 0fb498458905
child 763 84f9ac74cc30
equal deleted inserted replaced
761:0fb498458905 762:312b4a10d862
   458 
   458 
   459     d.close()
   459     d.close()
   460 
   460 
   461 def commit(ui, repo, *files, **opts):
   461 def commit(ui, repo, *files, **opts):
   462     """commit the specified files or all outstanding changes"""
   462     """commit the specified files or all outstanding changes"""
   463     text = opts['message'] or opts['text']
   463     message = opts['message'] or opts['text']
   464     logfile = opts['logfile']
   464     logfile = opts['logfile']
   465     if not text and logfile:
   465     if not message and logfile:
   466         try:
   466         try:
   467             text = open(logfile).read()
   467             message = open(logfile).read()
   468         except IOError, why:
   468         except IOError, why:
   469             ui.warn("Can't read commit text %s: %s\n" % (logfile, why))
   469             ui.warn("Can't read commit message %s: %s\n" % (logfile, why))
   470 
   470 
   471     if opts['addremove']:
   471     if opts['addremove']:
   472         addremove(ui, repo, *files)
   472         addremove(ui, repo, *files)
   473     repo.commit(relpath(repo, files), text, opts['user'], opts['date'])
   473     repo.commit(relpath(repo, files), message, opts['user'], opts['date'])
   474 
   474 
   475 def copy(ui, repo, source, dest):
   475 def copy(ui, repo, source, dest):
   476     """mark a file as copied or renamed for the next commit"""
   476     """mark a file as copied or renamed for the next commit"""
   477     return repo.copy(*relpath(repo, (source, dest)))
   477     return repo.copy(*relpath(repo, (source, dest)))
   478 
   478 
   635 
   635 
   636     for patch in patches:
   636     for patch in patches:
   637         ui.status("applying %s\n" % patch)
   637         ui.status("applying %s\n" % patch)
   638         pf = os.path.join(d, patch)
   638         pf = os.path.join(d, patch)
   639 
   639 
   640         text = []
   640         message = []
   641         user = None
   641         user = None
   642         hgpatch = False
   642         hgpatch = False
   643         for line in file(pf):
   643         for line in file(pf):
   644             line = line.rstrip()
   644             line = line.rstrip()
   645             if line.startswith("--- ") or line.startswith("diff -r"):
   645             if line.startswith("--- ") or line.startswith("diff -r"):
   648                 # parse values when importing the result of an hg export
   648                 # parse values when importing the result of an hg export
   649                 if line.startswith("# User "):
   649                 if line.startswith("# User "):
   650                     user = line[7:]
   650                     user = line[7:]
   651                     ui.debug('User: %s\n' % user)
   651                     ui.debug('User: %s\n' % user)
   652                 elif not line.startswith("# ") and line:
   652                 elif not line.startswith("# ") and line:
   653                     text.append(line)
   653                     message.append(line)
   654                     hgpatch = False
   654                     hgpatch = False
   655             elif line == '# HG changeset patch':
   655             elif line == '# HG changeset patch':
   656                 hgpatch = True
   656                 hgpatch = True
   657             else:
   657             else:
   658                 text.append(line)
   658                 message.append(line)
   659 
   659 
   660         # make sure text isn't empty
   660         # make sure message isn't empty
   661         if not text:
   661         if not message:
   662             text = "imported patch %s\n" % patch
   662             message = "imported patch %s\n" % patch
   663         else:
   663         else:
   664             text = "%s\n" % '\n'.join(text)
   664             message = "%s\n" % '\n'.join(message)
   665         ui.debug('text:\n%s\n' % text)
   665         ui.debug('message:\n%s\n' % message)
   666 
   666 
   667         f = os.popen("patch -p%d < %s" % (strip, pf))
   667         f = os.popen("patch -p%d < %s" % (strip, pf))
   668         files = []
   668         files = []
   669         for l in f.read().splitlines():
   669         for l in f.read().splitlines():
   670             l.rstrip('\r\n');
   670             l.rstrip('\r\n');
   677         if patcherr:
   677         if patcherr:
   678             raise Abort("patch failed")
   678             raise Abort("patch failed")
   679 
   679 
   680         if len(files) > 0:
   680         if len(files) > 0:
   681             addremove(ui, repo, *files)
   681             addremove(ui, repo, *files)
   682         repo.commit(files, text, user)
   682         repo.commit(files, message, user)
   683 
   683 
   684 def init(ui, source=None):
   684 def init(ui, source=None):
   685     """create a new repository in the current directory"""
   685     """create a new repository in the current directory"""
   686 
   686 
   687     if source:
   687     if source:
   789     r = repo.push(other)
   789     r = repo.push(other)
   790     return r
   790     return r
   791 
   791 
   792 def rawcommit(ui, repo, *flist, **rc):
   792 def rawcommit(ui, repo, *flist, **rc):
   793     "raw commit interface"
   793     "raw commit interface"
   794 
   794     message = rc['message'] or rc['text']
   795     text = rc['text']
   795     if not message and rc['logfile']:
   796     if not text and rc['logfile']:
       
   797         try:
   796         try:
   798             text = open(rc['logfile']).read()
   797             message = open(rc['logfile']).read()
   799         except IOError:
   798         except IOError:
   800             pass
   799             pass
   801     if not text and not rc['logfile']:
   800     if not message and not rc['logfile']:
   802         ui.warn("abort: missing commit text\n")
   801         ui.warn("abort: missing commit message\n")
   803         return 1
   802         return 1
   804 
   803 
   805     files = relpath(repo, list(flist))
   804     files = relpath(repo, list(flist))
   806     if rc['files']:
   805     if rc['files']:
   807         files += open(rc['files']).read().splitlines()
   806         files += open(rc['files']).read().splitlines()
   808 
   807 
   809     rc['parent'] = map(repo.lookup, rc['parent'])
   808     rc['parent'] = map(repo.lookup, rc['parent'])
   810 
   809 
   811     repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent'])
   810     repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent'])
   812 
   811 
   813 def recover(ui, repo):
   812 def recover(ui, repo):
   814     """roll back an interrupted transaction"""
   813     """roll back an interrupted transaction"""
   815     repo.recover()
   814     repo.recover()
   816 
   815 
   986     for f in u:
   985     for f in u:
   987         ui.write("? ", f, "\n")
   986         ui.write("? ", f, "\n")
   988 
   987 
   989 def tag(ui, repo, name, rev=None, **opts):
   988 def tag(ui, repo, name, rev=None, **opts):
   990     """add a tag for the current tip or a given revision"""
   989     """add a tag for the current tip or a given revision"""
   991 
       
   992     if name == "tip":
   990     if name == "tip":
   993         ui.warn("abort: 'tip' is a reserved name!\n")
   991         ui.warn("abort: 'tip' is a reserved name!\n")
   994         return -1
   992         return -1
   995     if rev:
   993     if rev:
   996         r = hg.hex(repo.lookup(rev))
   994         r = hg.hex(repo.lookup(rev))
  1014 
  1012 
  1015     repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name))
  1013     repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name))
  1016     if repo.dirstate.state(".hgtags") == '?':
  1014     if repo.dirstate.state(".hgtags") == '?':
  1017         repo.add([".hgtags"])
  1015         repo.add([".hgtags"])
  1018 
  1016 
  1019     if not opts['text']:
  1017     message = (opts['message'] or opts['text'] or
  1020         opts['text'] = "Added tag %s for changeset %s" % (name, r)
  1018                "Added tag %s for changeset %s" % (name, r))
  1021 
  1019     repo.commit([".hgtags"], message, opts['user'], opts['date'])
  1022     repo.commit([".hgtags"], opts['text'], opts['user'], opts['date'])
       
  1023 
  1020 
  1024 def tags(ui, repo):
  1021 def tags(ui, repo):
  1025     """list repository tags"""
  1022     """list repository tags"""
  1026 
  1023 
  1027     l = repo.tagslist()
  1024     l = repo.tagslist()
  1101     "^commit|ci":
  1098     "^commit|ci":
  1102         (commit,
  1099         (commit,
  1103          [('A', 'addremove', None, 'run add/remove during commit'),
  1100          [('A', 'addremove', None, 'run add/remove during commit'),
  1104           ('m', 'message', "", 'commit message'),
  1101           ('m', 'message', "", 'commit message'),
  1105           ('t', 'text', "", 'commit message (deprecated: use -m)'),
  1102           ('t', 'text', "", 'commit message (deprecated: use -m)'),
  1106           ('l', 'logfile', "", 'commit text file'),
  1103           ('l', 'logfile', "", 'commit message file'),
  1107           ('d', 'date', "", 'date code'),
  1104           ('d', 'date', "", 'date code'),
  1108           ('u', 'user', "", 'user')],
  1105           ('u', 'user', "", 'user')],
  1109          'hg commit [OPTION]... [FILE]...'),
  1106          'hg commit [OPTION]... [FILE]...'),
  1110     "copy": (copy, [], 'hg copy SOURCE DEST'),
  1107     "copy": (copy, [], 'hg copy SOURCE DEST'),
  1111     "debugcheckstate": (debugcheckstate, [], 'debugcheckstate'),
  1108     "debugcheckstate": (debugcheckstate, [], 'debugcheckstate'),
  1156         (rawcommit,
  1153         (rawcommit,
  1157          [('p', 'parent', [], 'parent'),
  1154          [('p', 'parent', [], 'parent'),
  1158           ('d', 'date', "", 'date code'),
  1155           ('d', 'date', "", 'date code'),
  1159           ('u', 'user', "", 'user'),
  1156           ('u', 'user', "", 'user'),
  1160           ('F', 'files', "", 'file list'),
  1157           ('F', 'files', "", 'file list'),
  1161           ('m', 'text', "", 'commit message'),
  1158           ('m', 'message', "", 'commit message'),
  1162           ('t', 'text', "", 'commit message (deprecated)'),
  1159           ('t', 'text', "", 'commit message (deprecated: use -m)'),
  1163           ('l', 'logfile', "", 'commit text file')],
  1160           ('l', 'logfile', "", 'commit message file')],
  1164          'hg rawcommit [OPTION]... [FILE]...'),
  1161          'hg rawcommit [OPTION]... [FILE]...'),
  1165     "recover": (recover, [], "hg recover"),
  1162     "recover": (recover, [], "hg recover"),
  1166     "^remove|rm": (remove, [], "hg remove FILE..."),
  1163     "^remove|rm": (remove, [], "hg remove FILE..."),
  1167     "^revert":
  1164     "^revert":
  1168         (revert,
  1165         (revert,
  1185                  ('X', 'exclude', [], 'exclude path from search')],
  1182                  ('X', 'exclude', [], 'exclude path from search')],
  1186                 'hg status [FILE]...'),
  1183                 'hg status [FILE]...'),
  1187     "tag":
  1184     "tag":
  1188         (tag,
  1185         (tag,
  1189          [('l', 'local', None, 'make the tag local'),
  1186          [('l', 'local', None, 'make the tag local'),
  1190           ('m', 'text', "", 'commit message'),
  1187           ('m', 'message', "", 'commit message'),
  1191           ('t', 'text', "", 'commit message (deprecated)'),
  1188           ('t', 'text', "", 'commit message (deprecated: use -m)'),
  1192           ('d', 'date', "", 'date code'),
  1189           ('d', 'date', "", 'date code'),
  1193           ('u', 'user', "", 'user')],
  1190           ('u', 'user', "", 'user')],
  1194          'hg tag [OPTION]... NAME [REV]'),
  1191          'hg tag [OPTION]... NAME [REV]'),
  1195     "tags": (tags, [], 'hg tags'),
  1192     "tags": (tags, [], 'hg tags'),
  1196     "tip": (tip, [], 'hg tip'),
  1193     "tip": (tip, [], 'hg tip'),