Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to rpm-ch #51

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
124 changes: 123 additions & 1 deletion docs/manpages/gbp-rpm-ch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
<arg><option>--packaging-dir=</option><replaceable>DIRECTORY</replaceable></arg>
<arg><option>--changelog-file=</option><replaceable>FILEPATH</replaceable></arg>
<arg><option>--spec-file=</option><replaceable>FILEPATH</replaceable></arg>
<arg><option>--since=</option><replaceable>COMMITISH</replaceable></arg>
<group>
<arg><option>--all</option></arg>
<arg><option>--message=</option><replaceable>MESSAGE</replaceable></arg>
<arg><option>--since=</option><replaceable>COMMITISH</replaceable></arg>
</group>
<arg><option>--meta-bts=</option><replaceable>META_TAGS</replaceable></arg>
<arg><option>--no-release</option></arg>
<arg><option>--[no-]git-author</option></arg>
<arg><option>--[no-]full</option></arg>
Expand All @@ -38,6 +43,13 @@
<arg><option>--git-log=</option><replaceable>GIT-LOG-OPTIONS</replaceable></arg>
<arg><option>--spawn-editor=<replaceable>[always|release|no]</replaceable></option></arg>
<arg><option>--editor-cmd=</option><replaceable>EDITOR</replaceable></arg>
<arg><option>--commit</option></arg>
<arg><option>--commit-msg</option><replaceable>MSG-FORMAT</replaceable></arg>
<arg><option>--tag</option></arg>
<arg><option>--retag</option></arg>
<arg><option>--packaging-tag-msg</option><replaceable>MSG-FORMAT</replaceable></arg>
<arg><option>--[no-]sign-tags</option></arg>
<arg><option>--keyid=</option><replaceable>GPG-KEYID</replaceable></arg>
<arg><option>--customizations=</option><replaceable>CUSTOMIZATION-FILE</replaceable></arg>
<arg choice="plain"><replaceable>[PATH1 PATH2]</replaceable></arg>
</cmdsynopsis>
Expand Down Expand Up @@ -151,6 +163,16 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--all</option>
</term>
<listitem>
<para>
Use all commits from the Git history, overrides
<option>--since</option>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--since=</option><replaceable>COMMITTISH</replaceable>
</term>
Expand All @@ -161,6 +183,19 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--meta-bts=</option><replaceable>META_TAGS</replaceable>
</term>
<listitem>
<para>
Meta tags in the commit messages that are interpreted as bug tracking
system related references. The recognized bts references are added in
the generated changelog entries. See the META TAGS section below for
more information. The bts meta tag tracking feature can be disabled
by defining an empty string.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-release</option>
</term>
Expand Down Expand Up @@ -263,6 +298,91 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--message=<replaceable>MESSAGE</replaceable></option>
</term>
<listitem>
<para>
Text to use for new changelog entries. Git history and the commit
messages, including <option>--since</option> and
<option>--all</option> options are ignored in this case.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--commit</option>
</term>
<listitem>
<para>
Commit changes to git after modifying changelog. Importantly, in
addition to the changelog modifications all other staged changes are
committed, too, making it possible to update other files in the same
commit.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--commit-msg=</option><replaceable>MSG-FORMAT</replaceable>
</term>
<listitem>
<para>
Format string for the commit message when committing changes
(when <option>--commit</option> is given).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--tag</option>
</term>
<listitem>
<para>
Commit the changes and create a packaging (release) tag. Similarly to
<option>--commit</option>, all staged changes are committed to git
before creating the tag. This option makes it possible to create a
release and correctly document the the tag name in the rpm changelog
(by using %(tagname)s in the <option>--changelog-revision</option>
string).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--retag</option>
</term>
<listitem>
<para>
Don't fail tag operations if a tag with the same version already
exists, but, overwrite the existing tag, instead.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--packaging-tag-msg=</option><replaceable>MSG-FORMAT</replaceable>
</term>
<listitem>
<para>
Format string for the tag message
(when <option>--tag</option> is given).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--[no-]sign-tags</option>
</term>
<listitem>
<para>
GPG sign all created tags.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--keyid=</option><replaceable>GPG-KEYID</replaceable>
</term>
<listitem>
<para>
Use this keyid for gpg signing tags.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--customizations=</option><replaceable>CUSTOMIZATION-FILE</replaceable>
</term>
Expand Down Expand Up @@ -310,6 +430,8 @@
<para>
Indicate in the changelog entry that bug
<replaceable>BUGNUMBER</replaceable> was addressed in this commit.
The bts meta tags recognized by &gbp-rpm-ch; is actually defined by
the <option>--meta-bts</option> option.
</para>
</listitem>
</varlistentry>
Expand Down
3 changes: 3 additions & 0 deletions gbp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ class GbpOptionParserRpm(GbpOptionParser):
'changelog-revision': '',
'spawn-editor': 'always',
'editor-cmd': 'vim',
'meta-bts': '(Close|Closes|Fixes|Fix)',
'spec-vcs-tag': '',
})

