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

Jesse Glick Jesse.Glick at Sun.COM
Fri Jan 25 18:53:08 CST 2008


# HG changeset patch
# User Jesse Glick <jesse.glick at sun.com>
# Date 1201308555 18000
# Node ID 71761e2018b3c1e9f72a9f1b66162497b6855eae
# Parent  eb34dda38f0a8b98d79052681c62296d1781ff30
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
@@ -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 % import of plain diff should be ok with --no-commit
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
+
 % import of plain diff should be ok with --no-commit
 requesting all changes
 adding changesets


More information about the Mercurial-devel mailing list