Implemented --message command line option for changelog mode
authorEd Bartosh <eduard.bartosh@intel.com>
Mon, 25 Jun 2012 14:38:28 +0000 (17:38 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Mon, 25 Jun 2012 14:38:28 +0000 (17:38 +0300)
Change-Id: If5acf53362ef49806d71e74a11d52120213c609c

gitbuildsys/cmd_changelog.py
tools/gbs

index 9cb83169e0f704524de7986dc7b587b2866cb80a..4e69b971462d48dbc6df88306b2f0cd3a0b1ec03 100644 (file)
@@ -53,6 +53,18 @@ def get_latest_rev(changesfile):
             return line.strip().split(" ")[-1].split("@")[-1]
     return ''
 
+def get_version(git_repo, commit):
+    """
+    Construct version from commit using rev-parse.
+    Set version to <tag>@<sha1> or <sha1> if tag is not found.
+    """
+    version = git_repo.rev_parse(commit, ['--short'])
+    try:
+        version = "%s@%s" % (git_repo.find_tag('HEAD'), version)
+    except GitRepositoryError:
+        pass
+
+    return version
 
 def make_log_entries(commits, git_repo):
     """Make changelog entries from the set of git commits."""
@@ -63,13 +75,6 @@ def make_log_entries(commits, git_repo):
     for commit in commits:
         commit_info =  git_repo.get_commit_info(commit)
 
-        # set version to <tag>@<sha1> or <sha1> if tag is not found
-        version = git_repo.rev_parse(commit, ['--short'])
-        try:
-            version = "%s@%s" % (git_repo.find_tag('HEAD'), version)
-        except GitRepositoryError:
-            pass
-
         # Add new entry header if date is changed
         date = datetime.datetime.fromtimestamp(int(commit_info["timestamp"]))
         if not prevdate or (date.year, date.month, date.day) != \
@@ -78,7 +83,7 @@ def make_log_entries(commits, git_repo):
                                                 date.strftime("%a %b %d %Y"),
                                                 commit_info["author"],
                                                 commit_info["email"],
-                                                version))
+                                                get_version(git_repo, commit)))
             cret = "\n"
         # Track authors
         elif not prevauthor or prevauthor != commit_info["author"]:
@@ -140,7 +145,17 @@ def do(opts, _args):
     if not commits:
         msger.error("Nothing found between %s and HEAD" % commitid_since)
 
-    new_entries = make_log_entries(commits, repo)
+    if opts.message:
+        author = repo.get_author_info()
+        lines = os.linesep.join([" -%s" % line for line in \
+                                     opts.message.split(os.linesep) \
+                                         if line.strip()])
+        new_entries = ["* %s %s <%s> %s\n%s\n" % \
+                           (datetime.datetime.now().strftime("%a %b %d %Y"),
+                            author.name, author.email,
+                            get_version(repo, commits[0]), lines)]
+    else:
+        new_entries = make_log_entries(commits, repo)
 
     # create temporary copy and update it with new entries
     temp = utils.TempCopy(fn_changes)
index 9938be351bb3b50cdab02daa5e703b753dfa5d93..a198ba6405fcfac2660e943c4af8e21c392ebe76 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -299,15 +299,20 @@ class Gbs(cmdln.Cmdln):
                   default=None,
                   dest='since',
                   help='commit to start from')
+    @cmdln.option('-m', '--message',
+                  default=None,
+                  dest='message',
+                  help='use given message as the changelog entry')
     def do_changelog(self, _subcmd, opts, *args):
         """${cmd_name}: update the changelog file with the git commit messages
 
         Usage:
-            gbs changelog [--since]
+            gbs changelog [options]
 
         Examples:
           $ gbs changelog
           $ gbs changelog --since=COMMIT_ID
+          $ gbs changelog -m 'new upstream release 0.0.1'
         ${cmd_option_list}
         """