From: Barry W. <bw...@us...> - 2001-07-23 16:48:05
|
Update of /cvsroot/jython/CVSROOT In directory usw-pr-cvs1:/tmp/cvs-serv28844 Modified Files: syncmail Log Message: Sync'ing with Fred's latest version of syncmail from the Python project. Index: syncmail =================================================================== RCS file: /cvsroot/jython/CVSROOT/syncmail,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** syncmail 2000/10/29 16:59:33 1.1 --- syncmail 2001/07/23 16:48:01 1.2 *************** *** 40,43 **** --- 40,53 ---- Print this text. + --context=# + -C # + Include # lines of context around lines that differ (default: 2). + + -c + Produce a context diff (default). + + -u + Produce a unified diff (smaller, but harder to read). + <%%S> CVS %%s loginfo expansion. When invoked by CVS, this will be a single *************** *** 78,82 **** ! def calculate_diff(filespec): try: file, oldrev, newrev = string.split(filespec, ',') --- 88,92 ---- ! def calculate_diff(filespec, contextlines): try: file, oldrev, newrev = string.split(filespec, ',') *************** *** 86,96 **** if oldrev == 'NONE': try: ! fp = open(file) lines = fp.readlines() fp.close() ! lines.insert(0, '--- NEW FILE ---\n') except IOError, e: lines = ['***** Error reading new file: ', ! str(e)] elif newrev == 'NONE': lines = ['--- %s DELETED ---\n' % file] --- 96,110 ---- if oldrev == 'NONE': try: ! if os.path.exists(file): ! fp = open(file) ! else: ! update_cmd = 'cvs -fn update -r %s -p %s' % (newrev, file) ! fp = os.popen(update_cmd) lines = fp.readlines() fp.close() ! lines.insert(0, '--- NEW FILE: %s ---\n' % file) except IOError, e: lines = ['***** Error reading new file: ', ! str(e), '\n***** file: ', file, ' cwd: ', os.getcwd()] elif newrev == 'NONE': lines = ['--- %s DELETED ---\n' % file] *************** *** 98,103 **** # This /has/ to happen in the background, otherwise we'll run into CVS # lock contention. What a crock. ! diffcmd = '/usr/bin/cvs -f diff -kk -C 2 -r %s -r %s %s' % ( ! oldrev, newrev, file) fp = os.popen(diffcmd) lines = fp.readlines() --- 112,121 ---- # This /has/ to happen in the background, otherwise we'll run into CVS # lock contention. What a crock. ! if contextlines > 0: ! difftype = "-C " + str(contextlines) ! else: ! difftype = "-u" ! diffcmd = "/usr/bin/cvs -f diff -kk %s --minimal -r %s -r %s '%s'" % ( ! difftype, oldrev, newrev, file) fp = os.popen(diffcmd) lines = fp.readlines() *************** *** 115,119 **** ! def blast_mail(mailcmd, filestodiff): # cannot wait for child process or that will cause parent to retain cvs # lock for too long. Urg! --- 133,137 ---- ! def blast_mail(mailcmd, filestodiff, contextlines): # cannot wait for child process or that will cause parent to retain cvs # lock for too long. Urg! *************** *** 127,131 **** # append the diffs if available for file in filestodiff: ! fp.write(calculate_diff(file)) fp.write('\n') fp.close() --- 145,149 ---- # append the diffs if available for file in filestodiff: ! fp.write(calculate_diff(file, contextlines)) fp.write('\n') fp.close() *************** *** 137,142 **** # scan args for options def main(): try: ! opts, args = getopt.getopt(sys.argv[1:], 'h', ['cvsroot=', 'help']) except getopt.error, msg: usage(1, msg) --- 155,162 ---- # scan args for options def main(): + contextlines = 2 try: ! opts, args = getopt.getopt(sys.argv[1:], 'hC:cu', ! ['context=', 'cvsroot=', 'help']) except getopt.error, msg: usage(1, msg) *************** *** 148,151 **** --- 168,178 ---- elif opt == '--cvsroot': os.environ['CVSROOT'] = arg + elif opt in ('-C', '--context'): + contextlines = int(arg) + elif opt == '-c': + if contextlines <= 0: + contextlines = 2 + elif opt == '-u': + contextlines = 0 # What follows is the specification containing the files that were *************** *** 172,177 **** if specs[-3:] == ['-', 'New', 'directory']: del specs[-3:] print 'Generating notification message...' ! blast_mail(mailcmd, specs[1:]) print 'Generating notification message... done.' --- 199,213 ---- if specs[-3:] == ['-', 'New', 'directory']: del specs[-3:] + elif len(specs) > 2: + L = specs[:2] + for s in specs[2:]: + prev = L[-1] + if string.count(prev, ",") < 2: + L[-1] = "%s %s" % (prev, s) + else: + L.append(s) + specs = L print 'Generating notification message...' ! blast_mail(mailcmd, specs[1:], contextlines) print 'Generating notification message... done.' |