Commits

Ebbe Elsborg  committed 635a0aa

sort modules using operation system casing logic

review: Henrik Stuart

  • Participants
  • Parent commits b939109

Comments (0)

Files changed (4)

File repoman/commands.py

                       (ui.emph_str(name),
                        mercurial.util.datestr(info.date(), format='%Y-%m-%d %H:%M:%S'),
                        util.longuser(info.user())))
-            ui.status('Modules: %s\n' % util.wrap(', '.join(sorted(branch.iterkeys())), 80, 9))
+            ui.status('Modules: %s\n' % util.wrap(', '.join(util.sortmodules(branch.iterkeys())), 80, 9))
         else:
             info = f.read_branch(name, base=True)
             if info:
                 ui.status('Branch %s (local branch)\n' % (ui.emph_str(name)))
-                ui.status('Modules: %s\n' % util.wrap(', '.join(sorted(info.iterkeys())), 80, 9))
+                ui.status('Modules: %s\n' % util.wrap(', '.join(util.sortmodules(info.iterkeys())), 80, 9))
         return
 
     # Read and validate dirstate
 
     if not module:
         raise util.Abort('you must specify at least one module to extend the forest with')
-    existing = sorted(mod for mod in module if os.path.exists(os.path.join(f.root, mod)))
+    existing = util.sortmodules(mod for mod in module if os.path.exists(os.path.join(f.root, mod)))
     if existing:
         raise util.Abort('the following modules already exist locally: %s' % (', '.join(existing)))
     remotemods = cmdutil.get_remote_info(ui, f.getsource(source=source))
     missing = set(module) - set(remotemods)
     if missing:
-        raise util.Abort('the following modules cannot be found: %s' % (', '.join(sorted(missing))))
+        raise util.Abort('the following modules cannot be found: %s' % (', '.join(util.sortmodules(missing))))
 
     ui.status('Extending forest in %s:\n' % util.normpath(ui, f.root))
     cmdutil.pull_metadata(f, source)
     operation, description, extra, modules, correct = f.read_undo()
     modules &= set(f) | set([f.GMD])
     ui.status('operation: %s\n' % description)
-    ui.status('involved modules: %s\n' % ', '.join(sorted(['(metadata)' if mod == f.GMD else mod for mod in modules])))
+    ui.status('involved modules: %s\n' % ', '.join(util.sortmodules(['(metadata)' if mod == f.GMD else mod for mod in modules])))
     wrong = modules - correct
     if wrong:
-        ui.warn('The following modules have changed and cannot be included: %s\n' % ', '.join(sorted(wrong)))
+        ui.warn('The following modules have changed and cannot be included: %s\n' % ', '.join(util.sortmodules(wrong)))
     if not yes:
         answer = ui.prompt('Undo this %s (y/yes/n/no)?' % operation, 'n')
         if answer not in ['y', 'yes']:
     modules &= correct
     modstr = cmdutil.modstr_tmpl(ui, modules, metadata=(f.GMD in modules))
     ui.filter = re.compile('^working directory now based')
-    for mod in sorted(modules):
+    for mod in util.sortmodules(modules):
         md = mod == f.GMD
         ui.write(modstr % ('(metadata)' if md else mod))
         repo = f[mod]

File repoman/forest.py

         mpath = self.modules_lmd_path
         if not os.path.isfile(mpath):
             raise self._error_noforest()
-        object.__setattr__(self, 'modules', sorted(util.read_utf8(mpath).split()))
+        object.__setattr__(self, 'modules', util.sortmodules(util.read_utf8(mpath).split()))
 
         def resolve_current_module(mod):
             if mod == '.':
         if name == 'branch' and value != self.branch:
             util.write_utf8(self.branch_lmd_path, value)
         elif name == 'modules':
