Mercurial > hg-stable
changeset 203:0b486b5e0796
hg rawcommit command
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
hg rawcommit command
From: Christopher Li <hg@chrisli.org>
This allows direct access to the commit command, primarily for
importing from other SCMs.
manifest hash: bea39fa8207582c9fa7ba0904721eb5113c61cf4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCnUinywK+sNU5EO8RAhWqAJ9PiafRbfEIA3VsO07BbGZr5adNvgCfT2k7
blYTdkrIiRzzCxn6yPq8Yu4=
=o8k0
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Tue, 31 May 2005 21:33:27 -0800 |
parents | e875a0cf7f3a |
children | 161cef501e8d |
files | hg mercurial/hg.py |
diffstat | 2 files changed, 56 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/hg Tue May 31 21:24:14 2005 -0800 +++ b/hg Tue May 31 21:33:27 2005 -0800 @@ -150,7 +150,33 @@ repo.commit(repo.current, args) else: repo.commit(repo.current) - +elif cmd == "rawcommit": + "raw commit interface" + rc = {} + opts = [('p', 'parent', [], 'parent'), + ('d', 'date', "", 'data'), + ('u', 'user', "", 'user'), + ('F', 'files', "", 'file list'), + ('t', 'text', "", 'commit text'), + ('l', 'logfile', "", 'commit text file') + ] + args = fancyopts.fancyopts(args, opts, rc, + "hg rawcommit [options] files") + text = rc['text'] + if not text and rc['logfile']: + try: text = open(rc['logfile']).read() + except IOError: pass + if not text and not rc['logfile']: + print "missing commit text" + sys.exit(0) + if rc['files']: + files = open(rc['files']).read().splitlines() + else: + files = args + + repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent']) + + elif cmd == "import" or cmd == "patch": try: import psyco
--- a/mercurial/hg.py Tue May 31 21:24:14 2005 -0800 +++ b/mercurial/hg.py Tue May 31 21:33:27 2005 -0800 @@ -137,11 +137,13 @@ def read(self, node): return self.extract(self.revision(node)) - def add(self, manifest, list, desc, transaction, p1=None, p2=None): - user = (os.environ.get("HGUSER") or + def add(self, manifest, list, desc, transaction, p1=None, p2=None, + user=None, date=None): + user = (user or + os.environ.get("HGUSER") or os.environ.get("EMAIL") or os.environ.get("LOGNAME", "unknown") + '@' + socket.getfqdn()) - date = "%d %d" % (time.time(), time.timezone) + date = date or "%d %d" % (time.time(), time.timezone) list.sort() l = [hex(manifest), user, date] + list + ["", desc] text = "\n".join(l) @@ -344,6 +346,30 @@ return lock.lock(self.join("lock"), wait) raise inst + def rawcommit(self, files, text, user, date, p1=None, p2=None): + p1 = p1 or self.current or nullid + pchange = self.changelog.read(p1) + pmmap = self.manifest.read(pchange[0]) + tr = self.transaction() + mmap = {} + linkrev = self.changelog.count() + for f in files: + try: + t = file(f).read() + except IOError: + self.ui.warn("Read file %s error, skipped\n" % f) + continue + r = self.file(f) + prev = pmmap.get(f, nullid) + mmap[f] = r.add(t, tr, linkrev, prev) + + mnode = self.manifest.add(mmap, tr, linkrev, pchange[0]) + n = self.changelog.add(mnode, files, text, tr, p1, p2, user ,date, ) + tr.close() + self.setcurrent(n) + self.dircache.clear() + self.dircache.update(mmap) + def commit(self, parent, update = None, text = ""): self.lock() try: