# HG changeset patch
# User Jesse Glick <jesse.glick@sun.com>
# Date 2008-01-26 00:49:15
# Node ID e7f1be4bf40a71d85dfda76aa26445dfe9562349
# Parent  2e8eeb5bf29b40b870af43dde98db397ee35379b

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.
[CHANGES: rebased against d8878742a924, --no-commit option.]

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1529,7 +1529,8 @@ def import_(ui, repo, patch1, *patches, 
                 finally:
                     files = patch.updatedir(ui, repo, files)
                 if not opts.get('no_commit'):
-                    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()
@@ -2901,8 +2902,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
@@ -32,6 +32,13 @@ 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@nowhere.net' ../tip.patch
+hg -R b tip -pv
+rm -r b
+
 echo % import of plain diff should be ok with --no-commit
 hg clone -r0 a b
 hg --cwd a diff -r0:1 > tip.patch
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 @@ 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
+% 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@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
+
 % import of plain diff should be ok with --no-commit
 requesting all changes
 adding changesets