public
Description: Collection of scripts for performing generic git tasks
Clone URL: git://github.com/farktronix/gittools.git
Search Repo:
Did some code cleanup, a tiny bit of refactoring, and a few bug fixes.

Fixed a bug where usage wasn't printed if --clean was used improperly.
Fixed a hang if the user ctl-c'd out of the process.
danpreston (author)
Sun May 11 22:25:56 -0700 2008
commit  e3432778bc58cfa462629c1bc14ad89eb0a62daf
tree    9411b25494763eb5bb53ba7cdc20bf44ee52d1e3
parent  261caf6ffdc9d66a19d7b7e087b80d6791db3718
...
19
20
21
22
 
23
24
 
25
26
27
28
29
30
31
...
51
52
53
 
 
 
54
 
 
 
 
 
 
55
56
57
58
59
60
 
 
61
62
63
64
...
67
68
69
 
70
71
72
73
74
 
75
76
77
78
...
79
80
81
82
 
83
84
 
85
86
87
88
...
89
90
91
92
 
93
94
95
96
 
 
97
98
99
100
101
102
103
104
105
106
107
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
 
 
120
121
122
123
124
 
125
126
127
128
129
130
 
131
132
133
134
135
 
136
137
138
 
139
140
 
141
142
 
143
144
145
146
...
152
153
154
155
156
 
 
157
158
159
160
 
 
161
162
163
164
165
166
167
168
...
168
169
170
171
172
173
174
 
 
 
 
175
176
177
178
179
180
181
 
182
183
 
184
185
186
 
187
188
189
190
 
191
192
 
193
194
195
196
197
198
...
200
201
202
203
204
205
 
 
 
206
207
208
209
210
 
 
211
212
 
213
214
 
215
216
217
...
219
220
221
222
 
223
224
225
226
227
...
261
262
263
264
 
265
266
 
267
268
269
270
 
 
 
271
272
273
...
283
284
285
286
 
287
288
289
...
300
301
302
303
 
 
 
 
304
305
306
...
19
20
21
 
22
23
 
24
25
 
26
27
28
29
30
...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
 
67
68
69
70
71
72
...
75
76
77
78
79
80
81
82
 
83
84
85
86
87
...
88
89
90
 
91
92
93
94
95
96
97
98
...
99
100
101
 
102
103
104
105
 
106
107
108
109
110
111
112
113
114
115
116
117
118
...
113
114
115
 
 
 
 
 
116
117
 
 
 
118
 
 
 
 
119
120
121
122
 
 
 
 
123
124
125
126
127
128
 
129
130
131
132
133
 
134
135
136
 
137
138
 
139
140
 
141
142
143
144
145
...
151
152
153
 
 
154
155
156
157
 
 
158
159
160
161
162
163
164
165
166
167
...
167
168
169
 
 
 
 
170
171
172
173
174
175
176
177
178
179
 
180
181
 
182
183
184
 
185
186
187
188
 
189
190
 
191
192
193
194
195
196
197
...
199
200
201
 
 
 
202
203
204
205
206
207
 
 
208
209
210
 
211
212
 
213
214
215
216
...
218
219
220
 
221
222
223
224
225
226
...
260
261
262
 
263
264
 
265
266
 
 
 
267
268
269
270
271
272
...
282
283
284
 
285
286
287
288
...
299
300
301
 
302
303
304
305
306
307
308
0
@@ -19,11 +19,10 @@
0
 #  fileNotPresentError
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
-def fileNotPresentError(repositoryPath, revision, chatty=True):
0
+def fileNotPresentError( repositoryPath, revision, chatty=True ):
0
   if chatty:
0
- print "\tFile \"%s\" does not exist in repository at revision \"%s\"." % (repositoryPath, revision)
0
+ print "\tFile \"%s\" does not exist in repository at revision \"%s\"." % ( repositoryPath, revision )
0
 
0
-
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 #  createTempFileForRevision
0
 #----------------------------------------------------------------------------------------------------------------------------
0
0
0
@@ -51,13 +50,22 @@
0
   
0
   return temp
0
 
0
+#----------------------------------------------------------------------------------------------------------------------------
0
+# signalDiffProcessed
0
+#----------------------------------------------------------------------------------------------------------------------------
0
 
0
+def signalDiffProcessed( condition, diffsLeft ):
0
+ condition.acquire()
0
+ diffsLeft[0] = diffsLeft[0] - 1
0
+ condition.notifyAll()
0
+ condition.release()
0
+
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 #  performDiff
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
-def performDiff(compareFile, revision, condition, diffsLeft, chatty=True):
0
- revision, _, revision2 = revision.partition("..")
0
+def performDiff( compareFile, revision, condition, diffsLeft, chatty=True ):
0
+ revision, _, revision2 = revision.partition( ".." )
0
   
0
   realpath = os.path.abspath( compareFile )
