Mercurial > hg
changeset 5034:c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Tue, 31 Jul 2007 16:28:05 -0700 |
parents | 1b07668b8cc3 |
children | a675f6d5d069 |
files | mercurial/cmdutil.py mercurial/commands.py |
diffstat | 2 files changed, 48 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Mon Jul 30 20:49:08 2007 -0700 +++ b/mercurial/cmdutil.py Tue Jul 31 16:28:05 2007 -0700 @@ -8,6 +8,7 @@ from node import * from i18n import _ import os, sys, atexit, signal, pdb, traceback, socket, errno, shlex +import bisect, stat import mdiff, bdiff, util, templater, patch, commands, hg, lock, time import fancyopts, revlog, version, extensions, hook @@ -1275,3 +1276,45 @@ for rev in nrevs: yield 'iter', rev, None return iterate(), matchfn + +def commit(ui, repo, commitfunc, pats, opts): + '''commit the specified files or all outstanding changes''' + message = logmessage(opts) + + if opts['addremove']: + addremove(repo, pats, opts) + fns, match, anypats = matchpats(repo, pats, opts) + if pats: + status = repo.status(files=fns, match=match) + modified, added, removed, deleted, unknown = status[:5] + files = modified + added + removed + slist = None + for f in fns: + if f == '.': + continue + if f not in files: + rf = repo.wjoin(f) + try: + mode = os.lstat(rf)[stat.ST_MODE] + except OSError: + raise util.Abort(_("file %s not found!") % rf) + if stat.S_ISDIR(mode): + name = f + '/' + if slist is None: + slist = list(files) + slist.sort() + i = bisect.bisect(slist, name) + if i >= len(slist) or not slist[i].startswith(name): + raise util.Abort(_("no match under directory %s!") + % rf) + elif not (stat.S_ISREG(mode) or stat.S_ISLNK(mode)): + raise util.Abort(_("can't commit %s: " + "unsupported file type!") % rf) + elif f not in repo.dirstate: + raise util.Abort(_("file %s not tracked!") % rf) + else: + files = [] + try: + return commitfunc(ui, repo, files, message, match, opts) + except ValueError, inst: + raise util.Abort(str(inst))
--- a/mercurial/commands.py Mon Jul 30 20:49:08 2007 -0700 +++ b/mercurial/commands.py Tue Jul 31 16:28:05 2007 -0700 @@ -8,7 +8,7 @@ import demandimport; demandimport.enable() from node import * from i18n import _ -import bisect, os, re, sys, urllib, stat +import os, re, sys, urllib import ui, hg, util, revlog, bundlerepo, extensions import difflib, patch, time, help, mdiff, tempfile import errno, version, socket @@ -428,46 +428,10 @@ If no commit message is specified, the editor configured in your hgrc or in the EDITOR environment variable is started to enter a message. """ - message = cmdutil.logmessage(opts) - - if opts['addremove']: - cmdutil.addremove(repo, pats, opts) - fns, match, anypats = cmdutil.matchpats(repo, pats, opts) - if pats: - status = repo.status(files=fns, match=match) - modified, added, removed, deleted, unknown = status[:5] - files = modified + added + removed - slist = None - for f in fns: - if f == '.': - continue - if f not in files: - rf = repo.wjoin(f) - try: - mode = os.lstat(rf)[stat.ST_MODE] - except OSError: - raise util.Abort(_("file %s not found!") % rf) - if stat.S_ISDIR(mode): - name = f + '/' - if slist is None: - slist = list(files) - slist.sort() - i = bisect.bisect(slist, name) - if i >= len(slist) or not slist[i].startswith(name): - raise util.Abort(_("no match under directory %s!") - % rf) - elif not (stat.S_ISREG(mode) or stat.S_ISLNK(mode)): - raise util.Abort(_("can't commit %s: " - "unsupported file type!") % rf) - elif f not in repo.dirstate: - raise util.Abort(_("file %s not tracked!") % rf) - else: - files = [] - try: - repo.commit(files, message, opts['user'], opts['date'], match, - force_editor=opts.get('force_editor')) - except ValueError, inst: - raise util.Abort(str(inst)) + def commitfunc(ui, repo, files, message, match, opts): + return repo.commit(files, message, opts['user'], opts['date'], match, + force_editor=opts.get('force_editor')) + cmdutil.commit(ui, repo, commitfunc, pats, opts) def docopy(ui, repo, pats, opts): # called with the repo lock held