blob: 041bcd0f8cf81bd27075e2c6c22fe63915a87a3b [file] [log] [blame]
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001#
2# Copyright (C) 2008 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from command import PagedCommand
17
Terence Haddock4655e812011-03-31 12:33:34 +020018try:
19 import threading as _threading
20except ImportError:
21 import dummy_threading as _threading
22
23import itertools
24import sys
25import StringIO
26
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070027class Status(PagedCommand):
28 common = True
29 helpSummary = "Show the working tree status"
30 helpUsage = """
31%prog [<project>...]
32"""
Shawn O. Pearce4c5c7aa2009-04-13 14:06:10 -070033 helpDescription = """
34'%prog' compares the working tree to the staging area (aka index),
35and the most recent commit on this branch (HEAD), in each project
36specified. A summary is displayed, one line per file where there
37is a difference between these three states.
38
Terence Haddock4655e812011-03-31 12:33:34 +020039The -j/--jobs option can be used to run multiple status queries
40in parallel.
41
Shawn O. Pearce4c5c7aa2009-04-13 14:06:10 -070042Status Display
43--------------
44
45The status display is organized into three columns of information,
46for example if the file 'subcmds/status.py' is modified in the
47project 'repo' on branch 'devwork':
48
49 project repo/ branch devwork
50 -m subcmds/status.py
51
52The first column explains how the staging area (index) differs from
53the last commit (HEAD). Its values are always displayed in upper
54case and have the following meanings:
55
56 -: no difference
57 A: added (not in HEAD, in index )
58 M: modified ( in HEAD, in index, different content )
59 D: deleted ( in HEAD, not in index )
60 R: renamed (not in HEAD, in index, path changed )
61 C: copied (not in HEAD, in index, copied from another)
62 T: mode changed ( in HEAD, in index, same content )
63 U: unmerged; conflict resolution required
64
65The second column explains how the working directory differs from
66the index. Its values are always displayed in lower case and have
67the following meanings:
68
69 -: new / unknown (not in index, in work tree )
70 m: modified ( in index, in work tree, modified )
71 d: deleted ( in index, not in work tree )
72
73"""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070074
Terence Haddock4655e812011-03-31 12:33:34 +020075 def _Options(self, p):
76 p.add_option('-j', '--jobs',
77 dest='jobs', action='store', type='int', default=2,
78 help="number of projects to check simultaneously")
79
80 def _StatusHelper(self, project, clean_counter, sem, output):
81 """Obtains the status for a specific project.
82
83 Obtains the status for a project, redirecting the output to
84 the specified object. It will release the semaphore
85 when done.
86
87 Args:
88 project: Project to get status of.
89 clean_counter: Counter for clean projects.
90 sem: Semaphore, will call release() when complete.
91 output: Where to output the status.
92 """
93 try:
94 state = project.PrintWorkTreeStatus(output)
95 if state == 'CLEAN':
96 clean_counter.next()
97 finally:
98 sem.release()
99
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700100 def Execute(self, opt, args):
Shawn O. Pearce161f4452009-04-10 17:41:44 -0700101 all = self.GetProjects(args)
Terence Haddock4655e812011-03-31 12:33:34 +0200102 counter = itertools.count()
Shawn O. Pearce161f4452009-04-10 17:41:44 -0700103
Shawn O. Pearce8bd5e602009-04-18 15:31:36 -0700104 on = {}
105 for project in all:
106 cb = project.CurrentBranch
107 if cb:
108 if cb not in on:
109 on[cb] = []
110 on[cb].append(project)
111
112 branch_names = list(on.keys())
113 branch_names.sort()
114 for cb in branch_names:
115 print '# on branch %s' % cb
116
Terence Haddock4655e812011-03-31 12:33:34 +0200117 if opt.jobs == 1:
118 for project in all:
119 state = project.PrintWorkTreeStatus()
120 if state == 'CLEAN':
121 counter.next()
122 else:
123 sem = _threading.Semaphore(opt.jobs)
124 threads_and_output = []
125 for project in all:
126 sem.acquire()
127 output = StringIO.StringIO()
128 t = _threading.Thread(target=self._StatusHelper,
129 args=(project, counter, sem, output))
130 threads_and_output.append((t, output))
131 t.start()
132 for (t, output) in threads_and_output:
133 t.join()
134 sys.stdout.write(output.getvalue())
135 output.close()
136 if len(all) == counter.next():
Shawn O. Pearce161f4452009-04-10 17:41:44 -0700137 print 'nothing to commit (working directory clean)'