public
Description: Collection of scripts for performing generic git tasks
Clone URL: git://github.com/farktronix/gittools.git
Search Repo:
Obviate the need for --clean to clean the tmp directory by using the 
--wait option with bbdiff.
danpreston (author)
Sun May 11 21:28:59 -0700 2008
commit  261caf6ffdc9d66a19d7b7e087b80d6791db3718
tree    02dc1150b22ca013f26ca010564c0fa754279f5b
parent  ff787702658b80fc7f50be92e82eb1c9ff11921f
...
6
7
8
 
9
10
11
12
 
13
14
15
...
55
56
57
58
59
60
 
61
62
63
64
65
66
...
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
...
249
250
251
252
 
253
254
255
256
 
257
258
259
260
261
262
263
264
265
 
 
 
266
267
268
269
...
286
287
288
 
 
 
 
 
289
290
291
292
 
 
 
 
 
 
293
294
295
...
6
7
8
9
10
11
12
 
13
14
15
16
...
56
57
58
 
 
 
59
60
61
62
63
64
65
...
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
...
252
253
254
 
255
256
257
258
 
259
260
261
262
263
264
265
 
 
 
266
267
268
269
270
271
272
...
289
290
291
292
293
294
295
296
297
298
299
 
300
301
302
303
304
305
306
307
308
0
@@ -6,10 +6,11 @@
0
 #
0
 
0
 import sys, commands, os, tempfile, filecmp
0
+import thread, threading
0
 from optparse import OptionParser
0
 
0
 gToolName = "git-bbdiff"
0
-gdiffVersion = gToolName + " version 1.2"
0
+gdiffVersion = gToolName + " version 1.3"
0
 gTempDir = "/tmp/"
0
 gConflictMarker = ".CONFLICT"
0
 gTheirsMarker = ".THEIRS"
0
@@ -55,9 +56,7 @@
0
 #  performDiff
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
-def performDiff(compareFile, revision, chatty=True):
0
-  # Check that we have enough arguments.
0
-  
0
+def performDiff(compareFile, revision, condition, diffsLeft, chatty=True):
0
   revision, _, revision2 = revision.partition("..")
0
   
0
   realpath = os.path.abspath( compareFile )
0
0
0
0
@@ -103,24 +102,28 @@
0
       print "\tThe file \"" + fileName + "\" has no differences."
0
   else:
0
     # Escape the files with quotes to allow for files with spaces.
0
-    command = 'bbdiff "%s" "%s"' % ( file2, file1 )
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
+  
0
+  condition.acquire()
0
+  while diffsLeft[0] > 0:
0
+    condition.wait()
0
+  condition.release()
0
 
0
-
0
 #----------------------------------------------------------------------------------------------------------------------------
0
-#  cleanTmpDirectory
0
-#----------------------------------------------------------------------------------------------------------------------------
0
-
0
-def cleanTmpDirectory(chatty=True):
0
-  tempContents = os.listdir( gTempDir )
0
-  for tmpFile in tempContents:
0
-    if tmpFile.startswith( gToolName + "-" ):
0
-      filePath = gTempDir + tmpFile
0
-      if chatty:
0
-        print "\tRemoving temp file:\"%s\"" % filePath
0
-      os.remove( filePath )
0
-
0
-#----------------------------------------------------------------------------------------------------------------------------
0
 #  numConflicts
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
0
0
@@ -249,20 +252,20 @@
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] [[-c | --conflict] | [-r | --revision <revision(s)>]] file1 [file2 ...]"
0
+  usage = "usage: %prog [--version] | [-h | --help] | [-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="Delete all of the temp files that " + gToolName + " has created. If any files are passed as arguments, their --conflict related files (\"" + gConflictMarker + "\", \"" + gTheirsMarker + "\") will be deleted.")
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
   
0
   printUsage = True
0
   (options, args) = parser.parse_args(argv[1:])
0
   if options.cleanUp:
0
-    cleanTmpDirectory(options.chatty)
0
-    for gitFile in args:
0
-      cleanConflictRelatedFiles(gitFile, options.chatty)
0
+    if len(args) > 0:
0
+      for gitFile in args:
0
+        cleanConflictRelatedFiles(gitFile, options.chatty)
0
     return 0
0
   if len(args) > 0:
0
     printUsage = False
0
0
@@ -286,10 +289,20 @@
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
-        performDiff(gitFile, rev, options.chatty)
0
+        thread.start_new_thread( performDiff, (gitFile, rev, condition, diffsLeft, options.chatty) )
0
+      condition.acquire()
0
+      while diffsLeft[0] > 0:
0
+        condition.wait()
0
+      condition.release()
0
+      
0
   return 0
0
 
0
 if __name__ == "__main__":

Comments

    No one has commented yet.