diff mercurial/hg.py @ 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 8450c18f2a45
children ec327cf0d3a9
line wrap: on
line diff
--- 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: