[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Monotone-devel] [PATCH] --msgfile commit option
From: |
rghetta |
Subject: |
Re: [Monotone-devel] [PATCH] --msgfile commit option |
Date: |
Wed, 11 May 2005 11:39:01 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.6) Gecko/20050322 |
Nathaniel Smith wrote:
On Mon, May 09, 2005 at 08:14:12AM +0200, rghetta wrote:
This patch adds a --msgfile=<message file> commit option. The named file
content is used as the commit message.
Two requests:
-- make it --message-file, I guess? Unless anyone else has a better
idea. It's a little verbose, but we don't have --msg either...
done
-- you're not quite using the right APIs to get the data.
"local_path" is only for files inside the working copy, and your
code won't work right if someone passes a relative path while in
a subdirectory of the working copy (because monotone will chdir()
before trying to open the file).
See OPT_RCFILE's implementation for how to handle this correctly.
The main thing is to munge the filename immediately, before
saving it, and then to use read_data_for_command_line later to
actually read it.
This should also mean --message-file=- will work automatically.
done that also (I hope). Thanks for the info :)
I've also added a check for files outside the working copy, by creating
and deleting a file in ../ (testsuite.dir). It's ok ?
Greetings,
Riccardo
#
# add_file "tests/t_commit_message_file.at"
#
# patch "app_state.cc"
# from [99273877068314cdc8d24e06032a022e72e01352]
# to [392734be5cdd5ba62dd214b28aa434e67b678171]
#
# patch "app_state.hh"
# from [a5ac3a99f998fee5a71b4f6201e6d26b086c7589]
# to [d0009cab364bc2ee2fa53170aa4bc61ce16a6f11]
#
# patch "commands.cc"
# from [82065a698ea04492cefc84b2935774b9fc3b92a8]
# to [00ef62e671f25b832bb1280d1c66c0bbc7c39545]
#
# patch "monotone.1"
# from [2b4b5dcbaba333709862fe47c0f02647e138a315]
# to [bc50c79f62de57cefae2292c6c96e53750f7f725]
#
# patch "monotone.cc"
# from [42020d9e45090f7a39457f9e376a968fcb003fb4]
# to [0d67d084ddfc9f143006b339c925a5fe86dce4c5]
#
# patch "monotone.texi"
# from [1043aaa99cad1d0060f75058661a71ad85c12ac5]
# to [8194357bcbb970bf5fd7aca9e00d5fca450984c0]
#
# patch "options.hh"
# from [de2a21d88f641eeb889184d57af3c433b91556ec]
# to [4c2651f57f221b2224b9a9dca93a4b1e9c99b281]
#
# patch "tests/t_commit_message_file.at"
# from []
# to [ed5a512378cb4497393b00c08b0992cf56bc607d]
#
# patch "testsuite.at"
# from [2c6c52294b3e4f89a0b7d917d732a83ab6ee99ac]
# to [ea7b03d154d01f1702ff5ef8e139744cf8657e32]
#
--- app_state.cc
+++ app_state.cc
@@ -274,6 +274,12 @@
}
void
+app_state::set_message_file(utf8 const & m)
+{
+ message_file = m;
+}
+
+void
app_state::set_date(utf8 const & d)
{
date = d;
--- app_state.hh
+++ app_state.hh
@@ -33,6 +33,7 @@
bool rcfiles;
options_map options;
utf8 message;
+ utf8 message_file;
utf8 date;
utf8 author;
utf8 search_root;
@@ -65,6 +66,7 @@
void set_signing_key(utf8 const & key);
void set_root(utf8 const & root);
void set_message(utf8 const & message);
+ void set_message_file(utf8 const & message_file);
void set_date(utf8 const & date);
void set_author(utf8 const & author);
void set_depth(long depth);
--- commands.cc
+++ commands.cc
@@ -2232,7 +2232,7 @@
CMD(commit, "working copy", "[PATH]...",
"commit working copy to database",
- OPT_BRANCH_NAME % OPT_MESSAGE % OPT_DATE % OPT_AUTHOR)
+ OPT_BRANCH_NAME % OPT_MESSAGE % OPT_MSGFILE % OPT_DATE % OPT_AUTHOR)
{
string log_message("");
revision_set rs;
@@ -2264,12 +2264,28 @@
L(F("new manifest %s\n") % rs.new_manifest);
L(F("new revision %s\n") % rid);
- // get log message
- N(!(app.message().length() > 0 && has_contents_user_log()),
+ // can't have both a --message and a --message-file ...
+ N(app.message().length() == 0 || app.message_file().length() == 0,
+ F("--message and --message-file are mutually exclusive"));
+
+ N(!( app.message().length() > 0 && has_contents_user_log()),
F("MT/log is non-empty and --message supplied\n"
"perhaps move or delete MT/log,\n"
"or remove --message from the command line?"));
+ N(!( app.message_file().length() > 0 && has_contents_user_log()),
+ F("MT/log is non-empty and --message-file supplied\n"
+ "perhaps move or delete MT/log,\n"
+ "or remove --message-file from the command line?"));
+
+ // fill app.message with message_file contents
+ if (app.message_file().length() > 0)
+ {
+ data dat;
+ read_data_for_command_line(app.message_file(), dat);
+ app.message = dat();
+ }
+
if (app.message().length() > 0)
log_message = app.message();
else
--- monotone.1
+++ monotone.1
@@ -144,10 +144,12 @@
\fBrename\fP \fI<src> \fI<dst>\fP
Rename files from \fI<src> \fP to \fI<dst> \fP in working copy.
.TP
-\fBcommit\fP \fI[--message=<log message>] [<pathname>...]\fP
+\fBcommit\fP \fI[(--message=<log message>|--message-file=<file>)]
[<pathname>...]\fP
Commit working copy to database. If a --message option is provided on
-the command line, it is used; otherwise a log message editor will be
-invoked.
+the command line, it is used; if a --message-file option is provided, the
+content of the named file will be used as a commit message.
+Otherwise a log message editor will be invoked.
+If the optional file MT/log exists, its content is used to prefill the editor.
.TP
\fBupdate\fP \fI[revision-id]\fP
Update working copy.
@@ -261,10 +263,18 @@
rather than invoking the log message editor. Currently this option only
applies to the commit command but it may also apply to the comment
command in the future.
+This option is alternative to --message-file
.TP
\fB-m \fI<log message>\fP
An alias for \fB--message=\fI<log message>\fP
.TP
+\fB--message-file=\fI<message file>\fP
+Use the content of the given file as the changelog when committing a
+new revision rather than invoking the log message editor. Currently
+this option only applies to the commit command but it may also apply
+to the comment command in the future.
+This option is alternative to --message.
+.TP
\fB--author=\fI<author email>\fP
Use the given author as the value of the "author" cert when committing
a new revision, rather than the default author. Useful when
--- monotone.cc
+++ monotone.cc
@@ -44,6 +44,7 @@
{"branch", 'b', POPT_ARG_STRING, &argstr, OPT_BRANCH_NAME, "select branch
cert for operation", NULL},
{"revision", 'r', POPT_ARG_STRING, &argstr, OPT_REVISION, "select revision
id for operation", NULL},
{"message", 'm', POPT_ARG_STRING, &argstr, OPT_MESSAGE, "set commit
changelog message", NULL},
+ {"message-file", 0, POPT_ARG_STRING, &argstr, OPT_MSGFILE, "set filename
containing commit changelog message", NULL},
{"date", 0, POPT_ARG_STRING, &argstr, OPT_DATE, "override date/time for
commit", NULL},
{"author", 0, POPT_ARG_STRING, &argstr, OPT_AUTHOR, "override author for
commit", NULL},
{"depth", 0, POPT_ARG_LONG, &arglong, OPT_DEPTH, "limit the log output to
the given number of entries", NULL},
@@ -333,6 +334,10 @@
app.set_message(string(argstr));
break;
+ case OPT_MSGFILE:
+
app.set_message_file(absolutify_for_command_line(tilde_expand(string(argstr))));
+ break;
+
case OPT_DATE:
app.set_date(string(argstr));
break;
--- monotone.texi
+++ monotone.texi
@@ -3408,12 +3408,14 @@
@item monotone commit
@itemx monotone commit address@hidden
address@hidden monotone commit address@hidden
@itemx monotone commit @var{pathname...}
@itemx monotone commit address@hidden @var{pathname...}
address@hidden monotone commit address@hidden @var{pathname...}
This command looks at your working copy, decides which files have
changed, and saves the changes to your database. It does this by
-loading the revision named in the @file{MT/revision} file, locating
+loading the evision named in the @file{MT/revision} file, locating
the base manifest for your working copy, applying any changes
described in the @file{MT/work} file, and then comparing the updated
base manifest to the files it finds in your working copy, to determine
@@ -3438,6 +3440,11 @@
copy. Specifying only the pathname "." will restrict @command{commit}
to files changed within the current subdirectory of the working copy.
+The @option{--message} and @option{--message-file} options are mutually
+exclusive. Both provide a @var{logmsg} describing the commit.
address@hidden actually specifies the name of the file containing
+the log message, while @option{--message} provides it directly.
+
The @file{MT/log} file can be edited by the user during their daily work
to record the changes made to the working copy. When running the
@command{commit} command without a @var{logmsg} supplied, the contents
@@ -6343,11 +6350,13 @@
Rename files from @i{<src>} to @i{<dst>} in working copy.
@comment TROFF INPUT: .TP
address@hidden @b{commit} @i{[--message=log message] [<pathname>...]}
address@hidden @b{commit} @i{[--message=log message | --message-file=log
message file] [<pathname>...]}
Commit working copy to database. If a --message @option{option} is
-provided on the command line, it is used; otherwise a log message
-editor will be invoked. If @i{MT/log} exists, its content will be
-passed to the message editor.
+provided on the command line, it is used; if a --message-file
address@hidden is provided, the content of the named file is used as
+a commit message.
+Otherwise a log message editor will be invoked. If @i{MT/log} exists,
+its content will be passed to the message editor.
@comment TROFF INPUT: .TP
@item @b{update} @i{[revision]}
@@ -6477,6 +6486,12 @@
two specific revisions. It will likely apply to other commands in the
future.
address@hidden @address@hidden<log message file>}
+Use the content of the given file as the changelog when committing a
+new revision rather than invoking the log message editor. Currently
+this option only applies to the commit command but it may also apply
+to the comment command in the future.
+
@item @address@hidden<log message>}
@itemx @b{-m} @i{<log message>}
Use the given message as the changelog when committing a new revision
--- options.hh
+++ options.hh
@@ -29,3 +29,4 @@
#define OPT_AUTHOR 20
#define OPT_ALL_FILES 21
#define OPT_PIDFILE 22
+#define OPT_MSGFILE 23
--- tests/t_commit_message_file.at
+++ tests/t_commit_message_file.at
@@ -0,0 +1,75 @@
+AT_SETUP([commit with --message-file])
+
+MONOTONE_SETUP
+
+AT_CHECK(rm -f MT/log)
+
+#--------------------
+#first, verify that --message-file actually works
+#--------------------
+
+AT_DATA(input.txt, [version 0 of the file
+])
+
+AT_CHECK(MONOTONE add input.txt, [], [ignore], [ignore])
+
+AT_DATA(msgfile.txt, [this commit uses the --message-file option
+])
+
+AT_CHECK(MONOTONE --branch=testbranch commit --message-file=msgfile.txt, [],
[ignore], [ignore])
+
+TSHA=`BASE_REVISION`
+AT_CHECK(MONOTONE ls certs $TSHA, [], [stdout], [ignore])
+AT_CHECK(grep -q 'this commit uses the --message-file option' stdout, [])
+
+#--------------------
+#also with a file coming outside the working copy
+#--------------------
+AT_DATA(input1.txt, [files... files...
+])
+
+AT_CHECK(MONOTONE add input1.txt, [], [ignore], [ignore])
+
+AT_DATA(../message-out-of-copy.txt, [out out out
+])
+
+AT_CHECK(MONOTONE --branch=testbranch commit
--message-file=../message-out-of-copy.txt, [], [ignore], [ignore])
+
+TSHA=`BASE_REVISION`
+AT_CHECK(MONOTONE ls certs $TSHA, [], [stdout], [ignore])
+AT_CHECK(grep -q 'out out out' stdout, [])
+
+AT_CHECK(rm -f ../message-out-of-copy.txt)
+
+#--------------------
+#start with the failures: non existing file
+#--------------------
+AT_DATA(input2.txt, [another file
+])
+
+AT_CHECK(MONOTONE add input2.txt, [], [ignore], [ignore])
+
+AT_CHECK(MONOTONE --branch=testbranch commit
--message-file=to-be-or-not-to-be.txt, [1], [ignore], [ignore])
+
+#--------------------
+#then verify that --message and --message-file together cause an error
+#--------------------
+
+AT_CHECK(MONOTONE --branch=testbranch commit --message-file=msgfile.txt
--message="also a message", [1], [ignore], [ignore])
+
+# --------------------
+# finally, --message-file and a filled MT/log should also fail
+# --------------------
+
+AT_DATA(commit_log.lua, [
+function edit_comment(summary, user_log_file)
+ return user_log_file
+end
+])
+
+AT_DATA(MT/log, [Log entry
+])
+
+AT_CHECK(MONOTONE --branch=testbranch --rcfile=commit_log.lua commit
--message-file=msgfile.txt, [1], [ignore], [ignore])
+
+AT_CLEANUP
--- testsuite.at
+++ testsuite.at
@@ -635,3 +635,4 @@
m4_include(tests/t_monotone_up.at)
m4_include(tests/t_drop_vs_patch_rename.at)
m4_include(tests/t_unreadable_MT.at)
+m4_include(tests/t_commit_message_file.at)