0
import thread, threading
0
from optparse import OptionParser
0
-gToolName = "git-bbdiff"
0
-gdiffVersion = gToolName + " version 1.3"
0
-gConflictMarker = ".CONFLICT"
0
-gTheirsMarker = ".THEIRS"
0
+kToolName = "git-bbdiff"
0
+kdiffVersion = kToolName + " version 1.4"
0
+kConflictMarker = ".CONFLICT"
0
+kTheirsMarker = ".THEIRS"
0
#----------------------------------------------------------------------------------------------------------------------------
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
if os.path.isdir( realpath ):
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
# 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
#----------------------------------------------------------------------------------------------------------------------------
0
def uniqueName( path, uniqueLabel ):
0
basePath, fileName = os.path.split( conflictFile )
0
print "\tThe file \"%s\" does not contain any conflicts. SKIPPING." % fileName
0
- newConflictPath = uniqueName( conflictFile,
gConflictMarker )
0
+ newConflictPath = uniqueName( conflictFile,
kConflictMarker )
0
os.rename( conflictFile, newConflictPath )
0
- theirPath = uniqueName( conflictFile,
gTheirsMarker )
0
+ theirPath = uniqueName( conflictFile,
kTheirsMarker )
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
# cleanConflictRelatedFiles
0
filePath, extension = os.path.splitext( conflictFile )
0
# Remove .CONFLICT files.
0
- tempfile = filePath +
gConflictMarker + extension
0
+ tempfile = filePath +
kConflictMarker + extension
0
if os.path.exists( tempfile ):
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
- tempfile = filePath +
gTheirsMarker + extension
0
+ tempfile = filePath +
kTheirsMarker + extension
0
if os.path.exists( tempfile ):
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
#----------------------------------------------------------------------------------------------------------------------------
0
+#----------------------------------------------------------------------------------------------------------------------------
0
+def compareModified( chatty=True ):
0
+ command = "git status"
0
+ output = commands.getoutput( command )
0
+ lines = output.split( "\n" )
0
+ modifiedFile = line.partition( "modified:" )[2].strip()
0
+ if modifiedFile != "":
0
+ modifiedFiles.append( modifiedFile )
0
+ compareFiles( modifiedFiles, "HEAD", chatty )
0
+#----------------------------------------------------------------------------------------------------------------------------
0
+#----------------------------------------------------------------------------------------------------------------------------
0
+def compareFiles( files, revision, chatty=True ):
0
+ diffsLeft = [len( files )];
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
+ print "Comparing \"%s\"." % gitFile
0
+ thread.start_new_thread( performDiff, (gitFile, revision, condition, diffsLeft, chatty) )
0
+ while diffsLeft[0] > 0:
0
+ except KeyboardInterrupt, e:
0
+ print( "\nProcess terminated.")
0
+#----------------------------------------------------------------------------------------------------------------------------
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
- 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
( options, args ) = parser.parse_args( argv[1:] )
0
cleanConflictRelatedFiles( gitFile, options.chatty )
0
+ elif options.modified:
0
+ compareModified( options.chatty )
0
# These options are mutually exclusive.
0
- diffsLeft = [len( args )];
0
- # Create a condition lock to ensure that we wait until all the diffs are done since we use the --wait option
0
- condition = threading.Condition()
0
- print "Comparing \"%s\"." % gitFile
0
- thread.start_new_thread( performDiff, (gitFile, rev, condition, diffsLeft, options.chatty) )
0
- while diffsLeft[0] > 0:
0
- except KeyboardInterrupt, e:
0
- print( "\nProcess terminated.")
0
+ compareFiles( args, rev, options.chatty )
Comments
No one has commented yet.