public
Description: Collection of scripts for performing generic git tasks
Clone URL: git://github.com/farktronix/gittools.git
Search Repo:
Added --modified option. git-bbdiff will compare any modified files in the 
git repository.
danpreston (author)
Mon May 12 02:31:16 -0700 2008
commit  1f5ebd858a12e080f4c7a137444fedc0767a9c63
tree    f9512613f4e2f544fa26f469f434584eeb063c9c
parent  e3432778bc58cfa462629c1bc14ad89eb0a62daf
...
9
10
11
12
13
14
15
16
 
 
 
 
 
17
18
19
...
43
44
45
46
 
47
48
49
...
74
75
76
77
 
78
79
80
...
114
115
116
117
 
118
119
120
...
148
149
150
151
 
152
153
154
155
156
...
205
206
207
208
 
209
210
211
 
212
213
214
215
 
216
217
218
219
220
221
222
...
222
223
224
225
 
226
227
228
229
 
230
231
232
233
234
235
 
236
237
238
239
 
240
241
242
243
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
246
247
248
...
251
252
253
254
 
255
256
257
258
259
260
 
 
 
 
 
 
261
262
263
...
266
267
268
269
 
 
 
 
270
271
272
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
 
307
308
309
...
9
10
11
 
 
 
 
 
12
13
14
15
16
17
18
19
...
43
44
45
 
46
47
48
49
...
74
75
76
 
77
78
79
80
...
114
115
116
 
117
118
119
120
...
148
149
150
 
151
152
153
154
155
156
...
205
206
207
 
208
209
210
 
211
212
213
214
 
215
216
217
218
219
220
221
222
...
222
223
224
 
225
226
227
228
 
229
230
231
232
233
234
 
235
236
237
238
 
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
...
287
288
289
 
290
291
 
 
 
 
 
292
293
294
295
296
297
298
299
300
...
303
304
305
 
306
307
308
309
310
311
312
...
328
329
330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
332
333
334
0
@@ -9,11 +9,11 @@
0
 import thread, threading
0
 from optparse import OptionParser
0
 
0
-gToolName = "git-bbdiff"
0
-gdiffVersion = gToolName + " version 1.3"
0
-gTempDir = "/tmp/"
0
-gConflictMarker = ".CONFLICT"
0
-gTheirsMarker = ".THEIRS"
0
+kToolName = "git-bbdiff"
0
+kdiffVersion = kToolName + " version 1.4"
0
+kTempDir = "/tmp/"
0
+kConflictMarker = ".CONFLICT"
0
+kTheirsMarker = ".THEIRS"
0
 
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 #  fileNotPresentError
0
@@ -43,7 +43,7 @@
0
   # Create the temp file name and write out the temp file.
0
   nameRoot, extension = os.path.splitext( repositoryPath )
0
   _, fileName = os.path.split( nameRoot )
0
- temp = tempfile.mktemp( "_" + fileName + extension, gToolName + "-" + revision + "_", gTempDir )
0
+ temp = tempfile.mktemp( "_" + fileName + extension, kToolName + "-" + revision + "_", kTempDir )
0
   f = open( temp, 'w' )
0
   f.write( output )
0
   f.close()
0
@@ -74,7 +74,7 @@
0
   
0
   if os.path.isdir( realpath ):
0
     if chatty:
0
- print "\t\"" + relativePath + "\" is a directory. " + gToolName + " only compares files."
0
+ print "\t\"" + relativePath + "\" is a directory. " + kToolName + " only compares files."
0
     signalDiffProcessed( condition, diffsLeft )
0
     return
0
   
0
@@ -114,7 +114,7 @@
0
   else:
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
+ output = commands.getoutput( command )
0
   
0
   os.remove( file1 )
0
   if revision2:
0
@@ -148,7 +148,7 @@
0
   return conflicts
0
 
0
 #----------------------------------------------------------------------------------------------------------------------------
0
-# renameConflictFile
0
+# uniqueName
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
 def uniqueName( path, uniqueLabel ):
0
0
0
@@ -205,14 +205,14 @@
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
+ newConflictPath = uniqueName( conflictFile, kConflictMarker )
0
     os.rename( conflictFile, newConflictPath )
0
     
0
- theirPath = uniqueName( conflictFile, gTheirsMarker )
0
+ theirPath = uniqueName( conflictFile, kTheirsMarker )
0
     
0
     createConflictFiles( conflictFile, theirPath, newConflictPath )
0
     command = 'bbdiff "%s" "%s"' % ( conflictFile, theirPath )
0
- status, output = commands.getstatusoutput( command )
0
+ output = commands.getoutput( command )
0
 
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 #  cleanConflictRelatedFiles
0
0
0
0
0
@@ -222,26 +222,62 @@
0
   filePath, extension = os.path.splitext( conflictFile )
0
   
0
   # Remove .CONFLICT files.
0
- tempfile = filePath + gConflictMarker + extension
0
+ tempfile = filePath + kConflictMarker + extension
0
   if os.path.exists( tempfile ):
0
     if chatty:
0
       _, base = os.path.split( filePath )
0
- base = base + gConflictMarker + extension
0
+ base = base + kConflictMarker + extension
0
       print "\tDeleting file \"%s\"." % base
0
     command = "rm " + tempfile
0
     os.remove( tempfile )
0
   
0
   #remove .THEIRS files.
0
- tempfile = filePath + gTheirsMarker + extension
0
+ tempfile = filePath + kTheirsMarker + extension
0
   if os.path.exists( tempfile ):
