public
Description: Collection of scripts for performing generic git tasks
Clone URL: git://github.com/farktronix/gittools.git
Search Repo:
Expand --clean option to clean up --conflict related files for any files 
passed as arguments.
danpreston (author)
Tue May 06 22:19:20 -0700 2008
commit  3bcaf5644eec1ce6f70cd5c61638f504a82561f0
tree    a81ac3ea042a2634f240c34389ce6484ad026ba9
parent  e3861867faaa37e5ec3fb5b7e5f42972fee60cf2
...
8
9
10
11
12
13
 
 
 
 
 
14
15
16
...
41
42
43
44
 
45
46
47
...
65
66
67
68
 
69
70
71
...
110
111
112
113
 
114
115
116
 
 
117
118
119
...
201
202
203
204
 
205
206
207
 
208
209
210
211
212
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
215
216
...
223
224
225
226
227
228
 
 
 
229
230
231
232
233
 
234
235
 
 
 
236
237
238
...
8
9
10
 
 
 
11
12
13
14
15
16
17
18
...
43
44
45
 
46
47
48
49
...
67
68
69
 
70
71
72
73
...
112
113
114
 
115
116
 
 
117
118
119
120
121
...
203
204
205
 
206
207
208
 
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
...
252
253
254
 
 
 
255
256
257
258
259
260
261
 
262
263
 
264
265
266
267
268
269
0
@@ -8,9 +8,11 @@
0
 import sys, commands, os, tempfile, filecmp
0
 from optparse import OptionParser
0
 
0
-name = "git-bbedit-diff"
0
-gdiffVersion = name + " version 1.2"
0
-tempDir = "/tmp/"
0
+gToolName = "git-bbedit-diff"
0
+gdiffVersion = gToolName + " version 1.2"
0
+gTempDir = "/tmp/"
0
+gConflictMarker = ".CONFLICT"
0
+gTheirsMarker = ".THEIRS"
0
 
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 #  fileNotPresentError
0
@@ -41,7 +43,7 @@ def createTempFileForRevision( revision, repositoryPath, chatty=True ):
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, name + "-" + revision + "_", tempDir )
0
+  temp = tempfile.mktemp( "_" + fileName + extension, gToolName + "-" + revision + "_", gTempDir )
0
   f = open( temp, 'w' )
0
   f.write( output )
0
   f.close()
0
@@ -65,7 +67,7 @@ def performDiff(compareFile, revision, chatty=True):
0
   
0
   if os.path.isdir( realpath ):
0
     if chatty:
0
-      print "\t\"" + relativePath + "\" is a directory. " + name + " only compares files."
0
+      print "\t\"" + relativePath + "\" is a directory. " + gToolName + " only compares files."
0
     return
0
   
0
   found = False;
0
@@ -110,10 +112,10 @@ def performDiff(compareFile, revision, chatty=True):
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
 def cleanTmpDirectory(chatty=True):
0
-  tempContents = os.listdir( tempDir )
0
+  tempContents = os.listdir( gTempDir )
0
   for tmpFile in tempContents:
0
-    if tmpFile.startswith( name + "-" ):
0
-      filePath = tempDir + tmpFile
0
+    if tmpFile.startswith( gToolName + "-" ):
0
+      filePath = gTempDir + tmpFile
0
       if chatty:
0
         print "\tRemoving temp file:\"%s\"" % filePath
0
       os.remove( filePath )
0
@@ -201,16 +203,43 @@ def diffConflict(conflictFile, chatty=True):
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, ".CONFLICT")
0
+    newConflictPath = uniqueName(conflictFile, gConflictMarker)
0
     os.rename(conflictFile, newConflictPath)
0
     
0
-    theirPath = uniqueName(conflictFile, ".THEIRS")
0
+    theirPath = uniqueName(conflictFile, gTheirsMarker)
0
     
0
     createConflictFiles(conflictFile, theirPath, newConflictPath)
0
     command = 'bbdiff "%s" "%s"' % ( conflictFile, theirPath )
0
     status, output = commands.getstatusoutput( command )
0
 
0
 #----------------------------------------------------------------------------------------------------------------------------
0
+#  cleanConflictRelatedFiles
0
+#----------------------------------------------------------------------------------------------------------------------------
0
+
0
+def cleanConflictRelatedFiles(conflictFile, chatty=True):
0
+  filePath, extension = os.path.splitext( conflictFile )
0
+  
0
+  # Remove .CONFLICT files.
0
+  tempfile = filePath + gConflictMarker + extension
0
+  if os.path.exists( tempfile ):
0
+    if chatty:
0
+      _, base = os.path.split( filePath )
0
+      base = base + gConflictMarker + 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
+  if os.path.exists( tempfile ):
0
+    if chatty:
0
+      _, base = os.path.split( filePath )
0
+      base = base + gTheirsMarker + extension
0
+      print "\tDeleting file \"%s\"." % base
0
+    command = "rm " + tempfile
0
+    os.remove( tempfile )
0
+
0
+#----------------------------------------------------------------------------------------------------------------------------
0
 #  main
0
 #----------------------------------------------------------------------------------------------------------------------------
0
 
0
@@ -223,16 +252,18 @@ def main(argv=None):
0
   usage = "usage: %prog [--version] | [-h | --help] | [-q | --quiet] [--clean] [[-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 " + name + " to compare. This option is mutually exclusive to the '-c' option.")
0
-  parser.add_option("--clean", action="store_true", dest="cleanTmp", default=False, help="Delete all of the temp files that " + name + " has created. This will not affect the files currently being compared if any.")
0
-  parser.add_option("-q", "--quiet", action="store_false", dest="chatty", default=True, help="Reduce the chatter of " + name + ".")
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("-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.cleanTmp:
0
+  if options.cleanUp:
0
     cleanTmpDirectory(options.chatty)
0
-    printUsage = False
0
+    for gitFile in args:
0
+      cleanConflictRelatedFiles(gitFile, options.chatty)
0
+    return 0
0
   if len(args) > 0:
0
     printUsage = False
0
   

Comments

    No one has commented yet.