From 2ba27b00384c55ec7fe29e09ce2d2c3e8eeb0977 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 3 Mar 2012 11:19:43 -0500 Subject: [PATCH] Make ID expansion less strict for comment text. This avoids errors if the comment text references a repository that you don't have locally. --- libbe/util/id.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libbe/util/id.py b/libbe/util/id.py index 8dc6075..9a90af5 100644 --- a/libbe/util/id.py +++ b/libbe/util/id.py @@ -471,17 +471,24 @@ class IDreplacer (object): -------- short_to_long_text, long_to_short_text """ - def __init__(self, bugdirs, replace_fn, wrap=True): + def __init__(self, bugdirs, replace_fn, wrap=True, strict=True): self.bugdirs = bugdirs self.replace_fn = replace_fn self.wrap = wrap + self.strict = strict + def __call__(self, match): ids = [] for m in match.groups(): if m == None: m = '' ids.append(m) - replacement = self.replace_fn(self.bugdirs, ''.join(ids)) + try: + replacement = self.replace_fn(self.bugdirs, ''.join(ids)) + except (MultipleIDMatches, NoIDMatches, InvalidIDStructure): + if self.strict: + raise + replacement = ''.join(ids) if self.wrap == True: return '#%s#' % replacement return replacement @@ -496,7 +503,8 @@ def short_to_long_text(bugdirs, text): short_to_long_user : conversion on a single ID long_to_short_text : inverse """ - return re.sub(REGEXP, IDreplacer(bugdirs, short_to_long_user), text) + return re.sub( + REGEXP, IDreplacer(bugdirs, short_to_long_user, strict=False), text) def long_to_short_text(bugdirs, text): """Convert long user IDs to short user IDs in text (see :class:`ID`). -- 2.26.2