Mailinglist Archive: opensuse-buildservice (273 mails)

< Previous Next >
[opensuse-buildservice] [PATCH] commit message template
  • From: Michal Vyskocil <mvyskocil@xxxxxxx>
  • Date: Wed, 28 Jan 2009 13:11:02 +0100
  • Message-id: <200901281311.02531.mvyskocil@xxxxxxx>
Hi,

the attached patch changes the behavior of 'osc commit' command. I'm not very
happy when I have three places where the changes should be documented:
- .changes
- %changelog in .spec
- osc commit messages

The modified commit command read a differences from 1.) .changes, or 2.)
%changelog part of .spec and fill it to the commit message, so you don't need
type it again.

Only one problem is - you need change the commit message anyway, because osc
check the difference between commit message template and a result, but this
should be easily fixed (use a checksum without commit message template).

What do you think about this approach?

Regards
Michal Vyskocil
From c4f4c91be1434a0038748030296e0dbec2a3a4a2 Mon Sep 17 00:00:00 2001
From: Michal Vyskocil <mvyskocil@xxxxxxx>
Date: Wed, 28 Jan 2009 12:53:05 +0100
Subject: [PATCH] commit message template

The new osc.core.get_commit_message_template()
- check the diff in .changes, or in %changelog part of .spec
- extract them and add to the commit message
Modified:
osc.core.edit_message():
- new optional argument template
osc.commandline.do_commit():
- use get_commit_message_template to collect the changes and call the
edit_message with template argument
---
osc/commandline.py | 4 ++-
osc/core.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/osc/commandline.py b/osc/commandline.py
index 7c004e3..8f82223 100755
--- a/osc/commandline.py
+++ b/osc/commandline.py
@@ -1312,15 +1312,17 @@ Please submit there instead, or use --nodevelproject to
force direct submission.
# open editor for commit message
# but first, produce status and diff to append to the template
footer = diffs = []
+ msg_template = []
for pac in pacs:
changed = getStatus([pac], quiet=True)
if changed:
footer += changed
diffs += ['\nDiff for working copy: %s' % pac.dir]
diffs += make_diff(pac, 0)
+ msg_template.extend(get_commit_message_template(pac))
# if footer is empty, there is nothing to commit, and no edit
needed.
if footer:
- msg = edit_message(footer='\n'.join(footer))
+ msg = edit_message(footer='\n'.join(footer),
template='\n'.join(msg_template))

if conf.config['do_package_tracking'] and len(pacs) > 0:
prj_paths = {}
diff --git a/osc/core.py b/osc/core.py
index c684771..7aa96a9 100755
--- a/osc/core.py
+++ b/osc/core.py
@@ -23,6 +23,7 @@ import shutil
import oscerr
import conf
import subprocess
+import re
try:
from xml.etree import cElementTree as ET
except ImportError:
@@ -1885,8 +1886,62 @@ def read_meta_from_spec(specfile, *args):
return spec_data


-def edit_message(footer=''):
- delim = '--This line, and those below, will be ignored--\n\n' + footer
+def get_commit_message_template(pac):
+ """
+Read the diffs of .changes or in %changelog section in .spec files and put it
+as a template to commit message.
+ """
+ diff = None
+ template = []
+ template_src = None # or changes|spec
+ date_re = None
+ date_re_template = r'(Mon|Tue|Wed|Thu|Fri|Sat|Sun) ([A-Z][a-z]{2}) (
?[0-9]|[0-3][0-9]) .*'
+ if pac.todo:
+ # don't like this code
+ files = filter(lambda file: '.changes' in file and pac.status(file) ==
'M', pac.todo)
+ if files:
+ template_src = 'changes'
+ date_re = re.compile(r'\+' + date_re_template)
+ else:
+ files = filter(lambda file: '.spec' in file and pac.status(file)
== 'M', pac.todo)
+ if files:
+ template_src = 'spec'
+ date_re = re.compile(r'\+\* ' + date_re_template)
+ else:
+ return template
+
+ for file in [file for file in files if file in pac.filenamelist]:
+ diff = (get_source_file_diff(pac.absdir, file, pac.rev))
+
+ if diff:
+ index = 0
+ diff = diff.split('\n')
+ if template_src == 'changes':
+ # The first four lines contains a header of diff
+ index = 4
+ elif template_src == 'spec':
+ if not ' %changelog' in diff:
+ return template
+ index = diff.index(' %changelog')
+
+ for line in diff[index:]:
+ if not(line) or (line and line[0] != '+') or \
+ date_re.match(line) or \
+ line == '+' or line[0:3] == '+++':
+ continue
+
+ if line ==
'+-------------------------------------------------------------------':
+ template.append('')
+ else:
+ template.append(line[1:])
+
+ return template
+
+
+def edit_message(footer='', template=''):
+ if template != '':
+ template = template + '\n'
+ delim = template + '--This line, and those below, will be ignored--\n\n' +
footer
import tempfile
(fd, filename) = tempfile.mkstemp(prefix = 'osc-commitmsg', suffix =
'.diff', dir = '/tmp')
f = os.fdopen(fd, 'w')
--
1.6.0.2

< Previous Next >
This Thread
  • No further messages