Guido Günther <a...@sigxcpu.org> writes:

> Hi,
> thanks for your patch. Creating the missing changelog might make sense
> but it shouldn't mangle all the code but be confined to one place
> (create the changelog and reread it).

Thanks for the review, I create and mangle the changelog in one method,
the use can:

- Set a new version with the "-N <VERSION>" on the command line

- let git-dch discover an upstream version and use it

Note that the creation make a changelog without any change data, a
warning is displayed:

#+begin_src
LANG=C git-dch --debian-branch=dist/debian/sid/t --verbose -a 
--spawn-editor=none debian/ ; cat debian/changelog
gbp:debug: ['git', 'rev-parse', '--show-cdup']
gbp:debug: ['git', 'rev-parse', '--is-bare-repository']
gbp:debug: ['git', 'symbolic-ref', 'HEAD']
gbp:debug: ['git', 'show-ref', 'refs/heads/dist/debian/sid/t']
gbp:info: No debian/changelog: create a new one
gbp:debug:  EDITOR=/bin/true dch --no-auto-nmu     --create --empty 
--newversion=0~~~~~ -- "" [] []
gbp:debug: ['git', 'describe', '--abbrev=0', '--match', 'm*', 'HEAD']
gbp:debug: Found upstream version 0.4.
gbp:debug: /usr/bin/dpkg ['--compare-versions'] ['0.4', 'lt', '0~~~~~']
gbp:debug: /usr/bin/dpkg ['--compare-versions'] ['0.4', 'gt', '0~~~~~']
gbp:debug: ['git', 'tag', '-l', 'debian/sid/0.4-1']
gbp:debug: ['git', 'tag', '-l', 'debian/sid/0.4-1']
gbp:debug: ['git', 'log', '--pretty=format:%H', '-1', '--', 'debian/changelog']
gbp:info: Couldn't find snapshot header, using version info
gbp:info: Only looking for changes on 'debian/'
gbp:debug: ['git', 'log', '--pretty=format:%H', '--no-merges', '--', 'debian/']
gbp:debug: ['git', 'log', '--pretty=format:%an%n%ae%n%s%n%b%n', '-n1', 
'e4b8adeda80e9b6306c76df78ee336152942c336']
gbp:debug: DEBFULLNAME="Daniel Dehennin" 
DEBEMAIL="daniel.dehen...@baby-gnu.org"  dch --no-auto-nmu    
--nomultimaint-merge --multimaint -- "[[[insert-git-dch-commit-message-here]]]" 
[] []
parsechangelog/debian: warning:     debian/changelog(l4): found trailer where 
expected start of change data
LINE:  -- Daniel Dehennin <d...@hati.baby-gnu.org>  Thu, 19 Apr 2012 23:11:22 
+0200
gbp:debug: ['git', 'log', '--pretty=format:%an%n%ae%n%s%n%b%n', '-n1', 
'69fb0b42dd64ab65136afd026b7354c0a41e99ac']
gbp:debug: DEBFULLNAME="Daniel Dehennin" 
DEBEMAIL="daniel.dehen...@baby-gnu.org"  dch --no-auto-nmu    
--nomultimaint-merge --multimaint -- "[[[insert-git-dch-commit-message-here]]]" 
[] []
gbp:debug: ['git', 'config', 'user.name']
gbp:debug: ['git', 'config', 'user.email']
gbp:debug: DEBFULLNAME="Daniel Dehennin" 
DEBEMAIL="daniel.dehen...@baby-gnu.org"  dch --no-auto-nmu    
--nomultimaint-merge --multimaint -- "" [] []
PACKAGE (0.4-1) UNRELEASED; urgency=low

  * [e4b8ade] New debian
  * [69fb0b4] New Readme

 -- Daniel Dehennin <daniel.dehen...@baby-gnu.org>  Thu, 19 Apr 2012 23:11:23 
+0200
#+end_src


Regards.

Here is the updated patch[1]:

diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py
index 3a4a02a..44a4892 100644
--- a/gbp/scripts/dch.py
+++ b/gbp/scripts/dch.py
@@ -75,6 +75,11 @@ def spawn_dch(msg=[], author=None, email=None, newversion=False, version=None,
     if author and email:
         env = """DEBFULLNAME="%s" DEBEMAIL="%s" """ % (author, email)
 
+    if dch_options.find(" --create") != -1:
+        env += """ EDITOR=/bin/true"""
+        # Should be lower than anything?
+        dch_options += """ --newversion=0~~~~~"""
+
     if distribution:
         distopt = "--distribution=%s" % distribution
 
@@ -97,6 +102,17 @@ def spawn_dch(msg=[], author=None, email=None, newversion=False, version=None,
         os.rename("debian/changelog.bak", "debian/changelog")
 
 
+def create_empty_changelog(changelog, repo, options):
+    """Create an empty changelog file"""
+    spawn_dch(dch_options=" --create --empty")
+    cp = ChangeLog(filename=changelog)
+    if not options.new_version:
+        cp['MangledVersion'] = guess_version_from_upstream(repo, options.upstream_tag, cp)
+    else:
+        cp['MangledVersion'] = options.new_version
+    mangle_changelog(changelog, cp)
+    return ChangeLog(filename=changelog)
+
 def add_changelog_entry(msg, author, email, dch_options):
     """Add a single changelog entry"""
     spawn_dch(msg=msg, author=author, email=email, dch_options=dch_options)
@@ -416,7 +432,13 @@ def main(argv):
             gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch))
             raise GbpError, "Use --ignore-branch to ignore or --debian-branch to set the branch name."
 
-        cp = ChangeLog(filename=changelog)
+        created_cp = False
+        try:
+            cp = ChangeLog(filename=changelog)
+        except NoChangeLogError, err:
+            gbp.log.info("No debian/changelog: create a new one")
+            cp = create_empty_changelog(changelog, repo, options)
+            created_cp = True
 
         if options.since:
             since = options.since
@@ -429,7 +451,7 @@ def main(argv):
                     found_snapshot_header = True
                 else:
                     gbp.log.info("Couldn't find snapshot header, using version info")
-            if not since:
+            if not created_cp and not since:
                 since = repo.find_version(options.debian_tag, cp['Version'])
                 if not since:
                     raise GbpError, "Version %s not found" % cp['Version']
@@ -441,7 +463,7 @@ def main(argv):
         commits.reverse()
 
         # add a new changelog section if:
-        if options.new_version or options.bpo or options.nmu or options.qa:
+        if not created_cp and (options.new_version or options.bpo or options.nmu or options.qa):
             if options.bpo:
                 version_change['increment'] = '--bpo'
             elif  options.nmu:

Footnotes: 
[1]  I need to look at how to add a test in the test suit

-- 
Daniel Dehennin
Récupérer ma clef GPG:
gpg --keyserver pgp.mit.edu --recv-keys 0x7A6FE2DF

Attachment: pgpnpWp2S7L9Z.pgp
Description: PGP signature

Reply via email to