Anonymous avatar Anonymous committed 92b5af2

Initial commit.

Comments (0)

Files changed (2)

+# -*- coding: utf-8 -*-
+"""
+    hgchangelog
+    ~~~~~~~~~~~
+
+    Mercurial extension to read commit message from changelog.
+
+    :copyright: 2008 by Georg Brandl.
+    :license: BSD.
+"""
+
+from mercurial import commands, cmdutil, extensions, patch
+
+def new_commit(orig_commit, ui, repo, *pats, **opts):
+    if opts['message'] or opts['logfile']:
+        # don't act if user already specified a message
+        return orig_commit(ui, repo, *pats, **opts)
+
+    # check if changelog changed
+    logname = ui.config('changelog', 'filename', 'CHANGES')
+    match = cmdutil.match(repo, pats, opts)
+    if logname not in match:
+        # changelog did not change
+        return orig_commit(ui, repo, *pats, **opts)
+    logmatch = cmdutil.match(repo, [logname], {})
+    # get diff of changelog
+    log = []
+    for chunk in patch.diff(repo, None, None, match=logmatch):
+        for line in chunk.splitlines():
+            # naive: all added lines are the changelog
+            if line.startswith('+') and not line.startswith('+++'):
+                line = line[1:].strip()
+                if line: log.append(line)
+    log = '\n'.join(log)
+    # strip bullet points and whitespace on the left
+    log = log.lstrip('*- \t')
+    opts['force_editor'] = True
+    opts['message'] = log
+    return orig_commit(ui, repo, *pats, **opts)
+
+
+def uisetup(ui):
+    if not hasattr(extensions, 'wrapcommand'):
+        return
+    extensions.wrapcommand(commands.table, 'commit', new_commit)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.