Expand Down Expand Up @@ -860,6 +861,8 @@ class GbpOptionParserRpm(GbpOptionParser):
'git-author':
"Use name and email from git-config for the changelog header, "
"default is '%(git-author)s'",
'meta-bts':
"Meta tags for the bts commands, default is '%(meta-bts)s'",
'spec-vcs-tag':
"Set/update the 'VCS:' tag in the spec file, empty value "
"removes the tag entirely, default is '%(spec-vcs-tag)s'",
Expand Down
53 changes: 34 additions & 19 deletions gbp/git/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _git_getoutput(self, command, args=[], extra_env=None, cwd=None):
return output, popen.returncode

def _git_inout(self, command, args, input=None, extra_env=None, cwd=None,
capture_stderr=False, config_args=None):
capture_stderr=False, capture_stdout=True, config_args=None):
"""
Run a git command with input and return output

Expand All @@ -192,10 +192,12 @@ def _git_inout(self, command, args, input=None, extra_env=None, cwd=None,
"""
if not cwd:
cwd = self.path
return self.__git_inout(command, args, input, extra_env, cwd, capture_stderr, config_args)
return self.__git_inout(command, args, input, extra_env, cwd, capture_stderr,
capture_stdout, config_args)

@classmethod
def __git_inout(cls, command, args, input, extra_env, cwd, capture_stderr, config_args=None):
def __git_inout(cls, command, args, input, extra_env, cwd, capture_stderr,
capture_stdout, config_args=None):
"""
As _git_inout but can be used without an instance
"""
Expand All @@ -206,21 +208,22 @@ def __git_inout(cls, command, args, input, extra_env, cwd, capture_stderr, confi

cmd = ['git'] + config_opts + [command] + args
env = cls.__build_env(extra_env)
stdout_arg = subprocess.PIPE if capture_stdout else None
stderr_arg = subprocess.PIPE if capture_stderr else None
stdin_arg = subprocess.PIPE if input is not None else None

log.debug(cmd)
popen = subprocess.Popen(cmd,
stdin=stdin_arg,
stdout=subprocess.PIPE,
stdout=stdout_arg,
stderr=stderr_arg,
env=env,
close_fds=True,
cwd=cwd)
(stdout, stderr) = popen.communicate(input)
return stdout, stderr, popen.returncode

def _git_command(self, command, args=[], extra_env=None):
def _git_command(self, command, args=[], extra_env=None, interactive=False):
"""
Execute git command with arguments args and environment env
at path.
Expand All @@ -232,12 +235,14 @@ def _git_command(self, command, args=[], extra_env=None):
@param extra_env: extra environment variables to set when running command
@type extra_env: C{dict}
"""
capture_stdout = not interactive
try:
stdout, stderr, ret = self._git_inout(command=command,
args=args,
input=None,
extra_env=extra_env,
capture_stderr=True)
capture_stderr=True,
capture_stdout=capture_stdout)
except Exception as excobj:
raise GitRepositoryError("Error running git %s: %s" % (command, excobj))
if ret:
Expand Down Expand Up @@ -1450,11 +1455,17 @@ def rename_file(self, old, new):

#{ Comitting

def _commit(self, msg, args=[], author_info=None):
def _commit(self, msg, args=[], author_info=None,
committer_info=None, edit=False):
extra_env = author_info.get_author_env() if author_info else None
self._git_command("commit", ['-q', '-m', msg] + args, extra_env=extra_env)
if committer_info:
extra_env.update(committer_info.get_committer_env())
default_args = ['-q', '-m', msg] + (['--edit'] if edit else [])
self._git_command("commit", default_args + args, extra_env=extra_env,
interactive=edit)

def commit_staged(self, msg, author_info=None, edit=False):
def commit_staged(self, msg, author_info=None, edit=False,
committer_info=None):
"""
Commit currently staged files to the repository

Expand All @@ -1464,10 +1475,11 @@ def commit_staged(self, msg, author_info=None, edit=False):
@type author_info: L{GitModifier}
@param edit: whether to spawn an editor to edit the commit info
@type edit: C{bool}
@param committer_info: committer information
@type committer_info: L{GitModifier}
"""
args = GitArgs()
args.add_true(edit, '--edit')
self._commit(msg=msg, args=args.args, author_info=author_info)
self._commit(msg=msg, author_info=author_info,
committer_info=committer_info, edit=edit)

