Commits

Alain Leufroy  committed ef6a23c

refactorization: remove ``makestatestr`` and ``getstate`` functions

Most of the corresponding code are duplication.
We just put generic metodes into ``guestrepo``
class allowing to retrieve repository data.

  • Participants
  • Parent commits 7d78837
  • Branches aleufroy/configfile

Comments (0)

Files changed (1)

File guestrepo/guestrepo.py

                             'id' : dict_rep['id']})
         ui.write(json.dumps(json_list) + "\n")
     else:
-        statestr = makestatestr(getstate(ui, repo, guests))
-        ui.write(statestr)
+        lines = ("%-10s = %-10s %s\n" % (guest.configpath,
+                                         guest.name,
+                                         guest.get_cset(ui, '.').hex())
+                 for guest in filterwarnguests(ui, guests))
+        ui.write(''.join(lines))
 
 @warn_uncomitted_config
 def freeze(ui, repo, **opts):
     ``.hgguestrepo`` file.
     '''
     guests = getguests(ui, repo)
-    state = getstate(ui, repo, guests)
     if opts.get('publish', False):
         if not SUPPORTS_PHASES:
             msg = 'your version of Mercurial does not support phases'
             raise util.Abort(msg)
         def publishaction(ui, repo, guest):
-            commands.phase(ui, repo, rev=[dict(state)[guest]],
+            commands.phase(ui, repo, rev=[guest.get_cset(ui, rev='.').hex()],
                            public=True, draft=None, secret=None, force=False)
 
         workers = makeworkers(ui, opts)
 
         return json_dict
 
-    def to_gr_entry(self, ui, rev=None):
+    def get_cset(self, ui, rev=None):
         guestrepo = hg.repository(ui, self.root, create=False)
-        if rev is None:
-            changeset_id = node.hex(guestrepo[None].parents()[0].node())
-        else:
-            changeset_id = node.hex(guestrepo[rev].node())
-        return "%s = %s %s\n" % (self.configpath.ljust(10), self.name.ljust(10), changeset_id)
+        return guestrepo[rev]
 
     def to_mapping_entry(self, ui):
         return "%s = %s" % self.configpath.ljust(10), self.name
         if work:
             workers.run(work, guest)
 
-def makestatestr(states):
-    '''
-    Create a description string for a list of state.
-
-    It can also return the same string in JSON.
-    '''
-    lines = []
-    for guest, hex in states:
-        lines.append("%s = %s %s\n" %
-                     (guest.configpath.ljust(10),
-                      guest.name.ljust(10),
-                      hex))
-    return ''.join(lines)
-
-
-def getstate(ui, repo, guests):
-    '''
-    Return a list of repo's guest's state.
-    '''
-    states = []
-
-    for guest in filterwarnguests(ui, guests):
-        guestrepo = hg.repository(ui, guest.root, create=False)
-        states.append((guest, guestrepo['.'].hex()))
-    return states
-
 def template_output_to_list(template_output):
     '''
     Take the output of hg.incoming or hg.incoming formatted using the