[PATCH] Introduce a 'die' function.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Fredrik Kuivinen
2005-09-12 23:30:47 +02:00
committed by Junio C Hamano
parent ace36858d3
commit 654291a2ac
2 changed files with 13 additions and 14 deletions

View File

@ -120,9 +120,8 @@ def unmergedCacheEntries():
e.stages[stage].mode = mode e.stages[stage].mode = mode
e.stages[stage].sha1 = sha1 e.stages[stage].sha1 = sha1
else: else:
print 'Error: Merge program failed: Unexpected output from', \ die('Error: Merge program failed: Unexpected output from', \
'git-ls-files:', l 'git-ls-files:', l)
sys.exit(2)
return res return res
def mergeTrees(head, merge, common, branch1Name, branch2Name, def mergeTrees(head, merge, common, branch1Name, branch2Name,
@ -381,15 +380,12 @@ def processEntry(entry, branch1Name, branch2Name, files, dirs,
os.unlink(src1) os.unlink(src1)
os.unlink(src2) os.unlink(src2)
else: else:
print 'ERROR: Fatal merge failure.' die("ERROR: Fatal merge failure, shouldn't happen.")
print "ERROR: Shouldn't happen"
sys.exit(2)
return cleanMerge return cleanMerge
def usage(): def usage():
print 'Usage:', sys.argv[0], ' <base>... -- <head> <remote>..' die('Usage:', sys.argv[0], ' <base>... -- <head> <remote>..')
sys.exit(2)
# main entry point as merge strategy module # main entry point as merge strategy module
# The first parameters up to -- are merge bases, and the rest are heads. # The first parameters up to -- are merge bases, and the rest are heads.
@ -399,8 +395,7 @@ def usage():
for nextArg in xrange(1, len(sys.argv)): for nextArg in xrange(1, len(sys.argv)):
if sys.argv[nextArg] == '--': if sys.argv[nextArg] == '--':
if len(sys.argv) != nextArg + 3: if len(sys.argv) != nextArg + 3:
print 'Not handling anything other than two heads merge.' die('Not handling anything other than two heads merge.')
sys.exit(2)
try: try:
h1 = firstBranch = sys.argv[nextArg + 1] h1 = firstBranch = sys.argv[nextArg + 1]
h2 = secondBranch = sys.argv[nextArg + 2] h2 = secondBranch = sys.argv[nextArg + 2]

View File

@ -10,6 +10,10 @@ if sys.version_info[0] < 2 or \
import subprocess import subprocess
def die(*args):
printList(args, sys.stderr)
sys.exit(2)
# Debugging machinery # Debugging machinery
# ------------------- # -------------------
@ -28,11 +32,11 @@ def debug(*args):
if funcName in functionsToDebug: if funcName in functionsToDebug:
printList(args) printList(args)
def printList(list): def printList(list, file=sys.stdout):
for x in list: for x in list:
sys.stdout.write(str(x)) file.write(str(x))
sys.stdout.write(' ') file.write(' ')
sys.stdout.write('\n') file.write('\n')
# Program execution # Program execution
# ----------------- # -----------------