blob: 7187f4b163651f607466b6dd0bd985b864d6e173 [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
Terence Haddock4655e812011-03-31 12:33:34 +0200104 if opt.jobs == 1:
105 for project in all:
106 state = project.PrintWorkTreeStatus()
107 if state == 'CLEAN':
108 counter.next()
109 else:
110 sem = _threading.Semaphore(opt.jobs)
111 threads_and_output = []
112 for project in all:
113 sem.acquire()
114 output = StringIO.StringIO()
115 t = _threading.Thread(target=self._StatusHelper,
116 args=(project, counter, sem, output))
117 threads_and_output.append((t, output))
118 t.start()
119 for (t, output) in threads_and_output:
120 t.join()
121 sys.stdout.write(output.getvalue())
122 output.close()
123 if len(all) == counter.next():
Shawn O. Pearce161f4452009-04-10 17:41:44 -0700124 print 'nothing to commit (working directory clean)'