0
   
0
0
@@ -67,11 +75,12 @@
0
   if os.path.isdir( realpath ):
0
     if chatty:
0
       print "\t\"" + relativePath + "\" is a directory. " + gToolName + " only compares files."
0
+ signalDiffProcessed( condition, diffsLeft )
0
     return
0
   
0
   found = False;
0
   # Figure out what the relative path of the file is from the .git folder.
0
- while (found == False) and (head != "/"):
0
+ while ( found == False ) and ( head != "/" ):
0
     gitPath = os.path.join( head, ".git" )
0
     found = os.path.exists( gitPath )
0
     if found == False:
0
0
@@ -79,9 +88,10 @@
0
       relativePath = os.path.join( tail, relativePath )
0
   
0
   # Make sure we are actually in a git repository.
0
- if (found == False) and (head == "/"):
0
+ if ( found == False ) and ( head == "/" ):
0
     if chatty:
0
       print "\tThat file is not in a git repository."
0
+ signalDiffProcessed( condition, diffsLeft )
0
     return
0
   
0
   file1 = createTempFileForRevision( revision, relativePath, chatty )
0
0
@@ -89,11 +99,12 @@
0
     file2 = createTempFileForRevision( revision2, relativePath, chatty )
0
   else:
0
     file2 = realpath
0
- if os.path.exists(file2) == False:
0
+ if os.path.exists( file2 ) == False:
0
       fileNotPresentError( relativePath, "HEAD", chatty )
0
       file2 = None
0
     
0
- if (file1 == None) or (file2 == None):
0
+ if ( file1 == None ) or ( file2 == None ):
0
+ signalDiffProcessed( condition, diffsLeft )
0
     return
0
   
0
   same = filecmp.cmp( file2, file1 )
0
0
0
0
0
0
0
0
0
@@ -102,44 +113,32 @@
0
       print "\tThe file \"" + fileName + "\" has no differences."
0
   else:
0
     # Escape the files with quotes to allow for files with spaces.
0
- if revision2:
0
- deleteFile2 = True
0
- else:
0
- deleteFile2 = False
0
- # Escape the files with quotes to allow for files with spaces.
0
     command = 'bbdiff "%s" "%s" --wait' % ( file2, file1 )
0
     status, output = commands.getstatusoutput( command )
0
- os.remove( file1 )
0
- if deleteFile2:
0
- os.remove( file2 )
0
   
0
- condition.acquire()
0
- diffsLeft[0] = diffsLeft[0] - 1
0
- condition.notifyAll()
0
- condition.release()
0
+ os.remove( file1 )
0
+ if revision2:
0
+ os.remove( file2 )
0
   
0
- condition.acquire()
0
- while diffsLeft[0] > 0:
0
- condition.wait()
0
- condition.release()
0
+ signalDiffProcessed( condition, diffsLeft )
0
 
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 #  numConflicts
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
-def numConflicts(conflictFile):
0
+def numConflicts( conflictFile ):
0
   foundStart = False
0
   foundMiddle = False
0
   
0
   conflicts = 0
0
- f = open(conflictFile, "r")
0
+ f = open( conflictFile, "r" )
0
   line = f.readline()
0
   while line:
0
- if line.startswith("<<<<<<<") and (foundStart == False) and (foundMiddle == False):
0
+ if line.startswith( "<<<<<<<" ) and ( foundStart == False ) and ( foundMiddle == False ):
0
       foundStart = True
0
- if line.startswith("=======") and foundStart and (foundMiddle == False):
0
+ if line.startswith( "=======" ) and foundStart and ( foundMiddle == False ):
0
       foundMiddle = True
0
- if line.startswith(">>>>>>>") and foundStart and foundMiddle:
0
+ if line.startswith( ">>>>>>>" ) and foundStart and foundMiddle:
0
       conflicts = conflicts + 1
0
       foundStart = False
0
       foundMiddle = False
0
0
@@ -152,12 +151,12 @@
0
 #  renameConflictFile
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
-def uniqueName(path, uniqueLabel):
0
- base, extension = os.path.splitext(path)
0
+def uniqueName( path, uniqueLabel ):
0
+ base, extension = os.path.splitext( path )
0
   digit = 2
0
   uniqueDigit = ""
0
- if os.path.exists(base + uniqueLabel + uniqueDigit + extension):
0
- uniqueDigit = str(digit)
0
+ if os.path.exists( base + uniqueLabel + uniqueDigit + extension ):
0
+ uniqueDigit = str( digit )
0
     digit = digit + 1
0
   
0
   newPath = base + uniqueLabel + uniqueDigit + extension
