Patchwork [3,of,8] convert: add parseclosemap method

login
register
mail settings
Submitter Sean Farley
Date Feb. 4, 2014, 12:09 a.m.
Message ID <ffc309a9200cb7d46b3e.1391472574@laptop.local>
Download mbox | patch
Permalink /patch/3459/
State Accepted
Commit a3545c3104aacb97cf98a22ee4a2e472f406708b
Headers show

Comments

Sean Farley - Feb. 4, 2014, 12:09 a.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1390324814 21600
#      Tue Jan 21 11:20:14 2014 -0600
# Node ID ffc309a9200cb7d46b3e42d77087f368e23003b6
# Parent  9d9cb420548d37223de02811ab1d53e1f0a9c93f
convert: add parseclosemap method

This is a copy of the parsesplicemap method and will serve as a way to specify
which changesets to close while converting.
Matt Mackall - Feb. 5, 2014, 12:04 a.m.
On Mon, 2014-02-03 at 18:09 -0600, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1390324814 21600
> #      Tue Jan 21 11:20:14 2014 -0600
> # Node ID ffc309a9200cb7d46b3e42d77087f368e23003b6
> # Parent  9d9cb420548d37223de02811ab1d53e1f0a9c93f
> convert: add parseclosemap method
> 
> This is a copy of the parsesplicemap method and will serve as a way to specify
> which changesets to close while converting.

Why is this something that needs automating?
Sean Farley - Feb. 5, 2014, 12:10 a.m.
mpm@selenic.com writes:

> On Mon, 2014-02-03 at 18:09 -0600, Sean Farley wrote:
>> # HG changeset patch
>> # User Sean Farley <sean.michael.farley@gmail.com>
>> # Date 1390324814 21600
>> #      Tue Jan 21 11:20:14 2014 -0600
>> # Node ID ffc309a9200cb7d46b3e42d77087f368e23003b6
>> # Parent  9d9cb420548d37223de02811ab1d53e1f0a9c93f
>> convert: add parseclosemap method
>> 
>> This is a copy of the parsesplicemap method and will serve as a way to specify
>> which changesets to close while converting.
>
> Why is this something that needs automating?

Currently, there is no way to close branches that were meant to be
closed but forgotten. It allows a clean way via a command-line option to
close old branches while converting without forcing the user to dig into
hgext/convert.

Patch

diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py
+++ b/hgext/convert/convcmd.py
@@ -118,10 +118,46 @@  class converter(object):
             self.readauthormap(opts.get('authormap'))
             self.authorfile = self.dest.authorfile()
 
         self.splicemap = self.parsesplicemap(opts.get('splicemap'))
         self.branchmap = mapfile(ui, opts.get('branchmap'))
+        self.closemap = self.parseclosemap(opts.get('closemap'))
+
+    def parseclosemap(self, path):
+        """ check and validate the closemap format and
+            return a list of revs to close.
+            Format checking has two parts.
+            1. generic format which is same across all source types
+            2. specific format checking which may be different for
+               different source type.  This logic is implemented in
+               checkrevformat function in source files like
+               hg.py, subversion.py etc.
+        """
+
+        if not path:
+            return []
+        m = []
+        try:
+            fp = open(path, 'r')
+            for i, line in enumerate(fp):
+                line = line.splitlines()[0].rstrip()
+                if not line:
+                    # Ignore blank lines
+                    continue
+                # split line
+                lex = shlex.shlex(line, posix=True)
+                lex.whitespace_split = True
+                lex.whitespace += ','
+                line = list(lex)
+                for part in line:
+                    self.source.checkrevformat(part, 'closemap')
+                m.extend(line)
+        # if file does not exist or error reading, exit
+        except IOError:
+            raise util.Abort(_('closemap file not found or error reading %s:')
+                               % path)
+        return m
 
     def parsesplicemap(self, path):
         """ check and validate the splicemap format and
             return a child/parents dictionary.
             Format checking has two parts.
@@ -406,10 +442,13 @@  class converter(object):
                            (parents, rev))
             parents = [self.map.get(p, p) for p in parents]
         except KeyError:
             parents = [b[0] for b in pbranches]
         source = progresssource(self.ui, self.source, len(files))
+        if self.closemap and rev in self.closemap:
+            commit.extra['close'] = 1
+
         newnode = self.dest.putcommit(files, copies, parents, commit,
                                       source, self.map)
         source.close()
         self.source.converted(rev, newnode)
         self.map[rev] = newnode