# # # add_file "contrib/ChangeLog.sh" # content [43ef52b9ec1e9b09e26ef0de1f5a4d7b156347ef] # # add_file "contrib/edit_comment_from_changelog.lua" # content [392821013c884731eaef31836acab2c2c5938373] # # patch "ChangeLog" # from [10694bb8d1df3a7be69f543f93472b17e62c6ab1] # to [4d2542409777c5441e85903bc133e23a3ed25c41] # # set "contrib/ChangeLog.sh" # attr "mtn:execute" # value "true" # ============================================================ --- contrib/ChangeLog.sh 43ef52b9ec1e9b09e26ef0de1f5a4d7b156347ef +++ contrib/ChangeLog.sh 43ef52b9ec1e9b09e26ef0de1f5a4d7b156347ef @@ -0,0 +1,72 @@ +#!/bin/sh +# Usage: ChangeLog [] [-d database] [-r revision] +# Construct and print a ChangeLog for the last revisions from their +# date, author, and changelog certs. + +# If is not given, it defaults to 15 + +# If this script is not run from the root of a monotone workspace, both +# the -d and -r options are required. + +NUM=15 + +while ! [ $# -eq 0 ] ; do + case "$1" in + -r) shift; REV="$1";; + -d) shift; DB="-d $1";; + *) NUM=$(($1 - 1));; + esac + shift +done + +if ! [ -s MT/revision ]; then + if [ "x$REV" = "x" ] || [ "x$DB" = "x" ]; then + echo "Both the -d and -r arguments are needed when this" >&2; + echo "script is not run from the root of a monotone workspace." >&2; + exit 1; + fi +else + if [ "x$REV" = "x" ]; then + REV=`cat MT/revision` + fi +fi + +# Get the contents of a cert +LOG='/^Name.*changelog$/,/^----/! D; /^Name/ D; /^----/ D' +DATE='/^Name.*date$/,/^----/! D; /^Name/ D; /^----/ D' +AUTHOR='/^Name.*author$/,/^----/! D; /^Name/ D; /^----/ D' + +# Remove "duplicate" lines (When the date+author line is unneeded because +# the same info is in the changelog cert (won't match exactly, but should +# both start with ^${year} )) +# Keep the line from the changelog, instead of the generated one +RD=':b; N; /^[[:digit:]]\{4\}.*\n[[:digit:]]\{4\}/ { s/^.*\n//; b b; }; P; D' + +get() +{ + monotone $DB ls certs "$2" | sed "$1" \ + | sed 's/^[^\:]\+\: //g' +} + +getrevs() +{ + monotone $DB automate ancestors "$1" \ + | monotone $DB automate toposort address@hidden \ + | tail -n "$2" | tac +} + +getlogs() +{ + for i in "$REV" `getrevs "$REV" "$NUM"`; do + echo `get "$DATE" "$i"` '' `get "$AUTHOR" "$i"` + get "$LOG" "$i" | sed 's/^\([^[:digit:]\t]\)/\t\1/g' + done +} + + +if [ ! x$REV = x ]; then + getlogs | sed "$RD" | sed '/^$/ d' \ + | sed 's/^\([[:digit:]]\{4\}.*\)$/\n\1\n/g' +else + echo "MT/revision does not exist!" >&2 +fi ============================================================ --- contrib/edit_comment_from_changelog.lua 392821013c884731eaef31836acab2c2c5938373 +++ contrib/edit_comment_from_changelog.lua 392821013c884731eaef31836acab2c2c5938373 @@ -0,0 +1,27 @@ +std_edit_comment = edit_comment +function edit_comment(basetext, user_log_message) + local tmp, tname = temp_file() + if (tmp == nil) then return nil end + if (user_log_message == "") then + local ChangeLog = io.open("ChangeLog", "r") + if ChangeLog == nil then + return std_edit_comment(basetext, user_log_message) + end + local line = ChangeLog:read() + local msg = "" + local n = 0 + while(line ~= nil and n < 2) do + if (string.find(line, "^[^%s]")) then + n = n + 1 + end + if (n < 2 and not string.find(line, "^%s*$")) + then + msg = msg .. line .. "\n" + end + line = ChangeLog:read() + end + user_log_message = msg + io.close(ChangeLog) + end + return std_edit_comment(basetext, user_log_message) +end ============================================================ --- ChangeLog 10694bb8d1df3a7be69f543f93472b17e62c6ab1 +++ ChangeLog 4d2542409777c5441e85903bc133e23a3ed25c41 @@ -1,3 +1,12 @@ +2006-01-23 Timothy Brownawell + + New ChangeLog utilities in contrib/ . + * contrib/ChangeLog.sh: Script that takes the date, author, and + changelog certs from the last n revisions and prints them in standard + ChangeLog format. + * contrib/edit_comment_from_changelog.lua: an edit_comment hook that + takes the initial commit message from the most recent ChangeLog entry + 2006-01-23 Henry Nestler * monotone.texi, monotone.1: Mode none for --ticker.