Commits

Graham Helliwell  committed dfd89dd

Pass functions instead of polluting the parameter list

  • Participants
  • Parent commits 5b9d659

Comments (0)

Files changed (1)

File guestrepo/guestrepo.py

 
     see help for the guestrepo extension for more information on the files used
     '''
-    return repoaction(ui, repo, opts.get('pull'), True, False, args, opts)
+    actions = [pull] if opts.get('pull') else []
+    actions.append(update)
+    return repoactions(ui, repo, actions, args, opts)
 
 def grpush(ui, repo, *args, **opts):
     '''push guest repos
 
     see help for the guestrepo extension for more information on the files used
     '''
-    return repoaction(ui, repo, False, False, True, args, opts)
+    return repoactions(ui, repo, [push], args, opts)
 
 def grpull(ui, repo, *args, **opts):
     '''pull  guest repos
 
     see help for the guestrepo extension for more information on the files used
     '''
-    return repoaction(ui,repo, True, opts.get('update'), False, args, opts)
+    actions = [pull]
+    if opts.get('update'): actions.append(update)
+    return repoactions(ui,repo, actions, args, opts)
 
 def summary(ui, repo, **opts):
     '''print a summary of the guest repos
 
 #####################
 
-def repoaction(ui, repo, shouldpull, shouldupdate, shouldpush, args, opts):
+def repoactions(ui, repo, orderedactions, args, opts):
     local = opts.get('local')
     mapping = 'local' if local else True
     abortIfInvalid= not opts.get('forcepartial')
-    succeeded = True
 
     guests = getguests(repo, None, abortIfInvalid)
     if args:
-       guests = matchguests(repo.root,
-                         os.getcwd(),
-                         args,
-                         guests)
+       guests = matchguests(repo.root, os.getcwd(), args, guests)
 
-    if (shouldpull):
-       succeeded = pull(ui, repo, mapping, guests, opts)
-    if succeeded and shouldupdate:
-       succeeded = update(ui, repo, local, mapping, guests, opts)
-    if succeeded and shouldpush:
-       succeeded = push(ui, repo, mapping, guests, opts)
-    return 0 if succeeded else 1
+    successes = list( action(ui, repo, mapping, guests, opts) for action in orderedactions )
+    return 0 if any(successes) else 1
 
 def pull(ui, repo, mapping, guests, opts):
     def pullaction(ui, repo, guest):
 
     runparallelaction(ui, repo, mapping, guests, pullaction, True, opts)
 
-def update(ui, repo, local, mapping, guests, opts):
+def update(ui, repo, mapping, guests, opts):
+    local = mapping=='local'
     path = dirtyrecursive(ui, repo, local, guests)
     if path:
         raise util.Abort("repository %s contains uncommitted changes" % path)