diff --git a/git_upstream/lib/__init__.py b/git_upstream/lib/__init__.py index e69de29..ec4c919 100644 --- a/git_upstream/lib/__init__.py +++ b/git_upstream/lib/__init__.py @@ -0,0 +1,18 @@ +# Copyright (c) 2012, 2013, 2014 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +IMPORT_NOTE_REF = 'refs/notes/upstream-merge' +SUPERSEDE_HEADER = 'Superseded-by:' +DROP_HEADER = 'Dropped:' diff --git a/git_upstream/lib/drop.py b/git_upstream/lib/drop.py index b9fa753..7a7aca4 100644 --- a/git_upstream/lib/drop.py +++ b/git_upstream/lib/drop.py @@ -20,6 +20,7 @@ import re from git import BadObject from git_upstream.errors import GitUpstreamError +from git_upstream import lib from git_upstream.lib.pygitcompat import BadName from git_upstream.lib.utils import GitMixin from git_upstream.log import LogDedentMixin @@ -44,9 +45,6 @@ class Drop(LogDedentMixin, GitMixin): """ - DROP_HEADER = 'Dropped:' - NOTE_REF = 'refs/notes/upstream-merge' - def __init__(self, git_object=None, author=None, *args, **kwargs): # make sure to correctly initialize inherited objects before performing @@ -90,9 +88,9 @@ class Drop(LogDedentMixin, GitMixin): def check_duplicates(self): """Check if a dropped header is already present""" - note = self.commit.note(note_ref=Drop.NOTE_REF) + note = self.commit.note(note_ref=lib.IMPORT_NOTE_REF) if note: - pattern = '^%s\s*(.+)' % Drop.DROP_HEADER + pattern = '^%s\s*(.+)' % lib.DROP_HEADER m = re.search(pattern, note, re.MULTILINE | re.IGNORECASE) if m: self.log.warning( @@ -108,10 +106,10 @@ class Drop(LogDedentMixin, GitMixin): self.log.debug("Creating a note for commit '%s'", self.commit) if self.check_duplicates(): - git_note = '%s %s\n' % (Drop.DROP_HEADER, self.author) + git_note = '%s %s\n' % (lib.DROP_HEADER, self.author) self.log.debug('With the following content:') self.log.debug(git_note) - self.commit.append_note(git_note, note_ref=Drop.NOTE_REF) + self.commit.append_note(git_note, note_ref=lib.IMPORT_NOTE_REF) else: self.log.warning( "Drop note has not been added as '%s' already has one" % diff --git a/git_upstream/lib/searchers.py b/git_upstream/lib/searchers.py index 57cc2ac..52717c5 100644 --- a/git_upstream/lib/searchers.py +++ b/git_upstream/lib/searchers.py @@ -20,6 +20,7 @@ from abc import abstractmethod import itertools import re +from git_upstream import lib from git_upstream.lib.pygitcompat import Commit from git_upstream.lib.utils import GitMixin from git_upstream.log import LogDedentMixin @@ -496,9 +497,6 @@ class SupersededCommitFilter(LogDedentMixin, GitMixin, CommitFilter): (optional). """ - SUPERSEDE_HEADER = 'Superseded-by:' - NOTE_REF = 'refs/notes/upstream-merge' - def __init__(self, search_ref, limit=None, *args, **kwargs): super(SupersededCommitFilter, self).__init__(*args, **kwargs) @@ -554,11 +552,11 @@ class SupersededCommitFilter(LogDedentMixin, GitMixin, CommitFilter): """, self.search_ref) supersede_re = re.compile('^%s\s*(.+)\s*$' % - SupersededCommitFilter.SUPERSEDE_HEADER, + lib.SUPERSEDE_HEADER, re.IGNORECASE | re.MULTILINE) for commit in commit_iter: - commit_note = commit.note(note_ref=SupersededCommitFilter.NOTE_REF) + commit_note = commit.note(note_ref=lib.IMPORT_NOTE_REF) # include non-annotated commits if not commit_note: yield commit @@ -616,15 +614,12 @@ class DroppedCommitFilter(LogDedentMixin, CommitFilter): Prunes all commits that have a note with the Dropped: header """ - DROPPED_HEADER = 'Dropped:' - NOTE_REF = 'refs/notes/upstream-merge' - def filter(self, commit_iter): for commit in commit_iter: - commit_note = commit.note(note_ref=DroppedCommitFilter.NOTE_REF) + commit_note = commit.note(note_ref=lib.IMPORT_NOTE_REF) if not commit_note: yield commit - elif not re.match('^%s.+' % DroppedCommitFilter.DROPPED_HEADER, + elif not re.match('^%s.+' % lib.DROP_HEADER, commit_note, re.IGNORECASE | re.MULTILINE): yield commit else: diff --git a/git_upstream/lib/supersede.py b/git_upstream/lib/supersede.py index aca5d9a..aa10ef6 100644 --- a/git_upstream/lib/supersede.py +++ b/git_upstream/lib/supersede.py @@ -21,7 +21,7 @@ from git import BadObject from git import Head from git_upstream.errors import GitUpstreamError -from git_upstream.lib import note # noqa +from git_upstream import lib from git_upstream.lib.pygitcompat import BadName from git_upstream.lib.searchers import CommitMessageSearcher from git_upstream.lib.utils import GitMixin @@ -46,9 +46,6 @@ class Supersede(LogDedentMixin, GitMixin): """ - SUPERSEDE_HEADER = 'Superseded-by:' - NOTE_REF = 'refs/notes/upstream-merge' - CHANGE_ID_REGEX = '^I[0-9a-f]{6,40}$' CHANGE_ID_HEADER_REGEX_FMT = '^Change-Id:\s*%s' CHANGE_ID_HEADER_REGEX = '^Change-Id:\s*(I[0-9a-f]{6,40})$' @@ -135,9 +132,9 @@ class Supersede(LogDedentMixin, GitMixin): Check if a supersede header is already present in the note containing one of change ids passed on the command line """ - new_note = self.commit.note(note_ref=Supersede.NOTE_REF) + new_note = self.commit.note(note_ref=lib.IMPORT_NOTE_REF) if new_note: - pattern = '^%s\s?(%s)$' % (Supersede.SUPERSEDE_HEADER, + pattern = '^%s\s?(%s)$' % (lib.SUPERSEDE_HEADER, '|'.join(self.change_ids)) m = re.search(pattern, new_note, re.MULTILINE | re.IGNORECASE) if m: @@ -154,9 +151,9 @@ class Supersede(LogDedentMixin, GitMixin): if self.check_duplicates(): git_note = '' for change_id in self.change_ids: - git_note += '%s %s\n' % (Supersede.SUPERSEDE_HEADER, change_id) + git_note += '%s %s\n' % (lib.SUPERSEDE_HEADER, change_id) self.log.debug('With the following content:') self.log.debug(git_note) - self.commit.append_note(git_note, note_ref=Supersede.NOTE_REF) + self.commit.append_note(git_note, note_ref=lib.IMPORT_NOTE_REF) else: self.log.warning('Note has not been added')