--- mailer-120.py 2005-08-18 12:32:15.000000000 +0200 +++ mailer-size_and_filediff-120.py 2005-08-19 11:47:50.000000000 +0200 @@ -667,6 +667,28 @@ if self.paths.has_key(path) != self.in_paths: continue + #Added ny JonB 20050818 + patern_matching = None + reason = '' + + filediff_conf = open(diff_config_fname, 'r') + diffpatern = filediff_conf.readline() + while diffpatern != '': + fixed_diff_patern = diffpatern.strip() + comment_matching = re.search('^#',fixed_diff_patern) + if comment_matching != None: + diffpatern = filediff_conf.readline() + continue + patern_matching = re.search(fixed_diff_patern,change.path) + if patern_matching == None: + diffpatern = filediff_conf.readline() + else: + break + + if patern_matching != None: + reason = 'FORCED Binary file because of patern: %s\n' % fixed_diff_patern + + # figure out if/how to generate a diff if not change.path: @@ -674,13 +696,16 @@ if not self.diffsels.delete: continue + # what is kind == R used for? in class TextCommitRenderer there is an + # unused kind == D ?? kind = 'R' - diff = svn.fs.FileDiff(self.repos.get_root(change.base_rev), - change.base_path, None, None, self.pool) + if reason == '': + diff = svn.fs.FileDiff(self.repos.get_root(change.base_rev), + change.base_path, None, None, self.pool) - label1 = '%s\t%s' % (change.base_path, self.date) - label2 = '(empty file)' - singular = True + label1 = '%s\t%s' % (change.base_path, self.date) + label2 = '(empty file)' + singular = True elif change.added: if change.base_path and (change.base_rev != -1): # this file was copied. any diff to show? should we? @@ -688,24 +713,26 @@ continue kind = 'C' - diff = svn.fs.FileDiff(self.repos.get_root(change.base_rev), - change.base_path, - self.repos.root_this, change.path, - self.pool) - label1 = change.base_path + '\t(original)' - label2 = '%s\t%s' % (change.path, self.date) - singular = False + if reason == '': + diff = svn.fs.FileDiff(self.repos.get_root(change.base_rev), + change.base_path, + self.repos.root_this, change.path, + self.pool) + label1 = change.base_path + '\t(original)' + label2 = '%s\t%s' % (change.path, self.date) + singular = False else: # the file was added. should we show it? if not self.diffsels.add: continue kind = 'A' - diff = svn.fs.FileDiff(None, None, self.repos.root_this, + if reason == '': + diff = svn.fs.FileDiff(None, None, self.repos.root_this, change.path, self.pool) - label1 = '(empty file)' - label2 = '%s\t%s' % (change.path, self.date) - singular = True + label1 = '(empty file)' + label2 = '%s\t%s' % (change.path, self.date) + singular = True elif not change.text_changed: # the text didn't change, so nothing to show. @@ -716,41 +743,55 @@ continue kind = 'M' - diff = svn.fs.FileDiff(self.repos.get_root(change.base_rev), + if reason == '': + diff = svn.fs.FileDiff(self.repos.get_root(change.base_rev), change.base_path, self.repos.root_this, change.path, self.pool) - label1 = change.base_path + '\t(original)' - label2 = '%s\t%s' % (change.path, self.date) - singular = False - - binary = diff.either_binary() - if binary: - content = src_fname = dst_fname = None - else: - src_fname, dst_fname = diff.get_files() - content = DiffContent(self.cfg.get_diff_cmd(self.group, { - 'label_from' : label1, - 'label_to' : label2, - 'from' : src_fname, - 'to' : dst_fname, - })) - - # return a data item for this diff - return _data( - kind=kind, - path=change.path, - base_path=change.base_path, - base_rev=change.base_rev, - label_from=label1, - label_to=label2, - from_fname=src_fname, - to_fname=dst_fname, - binary=binary, - singular=singular, - content=content, - diff=diff, - ) + label1 = change.base_path + '\t(original)' + label2 = '%s\t%s' % (change.path, self.date) + singular = False + + if reason == '': + binary = diff.either_binary() + if binary: + content = src_fname = dst_fname = None + else: + src_fname, dst_fname = diff.get_files() + content = DiffContent(self.cfg.get_diff_cmd(self.group, { + 'label_from' : label1, + 'label_to' : label2, + 'from' : src_fname, + 'to' : dst_fname, + })) + + + if reason == '': + # return a data item for this diff + return _data( + kind=kind, + path=change.path, + base_path=change.base_path, + base_rev=change.base_rev, + label_from=label1, + label_to=label2, + from_fname=src_fname, + to_fname=dst_fname, + binary=binary, + singular=singular, + content=content, + diff=diff, + ) + else: + # the lowercase letter is used to indicate that there is a "reason" for no diff + newkind = string.lower(kind) + return _data( + kind=newkind, + path=change.path, + base_path=change.base_path, + base_rev=change.base_rev, + reason=reason, + ) class DiffContent: @@ -872,7 +913,16 @@ def _render_diffs(self, diffs): w = self.output.write + # added by JonB 18 august 2005 to limit max mailsize to 2MB. + max_mail_size = 2*1024*1024 + max_files_included = 128 + i = 0 + for diff in diffs: + i = i + 1 + if i > max_files_included: + w('\n================ MAX NUMBER OF FILES=%s IS REACHED, NO MORE DIFF ================\n' % max_files_included) + break if diff.kind == 'D': w('\nDeleted: %s\n' % diff.base_path) elif diff.kind == 'C': @@ -880,9 +930,32 @@ % (diff.path, diff.base_rev, diff.base_path)) elif diff.kind == 'A': w('\nAdded: %s\n' % diff.path) - else: + elif diff.kind == 'M': # kind == 'M' w('\nModified: %s\n' % diff.path) + elif diff.kind == 'd': # for some "reason" the is no diff + w('\nDeleted: %s\n' % diff.base_path) + w(SEPARATOR + '\n') + w(diff.reason) + continue + elif diff.kind == 'c': # for some "reason" the is no diff + w('\nCopied: %s (from r%d, %s)\n' + % (diff.path, diff.base_rev, diff.base_path)) + w(SEPARATOR + '\n') + w(diff.reason) + continue + elif diff.kind == 'a': # for some "reason" the is no diff + w('\nAdded: %s\n' % diff.path) + w(SEPARATOR + '\n') + w(diff.reason) + continue + elif diff.kind == 'm': # for some "reason" the is no diff + w('\nModified: %s\n' % diff.path) + w(SEPARATOR + '\n') + w(diff.reason) + continue + else: + unusedvariable='The else should never be taken' w(SEPARATOR + '\n') @@ -894,6 +967,13 @@ continue for line in diff.content: + max_mail_size = max_mail_size - len(line.raw) + if max_mail_size <= 0: + w('================ MAX MAILSIZE=%s IS REACHED NO MORE DIFF INCLUDED ================\n' % max_mail_size) + max_files_included = 0 + i = 512 + # the above are to be sure to leave the diff generation + break w(line.raw) @@ -1163,6 +1243,7 @@ } config_fname = None + diff_config_fname = None argc = len(sys.argv) if argc < 3: usage() @@ -1192,6 +1273,16 @@ raise MissingConfig(config_fname) config_fp = open(config_fname) + # Settle on a filediff file location, and open it. + if diff_config_fname is None: + # Default to REPOS-DIR/conf/filediff.conf. + diff_config_fname = os.path.join(repos_dir, 'conf', 'filediff.conf') + if not os.path.exists(diff_config_fname): + # Okay. Look for 'filediff.conf' as a sibling of this script. + diff_config_fname = os.path.join(os.path.dirname(sys.argv[0]), 'filediff.conf') + if not os.path.exists(diff_config_fname): + raise MissingConfig(diff_config_fname) + svn.core.run_app(main, cmd, config_fname, repos_dir, sys.argv[3:3+expected_args])