0
0
0
0
0
0
@@ -168,28 +167,28 @@
0
 #  createConflictFiles
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
-def createConflictFiles(minePath, theirPath, conflictFile):
0
- orig = open(conflictFile, "r")
0
- mine = open(minePath, "w")
0
- theirs = open(theirPath, "w")
0
+def createConflictFiles( minePath, theirPath, conflictFile ):
0
+ orig = open( conflictFile, "r" )
0
+ mine = open( minePath, "w" )
0
+ theirs = open( theirPath, "w" )
0
   
0
   placeInTheirs = True
0
   placeInMine = True
0
   
0
   line = orig.readline()
0
   while line:
0
- if line.startswith("<<<<<<<") and placeInTheirs and placeInMine:
0
+ if line.startswith( "<<<<<<<" ) and placeInTheirs and placeInMine:
0
       placeInMine = False
0
- elif line.startswith("=======") and placeInTheirs and (placeInMine == False):
0
+ elif line.startswith( "=======" ) and placeInTheirs and ( placeInMine == False ):
0
       placeInTheirs = False
0
       placeInMine = True
0
- elif line.startswith(">>>>>>>") and (placeInTheirs == False) and placeInMine:
0
+ elif line.startswith( ">>>>>>>" ) and ( placeInTheirs == False ) and placeInMine:
0
       placeInTheirs = True
0
     else:
0
       if placeInMine:
0
- mine.write(line)
0
+ mine.write( line )
0
       if placeInTheirs:
0
- theirs.write(line)
0
+ theirs.write( line )
0
     line = orig.readline()
0
     
0
   orig.close()
0
0
0
0
@@ -200,18 +199,18 @@
0
 #  diffConflict
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
-def diffConflict(conflictFile, chatty=True):
0
- conflicts = numConflicts(conflictFile)
0
- if (conflicts == 0) and chatty:
0
+def diffConflict( conflictFile, chatty=True ):
0
+ conflicts = numConflicts( conflictFile )
0
+ if ( conflicts == 0 ) and chatty:
0
     basePath, fileName = os.path.split( conflictFile )
0
     print "\tThe file \"%s\" does not contain any conflicts. SKIPPING." % fileName
0
   else:
0
- newConflictPath = uniqueName(conflictFile, gConflictMarker)
0
- os.rename(conflictFile, newConflictPath)
0
+ newConflictPath = uniqueName( conflictFile, gConflictMarker )
0
+ os.rename( conflictFile, newConflictPath )
0
     
0
- theirPath = uniqueName(conflictFile, gTheirsMarker)
0
+ theirPath = uniqueName( conflictFile, gTheirsMarker )
0
     
0
- createConflictFiles(conflictFile, theirPath, newConflictPath)
0
+ createConflictFiles( conflictFile, theirPath, newConflictPath )
0
     command = 'bbdiff "%s" "%s"' % ( conflictFile, theirPath )
0
     status, output = commands.getstatusoutput( command )
0
 
0
@@ -219,7 +218,7 @@
0
 #  cleanConflictRelatedFiles
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
-def cleanConflictRelatedFiles(conflictFile, chatty=True):
0
+def cleanConflictRelatedFiles( conflictFile, chatty=True ):
0
   filePath, extension = os.path.splitext( conflictFile )
0
   
0
   # Remove .CONFLICT files.
0
0
0
@@ -261,13 +260,13 @@
0
   parser.add_option("-c", "--conflict", action="store_true", dest="conflict", default=False, help="The files being diffed have conflict markers that need to be resolved. This option is mutually exclusive to the '-r' option.")
0
   
0
   printUsage = True
0
- (options, args) = parser.parse_args(argv[1:])
0
+ ( options, args ) = parser.parse_args( argv[1:] )
0
   if options.cleanUp:
0
- if len(args) > 0:
0
+ if len( args ) > 0:
0
       for gitFile in args:
0
- cleanConflictRelatedFiles(gitFile, options.chatty)
0
- return 0
0
- if len(args) > 0:
0
+ cleanConflictRelatedFiles( gitFile, options.chatty )
0
+ return 0
0
+ if len( args ) > 0:
0
     printUsage = False
0
   
0
   # These options are mutually exclusive.
0
@@ -283,7 +282,7 @@
0
       for gitFile in args:
0
         if options.chatty:
0
           print "Diffing Conflict \"%s\"." % gitFile
0
- diffConflict(gitFile, options.chatty)
0
+ diffConflict( gitFile, options.chatty )
0
     else:
0
       if options.revision:
0
         rev = options.revision
0
@@ -300,7 +299,10 @@
0
         thread.start_new_thread( performDiff, (gitFile, rev, condition, diffsLeft, options.chatty) )
0
       condition.acquire()
0
       while diffsLeft[0] > 0:
0
- condition.wait()
0
+ try:
0
+ condition.wait()
0
+ except KeyboardInterrupt, e:
0
+ print( "\nProcess terminated.")
0
       condition.release()
0
       
0
   return 0

Comments

    No one has commented yet.