monotone-devel
[Top][All Lists]
Advanced

[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: Thu, 12 May 2005 08:55:57 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.6) Gecko/20050322

Here's the --message-file with the out-of-working-copy test revised to use a subdir instead of writing into testsuite.dir
The othe

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 [f3febee041e99d486cc766bec350719df952b82a]
# 
# patch "monotone.cc"
#  from [42020d9e45090f7a39457f9e376a968fcb003fb4]
#    to [0d67d084ddfc9f143006b339c925a5fe86dce4c5]
# 
# patch "monotone.texi"
#  from [1043aaa99cad1d0060f75058661a71ad85c12ac5]
#    to [1151c9997c4c3d246fe0f376e79bde006d219490]
# 
# patch "options.hh"
#  from [de2a21d88f641eeb889184d57af3c433b91556ec]
#    to [4c2651f57f221b2224b9a9dca93a4b1e9c99b281]
# 
# patch "tests/t_commit_message_file.at"
#  from []
#    to [a44df1257c0a0400d00f6876f1c82eb64b0466ac]
# 
# patch "testsuite.at"
#  from [6b0d1c1e97cbb6def87352d063db38857a432f48]
#    to [dafe5bc569348041cd07ab007d99a0607c2de8e7]
# 
--- 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. If the filename is 
'-' the commit message will be read from standard input.
+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. If the passed 
filename is '-' the changelog message will be read from standard input.
+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,14 @@
 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. If you pass '-' as the filename, the commit message
+will be read from standard input.
+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 +6487,13 @@
 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. 
+If the filename is '-' the changelog is read from standard input.
+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_CHECK(MONOTONE setup alt_wrk, [], [ignore], [ignore])
+
+AT_DATA(alt_wrk/input1.txt, [files... files...
+])
+
+AT_DATA(message-out-of-copy.txt, [out out out 
+])
+
+AT_CHECK(cd alt_wrk && MONOTONE add input1.txt, [], [ignore], [ignore])
+
+AT_CHECK(cd alt_wrk && MONOTONE --branch=outbranch commit 
--message-file=../message-out-of-copy.txt, [], [ignore], [ignore])
+
+TSHA=`cd alt_wrk && BASE_REVISION`
+AT_CHECK(cd alt_wrk && MONOTONE ls certs $TSHA, [], [stdout], [ignore])
+AT_CHECK(grep -q 'out out out' stdout, [])
+
+#--------------------
+#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
@@ -636,3 +636,4 @@
 m4_include(tests/t_drop_vs_patch_rename.at)
 m4_include(tests/t_unreadable_MT.at)
 m4_include(tests/t_cvsimport3.at)
+m4_include(tests/t_commit_message_file.at)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]