David Jade avatar David Jade committed 32a9175

Added -b bottomup option to reverse the order that the ACTION is applied

Comments (0)

Files changed (1)

     optReclone = opts.get('reclone', None)
     optRecurse = opts.get('recurse', None)
     optAll = opts.get('all', None)
+    optBottomUp = opts.get('bottomup', None)
 
     # force optAll mode for user-defined actions
     forceAllForCommands = ui.config("subrepo", "forceAllForCommands")
         # do action for all subrepos
         ui.status("doing '%s' for all subrepos, watch output for necessity of user intervention...\n" % action)
         func = lambda ui, repoPath, remotePath: doHgTextCommand(ui, repoPath, action)
-        doCommand(ui, repo, func, (optRecurse or optAll), optAll)
+        if optBottomUp:
+            doCommandReverse(ui, repo, func, (optRecurse or optAll), optAll)
+        else:
+            doCommand(ui, repo, func, (optRecurse or optAll), optAll)
         ui.status("---------------------------\n")
 
         # special messages for some actions
             else:
                 ui.status("* %s is missing (perhaps you should reclone)\n" % subrepoPath)
 
+				
+# execute a function for each subrepo with optional recloning and optional recursion, in bottom up or reverse order
+# func is defined as func(localPath, remotePath)
+def doCommandReverse(ui, repo, func, recurse, all, relativePath=""):
+    if os.path.exists(os.path.join(repo.root, ".hgsub")):
+        for local, remote in getSubreposFromHgsub(repo):
+            subrepoPath = os.path.join(relativePath, local)
+            if os.path.exists(subrepoPath):
+                if recurse:
+                    doCommandReverse(ui, hg.repository(ui, subrepoPath, False), func, recurse, all, subrepoPath)
+                func(ui, subrepoPath, remote)
+            else:
+                ui.status("* %s is missing (perhaps you should reclone)\n" % subrepoPath)
+    if relativePath == "" and all:
+        func(ui, ".", ui.config('paths', 'default'))
+
 
 # generic helper to execute a hg command
 def doHgTextCommand(ui, repoPath, commandText):
           ('c', 'reclone', None, _('reclone all missing but registered subrepositories (as defined in .hgsub), ' +
 		  'leaving existing ones intact; this does not look at nor modify .hgsubstate! ' +
 		  'If an ACTION is specified it will execute after recloning all missing subrepos.')),
+		  ('b', 'bottomup', None, _('operate bottom up, reversing the order that ACTION is applied')),
          ],
-         _('hg subrepo [-r] [-a] [-c] [ACTION] '))
+         _('hg subrepo [-r] [-a] [-c] [-b] [ACTION] '))
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.