0
     if chatty:
0
       _, base = os.path.split( filePath )
0
- base = base + gTheirsMarker + extension
0
+ base = base + kTheirsMarker + extension
0
       print "\tDeleting file \"%s\"." % base
0
     command = "rm " + tempfile
0
     os.remove( tempfile )
0
 
0
 #----------------------------------------------------------------------------------------------------------------------------
0
+# compareModified
0
+#----------------------------------------------------------------------------------------------------------------------------
0
+
0
+def compareModified( chatty=True ):
0
+ command = "git status"
0
+ output = commands.getoutput( command )
0
+ lines = output.split( "\n" )
0
+ modifiedFiles = []
0
+ for line in lines:
0
+ modifiedFile = line.partition( "modified:" )[2].strip()
0
+ if modifiedFile != "":
0
+ modifiedFiles.append( modifiedFile )
0
+ compareFiles( modifiedFiles, "HEAD", chatty )
0
+
0
+#----------------------------------------------------------------------------------------------------------------------------
0
+# compareFiles
0
+#----------------------------------------------------------------------------------------------------------------------------
0
+
0
+def compareFiles( files, revision, chatty=True ):
0
+ diffsLeft = [len( files )];
0
+
0
+ # Create a condition lock to ensure that we wait until all the diffs are done since we use the --wait option in bbdiff.
0
+ condition = threading.Condition()
0
+ for gitFile in files:
0
+ if chatty:
0
+ print "Comparing \"%s\"." % gitFile
0
+ thread.start_new_thread( performDiff, (gitFile, revision, condition, diffsLeft, chatty) )
0
+ condition.acquire()
0
+ while diffsLeft[0] > 0:
0
+ try:
0
+ condition.wait()
0
+ except KeyboardInterrupt, e:
0
+ print( "\nProcess terminated.")
0
+ condition.release()
0
+
0
+#----------------------------------------------------------------------------------------------------------------------------
0
 #  main
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
0
@@ -251,13 +287,14 @@
0
   
0
   # Set up options for the command line that we support.
0
   description="A utility to compare files in a git repository using bbedit."
0
- usage = "usage: %prog [--version] | [-h | --help] | [-q | --quiet] [--clean file1 [file2 ...]] [[-c | --conflict] | [-r | --revision <revision(s)>]] file1 [file2 ...]"
0
+ usage = "usage: %prog [--version] | [-h] | [-q | --quiet] [--clean file1 [file2 ...]] [[-c | --conflict] | [-r | --revision <revision(s)>]] file1 [file2 ...]"
0
   
0
- parser = OptionParser(version=gdiffVersion, description=description, usage=usage)
0
- parser.add_option("-r", "--revision", dest="revision", help="Pass a revision or a revision range using the git syntax (ie: 98d4cf..bfced5) for " + gToolName + " to compare. This option is mutually exclusive to the '-c' option.")
0
- parser.add_option("--clean", action="store_true", dest="cleanUp", default=False, help="Conflict (--conflict) related files (\"" + gConflictMarker + "\", \"" + gTheirsMarker + "\") will be deleted for any files that are passed as arguments. Requires at least one file path as an argument.")
0
- parser.add_option("-q", "--quiet", action="store_false", dest="chatty", default=True, help="Reduce the chatter of " + gToolName + ".")
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
+ parser = OptionParser(version=kdiffVersion, description=description, usage=usage)
0
+ parser.add_option( "-r", "--revision", dest="revision", help="Pass a revision or a revision range using the git syntax (ie: 98d4cf..bfced5) for " + kToolName + " to compare. This option is mutually exclusive to the '-c' option." )
0
+ parser.add_option( "-m", "--modified", action="store_true", dest="modified", help="Compare files that have been modified against HEAD." )
0
+ parser.add_option( "--clean", action="store_true", dest="cleanUp", default=False, help="Conflict (--conflict) related files (\"" + kConflictMarker + "\", \"" + kTheirsMarker + "\") will be deleted for any files that are passed as arguments. Requires at least one file path as an argument." )
0
+ parser.add_option( "-q", "--quiet", action="store_false", dest="chatty", default=True, help="Reduce the chatter of " + kToolName + "." )
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
@@ -266,7 +303,10 @@
0
       for gitFile in args:
0
         cleanConflictRelatedFiles( gitFile, options.chatty )
0
       return 0
0
- if len( args ) > 0:
0
+ elif options.modified:
0
+ compareModified( options.chatty )
0
+ return 0
0
+ elif len( args ) > 0:
0
     printUsage = False
0
   
0
   # These options are mutually exclusive.
0
@@ -288,22 +328,7 @@
0
         rev = options.revision
0
       else:
0
         rev = "HEAD"
0
- diffsLeft = [len( args )];
0
-
0
- # Create a condition lock to ensure that we wait until all the diffs are done since we use the --wait option
0
- # in bbdiff.
0
- condition = threading.Condition()
0
- for gitFile in args:
0
- if options.chatty:
0
- print "Comparing \"%s\"." % gitFile
0
- thread.start_new_thread( performDiff, (gitFile, rev, condition, diffsLeft, options.chatty) )
0
- condition.acquire()
0
- while diffsLeft[0] > 0:
0
- try:
0
- condition.wait()
0
- except KeyboardInterrupt, e:
0
- print( "\nProcess terminated.")
0
- condition.release()
0
+ compareFiles( args, rev, options.chatty )
0
       
0
   return 0
0
 

Comments

    No one has commented yet.