[PATCH] Permitting the import command to accept a --user option

Jesse Glick Jesse.Glick at Sun.COM
Fri Jan 25 03:39:25 CST 2008


# HG changeset patch
# User Jesse Glick <jesse.glick at sun.com>
# Date 1201253845 18000
# Node ID 53b20abfd45c8340346246b2c32b4965b330cf1a
# Parent  4ca557248e885ad526226f5f6a62f6d405d9b14f
Permitting the import command to accept a --user option.
The prose section of the help text for the command already said that -u and -m
are accepted, but -u was not listed in the table of options, and did not work.
Useful when accepting patches from other people made by hg diff rather than hg
export. For completeness, also accepting -d DATE.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1528,7 +1528,8 @@ def import_(ui, repo, patch1, *patches, 
                                        files=files)
                 finally:
                     files = patch.updatedir(ui, repo, files)
-                n = repo.commit(files, message, user, date)
+                n = repo.commit(files, message, opts.get('user') or user,
+                                opts.get('date') or date)
                 if opts.get('exact'):
                     if hex(n) != nodeid:
                         repo.rollback()
@@ -2899,8 +2900,9 @@ table = {
           ('', 'exact', None,
            _('apply patch to the nodes from which it was generated')),
           ('', 'import-branch', None,
-           _('Use any branch information in patch (implied by --exact)'))] + commitopts,
-         _('hg import [-p NUM] [-m MESSAGE] [-f] PATCH...')),
+           _('Use any branch information in patch (implied by --exact)'))] +
+         commitopts + commitopts2,
+         _('hg import [OPTION]... PATCH...')),
     "incoming|in":
         (incoming,
          [('M', 'no-merges', None, _('do not show merges')),
diff --git a/tests/test-import b/tests/test-import
--- a/tests/test-import
+++ b/tests/test-import
@@ -30,6 +30,13 @@ hg clone -r0 a b
 hg clone -r0 a b
 hg --cwd a diff -r0:1 > tip.patch
 hg --cwd b import -mpatch ../tip.patch
+rm -r b
+
+echo % import of plain diff with specific date and user
+hg clone -r0 a b
+hg --cwd a diff -r0:1 > tip.patch
+hg --cwd b import -mpatch -d '1 0' -u 'user at nowhere.net' ../tip.patch
+hg -R b tip -pv
 rm -r b
 
 echo % hg -R repo import
diff --git a/tests/test-import.out b/tests/test-import.out
--- a/tests/test-import.out
+++ b/tests/test-import.out
@@ -31,6 +31,30 @@ added 1 changesets with 2 changes to 2 f
 added 1 changesets with 2 changes to 2 files
 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
 applying ../tip.patch
+% import of plain diff with specific date and user
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 1 changesets with 2 changes to 2 files
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+applying ../tip.patch
+changeset:   1:ca68f19f3a40
+tag:         tip
+user:        user at nowhere.net
+date:        Thu Jan 01 00:00:01 1970 +0000
+files:       a
+description:
+patch
+
+
+diff -r 80971e65b431 -r ca68f19f3a40 a
+--- a/a	Thu Jan 01 00:00:00 1970 +0000
++++ b/a	Thu Jan 01 00:00:01 1970 +0000
+@@ -1,1 +1,2 @@
+ line 1
++line 2
+
 % hg -R repo import
 requesting all changes
 adding changesets


More information about the Mercurial-devel mailing list