-            value = sorted(value)
+            value = util.sortmodules(value)
             util.write_utf8(self.modules_lmd_path, '\n'.join(value) + '\n')
         elif name == 'solution':
             util.write_utf8(self.solution_lmd_path, value)
             util.mkdir_rec(os.path.dirname(filename))
             data = ''.join(
                     ['%s %s\r\n' % (oldmap[m], fromlocal(m))
-                        for m in sorted(iter())])
+                        for m in util.sortmodules(iter())])
             if not data and allow_unlink:
                 if os.path.exists(filename):
                     util.unlink(filename)
         if initial:
             missing_modules = set(modules) - set(self.modules)
             if missing_modules:
-                raise util.ModulesMissingError(missing_modules)
+                raise util.ModulesMissingError(util.sortmodules(missing_modules))
 
         ui = self.ui
         mods = set()
-        for module in modules:
+        for module in util.sortmodules(modules):
             ui.write_module_header(module)
             if source:
                 src = self.getsource(module, source)
             ui.write('\n')
 
         if initial:
-            self.modules = sorted(mods)
+            self.modules = util.sortmodules(mods)
         else:
-            self.modules = sorted(mods | set(self.modules))
+            self.modules = util.sortmodules(mods | set(self.modules))
             util.commit(self.lmd_repo, 'Added modules', ['modules'])
 
     def repo_branch_heads(self, repo, name, base):

File repoman/util.py

     return s.decode(encoding.fallbackencoding, 'replace')
 
 def sortmodules(modules):
+    modules = list(modules)
+
     if any([x.__class__ is unicode for x in modules]):
         key = unicode.lower
     else:

File tests/output/vclone.py.out

-Perform a normal vclone
-Creating virtual clone of solution sol1 in <TESTROOT>/vclonetest/sol1 (from <TESTROOT>/vclonetest/master)
-Cloning metadata
-Creating symbolic links
-True
-
-Perform vclone of unrelated solution, failure
-abort: source is a 'sol1' forest and can't be cloned as a 'sol2' forest.
-
-Perform vclone on existing destination, failure
-abort: destination already exists.
-
-Perform vclone on unknown solution, failure
-abort: solution foobarbazquux not found
-
-Perform vclone that fetches missing modules
-Creating virtual clone of solution sol1 in <TESTROOT>/vclonetest/sol1 (from <TESTROOT>/vclonetest/master)
-Cloning metadata
-Cloning missing modules:
-~~~ (metadata) ~~~
-no changes found
-
-~~~ a ~~~
-2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-
-~~~ c ~~~
-2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-
-~~~ b ~~~
-2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-
-Creating symbolic links
-True
-
-Perform vclone on solution as solution with separate destination
-Creating virtual clone of solution sol1 in <TESTROOT>/vclonetest/sol1_1 (from <TESTROOT>/vclonetest/sol1)
-Cloning metadata
-Creating symbolic links
+Perform a normal vclone
+Creating virtual clone of solution sol1 in <TESTROOT>/vclonetest/sol1 (from <TESTROOT>/vclonetest/master)
+Cloning metadata
+Creating symbolic links
+True
+
+Perform vclone of unrelated solution, failure
+abort: source is a 'sol1' forest and can't be cloned as a 'sol2' forest.
+
+Perform vclone on existing destination, failure
+abort: destination already exists.
+
+Perform vclone on unknown solution, failure
+abort: solution foobarbazquux not found
+
+Perform vclone that fetches missing modules
+Creating virtual clone of solution sol1 in <TESTROOT>/vclonetest/sol1 (from <TESTROOT>/vclonetest/master)
+Cloning metadata
+Cloning missing modules:
+~~~ (metadata) ~~~
+no changes found
+
+~~~ a ~~~
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+~~~ b ~~~
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+~~~ c ~~~
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+Creating symbolic links
+True
+
+Perform vclone on solution as solution with separate destination
+Creating virtual clone of solution sol1 in <TESTROOT>/vclonetest/sol1_1 (from <TESTROOT>/vclonetest/sol1)
+Cloning metadata
+Creating symbolic links