diff options
author | Mitchel Humpherys <mitchelh@codeaurora.org> | 2014-03-31 11:36:56 -0700 |
---|---|---|
committer | Mitchel Humpherys <mitchelh@codeaurora.org> | 2014-03-31 13:08:26 -0700 |
commit | e81bc030bba802627fd34af472fc0cf451e17c1d (patch) | |
tree | 2d899160e958b00b330e7a50927f1a6cd16eb526 /subcmds/forall.py | |
parent | 26c45a79586da17fe2e26a427acb56c81fb3bcc5 (diff) | |
download | git-repo-e81bc030bba802627fd34af472fc0cf451e17c1d.tar.gz |
Add total count and iteration count to forall environment
For long-running forall commands sometimes it's useful to know which
iteration is currently running. Add REPO_I and REPO_COUNT environment
variables to reflect the current iteration count as well as the total
number of iterations so that the user can build simple status
indicators.
Example:
$ repo forall -c 'echo $REPO_I / $REPO_COUNT; git gc'
1 / 579
Counting objects: 41, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (41/41), done.
Total 41 (delta 21), reused 41 (delta 21)
2 / 579
Counting objects: 53410, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (10423/10423), done.
Writing objects: 100% (53410/53410), done.
Total 53410 (delta 42513), reused 53410 (delta 42513)
3 / 579
...
Change-Id: I9f28b0d8b7debe423eed3b4bc1198b23e40c0c50
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Diffstat (limited to 'subcmds/forall.py')
-rw-r--r-- | subcmds/forall.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/subcmds/forall.py b/subcmds/forall.py index e2a420a9..03ebcb21 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
@@ -87,6 +87,12 @@ revision to a locally executed git command, use REPO_LREV. | |||
87 | REPO_RREV is the name of the revision from the manifest, exactly | 87 | REPO_RREV is the name of the revision from the manifest, exactly |
88 | as written in the manifest. | 88 | as written in the manifest. |
89 | 89 | ||
90 | REPO_COUNT is the total number of projects being iterated. | ||
91 | |||
92 | REPO_I is the current (1-based) iteration count. Can be used in | ||
93 | conjunction with REPO_COUNT to add a simple progress indicator to your | ||
94 | command. | ||
95 | |||
90 | REPO__* are any extra environment variables, specified by the | 96 | REPO__* are any extra environment variables, specified by the |
91 | "annotation" element under any project element. This can be useful | 97 | "annotation" element under any project element. This can be useful |
92 | for differentiating trees based on user-specific criteria, or simply | 98 | for differentiating trees based on user-specific criteria, or simply |
@@ -178,7 +184,9 @@ without iterating through the remaining projects. | |||
178 | else: | 184 | else: |
179 | projects = self.FindProjects(args) | 185 | projects = self.FindProjects(args) |
180 | 186 | ||
181 | for project in projects: | 187 | os.environ['REPO_COUNT'] = str(len(projects)) |
188 | |||
189 | for (cnt, project) in enumerate(projects): | ||
182 | env = os.environ.copy() | 190 | env = os.environ.copy() |
183 | def setenv(name, val): | 191 | def setenv(name, val): |
184 | if val is None: | 192 | if val is None: |
@@ -190,6 +198,7 @@ without iterating through the remaining projects. | |||
190 | setenv('REPO_REMOTE', project.remote.name) | 198 | setenv('REPO_REMOTE', project.remote.name) |
191 | setenv('REPO_LREV', project.GetRevisionId()) | 199 | setenv('REPO_LREV', project.GetRevisionId()) |
192 | setenv('REPO_RREV', project.revisionExpr) | 200 | setenv('REPO_RREV', project.revisionExpr) |
201 | setenv('REPO_I', str(cnt + 1)) | ||
193 | for a in project.annotations: | 202 | for a in project.annotations: |
194 | setenv("REPO__%s" % (a.name), a.value) | 203 | setenv("REPO__%s" % (a.name), a.value) |
195 | 204 | ||