def commit_all(self, msg, author_info=None, edit=False):
"""
Expand All @@ -1477,11 +1489,9 @@ def commit_all(self, msg, author_info=None, edit=False):
@param author_info: authorship information
@type author_info: L{GitModifier}
"""
args = GitArgs('-a')
args.add_true(edit, '--edit')
self._commit(msg=msg, args=args.args, author_info=author_info)
self._commit(msg=msg, args=['-a'], author_info=author_info, edit=edit)

def commit_files(self, files, msg, author_info=None):
def commit_files(self, files, msg, author_info=None, committer_info=None):
"""
Commit the given files to the repository

Expand All @@ -1491,10 +1501,13 @@ def commit_files(self, files, msg, author_info=None):
@type msg: C{str}
@param author_info: authorship information
@type author_info: L{GitModifier}
@param committer_info: committer information
@type committer_info: L{GitModifier}
"""
if isinstance(files, str):
files = [files]
self._commit(msg=msg, args=files, author_info=author_info)
self._commit(msg=msg, args=files, author_info=author_info,
committer_info=committer_info)

def commit_dir(self, unpack_dir, msg, branch, other_parents=None,
author={}, committer={}, create_missing_branch=False):
Expand Down Expand Up @@ -2007,7 +2020,8 @@ def create(cls, path, description=None, bare=False):
input=None,
extra_env=None,
cwd=abspath,
capture_stderr=True)
capture_stderr=True,
capture_stdout=True)
except Exception as excobj:
raise GitRepositoryError("Error running git init: %s" % excobj)
if ret:
Expand Down Expand Up @@ -2073,7 +2087,8 @@ def clone(cls, path, remote, depth=0, recursive=False, mirror=False,
input=None,
extra_env=None,
cwd=abspath,
capture_stderr=True)
capture_stderr=True,
capture_stdout=True)
except Exception as excobj:
raise GitRepositoryError("Error running git clone: %s" % excobj)
if ret:
Expand Down
17 changes: 9 additions & 8 deletions gbp/rpm/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class ChangelogEntryFormatter(object):

# Maximum length for a changelog entry line
max_entry_line_length = 76
# Bug tracking system related meta tags recognized from git commit msg
bts_meta_tags = ("Close", "Closes", "Fixes", "Fix")
# Regexp for matching bug tracking system ids (e.g. "bgo#123")
bug_id_re = r'[A-Za-z0-9#_\-]+'

Expand All @@ -107,15 +105,18 @@ def _parse_bts_tags(cls, lines, meta_tags):

@param lines: commit message
@type lines: C{list} of C{str}
@param meta_tags: meta tags to look for
@type meta_tags: C{tuple} of C{str}
@param meta_tags: meta tags (regexp) to look for
@type meta_tags: C{str}
@return: bts-ids per meta tag and the non-mathced lines
@rtype: (C{dict}, C{list} of C{str})
"""
if not meta_tags:
return ({}, lines[:])

tags = {}
other_lines = []
bts_re = re.compile(r'^(?P<tag>%s):\s*(?P<ids>.*)' %
('|'.join(meta_tags)), re.I)
bts_re = re.compile(r'^(?P<tag>%s):\s*(?P<ids>.*)' % meta_tags,
re.I)
bug_id_re = re.compile(cls.bug_id_re)
for line in lines:
match = bts_re.match(line)
Expand Down Expand Up @@ -172,7 +173,7 @@ def compose(cls, commit_info, **kwargs):
return None

# Parse and filter out bts-related meta-tags
bts_tags, body = cls._parse_bts_tags(body, cls.bts_meta_tags)
bts_tags, body = cls._parse_bts_tags(body, kwargs['meta_bts'])

# Additional filtering
body = cls._extra_filter(body, kwargs['ignore_re'])
Expand All @@ -191,7 +192,7 @@ def compose(cls, commit_info, **kwargs):
text.extend([" " + line for line in body if line.strip()])

# Add bts tags and ids in the end
for tag, ids in bts_tags.items():
for tag, ids in sorted(bts_tags.items()):
bts_msg = " (%s: %s)" % (tag, ', '.join(ids))
if len(text[-1]) + len(bts_msg) >= cls.max_entry_line_length:
text.append(" ")
Expand Down
Loading