comparison mercurial/cmdutil.py @ 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 4106dde15aed
children d5126a0172ba
comparison
equal deleted inserted replaced
5033:1b07668b8cc3 5034:c0417a319e39
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 from node import * 8 from node import *
9 from i18n import _ 9 from i18n import _
10 import os, sys, atexit, signal, pdb, traceback, socket, errno, shlex 10 import os, sys, atexit, signal, pdb, traceback, socket, errno, shlex
11 import bisect, stat
11 import mdiff, bdiff, util, templater, patch, commands, hg, lock, time 12 import mdiff, bdiff, util, templater, patch, commands, hg, lock, time
12 import fancyopts, revlog, version, extensions, hook 13 import fancyopts, revlog, version, extensions, hook
13 14
14 revrangesep = ':' 15 revrangesep = ':'
15 16
1273 fns = fns_generator() 1274 fns = fns_generator()
1274 yield 'add', rev, fns 1275 yield 'add', rev, fns
1275 for rev in nrevs: 1276 for rev in nrevs:
1276 yield 'iter', rev, None 1277 yield 'iter', rev, None
1277 return iterate(), matchfn 1278 return iterate(), matchfn
1279
1280 def commit(ui, repo, commitfunc, pats, opts):
1281 '''commit the specified files or all outstanding changes'''
1282 message = logmessage(opts)
1283
1284 if opts['addremove']:
1285 addremove(repo, pats, opts)
1286 fns, match, anypats = matchpats(repo, pats, opts)
1287 if pats:
1288 status = repo.status(files=fns, match=match)
1289 modified, added, removed, deleted, unknown = status[:5]
1290 files = modified + added + removed
1291 slist = None
1292 for f in fns:
1293 if f == '.':
1294 continue
1295 if f not in files:
1296 rf = repo.wjoin(f)
1297 try:
1298 mode = os.lstat(rf)[stat.ST_MODE]
1299 except OSError:
1300 raise util.Abort(_("file %s not found!") % rf)
1301 if stat.S_ISDIR(mode):
1302 name = f + '/'
1303 if slist is None:
1304 slist = list(files)
1305 slist.sort()
1306 i = bisect.bisect(slist, name)
1307 if i >= len(slist) or not slist[i].startswith(name):
1308 raise util.Abort(_("no match under directory %s!")
1309 % rf)
1310 elif not (stat.S_ISREG(mode) or stat.S_ISLNK(mode)):
1311 raise util.Abort(_("can't commit %s: "
1312 "unsupported file type!") % rf)
1313 elif f not in repo.dirstate:
1314 raise util.Abort(_("file %s not tracked!") % rf)
1315 else:
1316 files = []
1317 try:
1318 return commitfunc(ui, repo, files, message, match, opts)
1319 except ValueError, inst:
1320 raise util.Abort(str(inst))