[PATCH] convert: add config for recording the source name

Durham Goode durham at fb.com
Wed Jul 8 17:52:07 UTC 2015


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1436376669 25200
#      Wed Jul 08 10:31:09 2015 -0700
# Node ID 604822f422e3bdab04ebba9e52b332462b45865e
# Parent  0dfd9b064e56280fc7f3345382714dc28d913362
convert: add config for recording the source name

This creates the convert.hg.sourcename config option which will embed a user
defined name into each commit created by the convert. This is useful when using
the convert extension to merge several repositories together and we want to
record where each commit came from.

diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py
--- a/hgext/convert/__init__.py
+++ b/hgext/convert/__init__.py
@@ -356,6 +356,9 @@ def convert(ui, src, dest=None, revmapfi
     :convert.hg.usebranchnames: preserve branch names. The default is
         True.
 
+    :convert.hg.sourcename: records the given string as a 'convert_source' extra
+        value on each commit made in the target repository. The default is None.
+
     All Destinations
     ################
 
diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -225,6 +225,10 @@ class mercurial_sink(converter_sink):
 
         extra = commit.extra.copy()
 
+        sourcename = self.repo.ui.config('convert', 'hg.sourcename')
+        if sourcename:
+            extra['convert_source'] = sourcename
+
         for label in ('source', 'transplant_source', 'rebase_source',
                       'intermediate-source'):
             node = extra.get(label)
diff --git a/tests/test-convert.t b/tests/test-convert.t
--- a/tests/test-convert.t
+++ b/tests/test-convert.t
@@ -294,6 +294,10 @@
                     branch name for tag revisions, defaults to "default".
       convert.hg.usebranchnames
                     preserve branch names. The default is True.
+      convert.hg.sourcename
+                    records the given string as a 'convert_source' extra value
+                    on each commit made in the target repository. The default is
+                    None.
   
       All Destinations
       ################
@@ -503,3 +507,17 @@ test revset converted() lookup
   date:        Thu Jan 01 00:00:04 1970 +0000
   summary:     e
   
+
+test specifying a sourcename
+  $ echo g > a/g
+  $ hg -R a ci -d'0 0' -Amg
+  adding g
+  $ hg --config convert.hg.sourcename=mysource --config convert.hg.saverev=True convert a c
+  scanning source...
+  sorting...
+  converting...
+  0 g
+  $ hg -R c log -r tip --template '{extras % "{extra}\n"}'
+  branch=default
+  convert_revision=a3bc6100aa8ec03e00aaf271f1f50046fb432072
+  convert_source=mysource


More information about the Mercurial-devel mailing list