0
import sys, commands, os, tempfile, filecmp
0
from optparse import OptionParser
0
-name = "git-bbedit-diff"
0
-gdiffVersion = name + " version 1.2"
0
+gToolName = "git-bbedit-diff"
0
+gdiffVersion = gToolName + " version 1.2"
0
+gConflictMarker = ".CONFLICT"
0
+gTheirsMarker = ".THEIRS"
0
#----------------------------------------------------------------------------------------------------------------------------
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
@@ -65,7 +67,7 @@ def performDiff(compareFile, revision, chatty=True):
0
if os.path.isdir( realpath ):
0
- print "\t\"" + relativePath + "\" is a directory. " + name + " only compares files."
0
+ print "\t\"" + relativePath + "\" is a directory. " + gToolName + " only compares files."
0
@@ -110,10 +112,10 @@ def performDiff(compareFile, revision, chatty=True):
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
print "\tRemoving temp file:\"%s\"" % 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
- newConflictPath = uniqueName(conflictFile, ".CONFLICT")
0
+ newConflictPath = uniqueName(conflictFile, gConflictMarker)
0
os.rename(conflictFile, newConflictPath)
0
- theirPath = uniqueName(conflictFile, ".THEIRS")
0
+ theirPath = uniqueName(conflictFile, gTheirsMarker)
0
createConflictFiles(conflictFile, theirPath, newConflictPath)
0
command = 'bbdiff "%s" "%s"' % ( conflictFile, theirPath )
0
status, output = commands.getstatusoutput( command )
0
#----------------------------------------------------------------------------------------------------------------------------
0
+# cleanConflictRelatedFiles
0
+#----------------------------------------------------------------------------------------------------------------------------
0
+def cleanConflictRelatedFiles(conflictFile, chatty=True):
0
+ filePath, extension = os.path.splitext( conflictFile )
0
+ # Remove .CONFLICT files.
0
+ tempfile = filePath + gConflictMarker + extension
0
+ if os.path.exists( tempfile ):
0
+ _, base = os.path.split( filePath )
0
+ base = base + gConflictMarker + extension
0
+ print "\tDeleting file \"%s\"." % base
0
+ command = "rm " + tempfile
0
+ #remove .THEIRS files.
0
+ tempfile = filePath + gTheirsMarker + extension
0
+ if os.path.exists( tempfile ):
0
+ _, base = os.path.split( filePath )
0
+ base = base + gTheirsMarker + extension
0
+ print "\tDeleting file \"%s\"." % base
0
+ command = "rm " + tempfile
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
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
(options, args) = parser.parse_args(argv[1:])
0
cleanTmpDirectory(options.chatty)
0
+ cleanConflictRelatedFiles(gitFile, options.chatty)
Comments
No one has commented yet.