monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-devel] [PATCH] mtn automate get_current_revision


From: Thomas Keller
Subject: [Monotone-devel] [PATCH] mtn automate get_current_revision
Date: Tue, 27 Mar 2007 14:16:09 +0200
User-agent: Thunderbird 1.5.0.10 (X11/20060911)

Hi all!

Attached is a patch that introduces a new automate command, named
"get_current_revision". I first named it "get_workspace_revision", but
then decided that the new name better fits into the naming concept of
other commands (f.e. get_current_revision_id).

What the patch basically does is that it removes the possibility from
auto get_revision to be called without a revision_id argument (hence the
interface version push to 5.0) and moves that into the new command while
allowing to restrict the outputted workspace revision by path arguments
and via --exclude.

The docs are already patched, (adapted) tests are missing, but will
follow of course if this is decided to be useful - then I'll put it into
a separate branch. I don't like to do that right now to avoid having
another branch name clobbering the global namespace which basic idea
then eventually get dropped, gets no feedback or is discontinued (like
some of my recent branches are).

My (very personal) use case for this command is to be able to create a
restricted revision from the current workspace which should be able to
be fed into auto put_revision without creating ugly invariant errors
because of missing nodes and the else. The alternative for me was to
mirror the internal mtn logic to create a valid restricted revision for
such a use case, from which I thought would not such a great idea.

So, opinions?

Thomas.

-- 
ICQ: 85945241 | SIP: 1-747-027-0392 | http://www.thomaskeller.biz
> Guitone, a frontend for monotone: http://guitone.thomaskeller.biz
> Music lyrics and more: http://musicmademe.com
# 
# old_revision [85b864138e3d232b606cd7515fb9602d468e78a1]
# 
# patch "automate.cc"
#  from [1c29dbf96103bd040cda530c7bba9a2d3fb2fbfa]
#    to [b695f0bbc2c3ea42eae2d39a4a55bab71b1dce58]
# 
# patch "cmd_automate.cc"
#  from [5ed92bb941b4c560f73a7c5b86899235e40b3f5c]
#    to [021d4b0fb4a4f02eda3e47d5a5532f597d3b8b07]
# 
# patch "monotone.texi"
#  from [c092a9b69224b93d76b9f43aa5f98cddcdeedfa9]
#    to [0c02b1e82164290eb47edb3ec63e378cf3fb2ecc]
# 
============================================================
--- automate.cc 1c29dbf96103bd040cda530c7bba9a2d3fb2fbfa
+++ automate.cc b695f0bbc2c3ea42eae2d39a4a55bab71b1dce58
@@ -849,8 +849,7 @@ AUTOMATE(inventory, "", options::opts::n
 
 // Name: get_revision
 // Arguments:
-//   1: a revision id (optional, determined from the workspace if
-//      non-existant)
+//   1: a revision id
 // Added in: 1.0
 
 // Purpose: Prints change information for the specified revision id.
@@ -910,42 +909,71 @@ AUTOMATE(inventory, "", options::opts::n
 //   the same type will be sorted by the filename they refer to.
 // Error conditions: If the revision specified is unknown or invalid
 // prints an error message to stderr and exits with status 1.
-AUTOMATE(get_revision, N_("[REVID]"), options::opts::none)
+AUTOMATE(get_revision, N_("REVID"), options::opts::none)
 {
-  N(args.size() < 2,
+  N(args.size() == 1,
     F("wrong argument count"));
 
   temp_node_id_source nis;
   revision_data dat;
   revision_id ident;
 
-  if (args.size() == 0)
-    {
-      roster_t new_roster;
-      parent_map old_rosters;
-      revision_t rev;
+  ident = revision_id(idx(args, 0)());
+  N(app.db.revision_exists(ident),
+    F("no revision %s found in database") % ident);
+  app.db.get_revision(ident, dat);
 
-      app.require_workspace();
-      app.work.get_parent_rosters(old_rosters);
-      app.work.get_current_roster_shape(new_roster, nis);
-      app.work.update_current_roster_from_filesystem(new_roster);
+  L(FL("dumping revision %s") % ident);
+  output.write(dat.inner()().data(), dat.inner()().size());
+}
 
-      make_revision(old_rosters, new_roster, rev);
-      calculate_ident(rev, ident);
-      write_revision(rev, dat);
-    }
-  else
-    {
-      ident = revision_id(idx(args, 0)());
-      N(app.db.revision_exists(ident),
-        F("no revision %s found in database") % ident);
-      app.db.get_revision(ident, dat);
-    }
+// Name: get_current_revision
+// Arguments:
+//   1: zero or more path names
+// Added in: 5.0
 
-  L(FL("dumping revision %s") % ident);
+// Purpose: Prints change information of the current workspace revision,
+//          restricted by the given Path(s).
+//
+// Error conditions: If there are no changes in the current workspace or the
+// restriction is invalid or has no recorded changes, prints an error message 
+// to stderr and exits with status 1. A workspace is required.
+AUTOMATE(get_current_revision, N_("[PATHNAME...]"),
+    options::opts::exclude | options::opts::depth)
+{
+  app.require_workspace();
+
+  revision_t restricted_rev;
+  parent_map old_rosters;
+  roster_t new_roster;
+  temp_node_id_source nis;
+  cset excluded;
+
+  app.work.get_parent_rosters(old_rosters);
+  app.work.get_current_roster_shape(new_roster, nis);
+
+  node_restriction mask(args_to_paths(args),
+                        args_to_paths(app.opts.exclude_patterns),
+                        app.opts.depth,
+                        old_rosters, new_roster, app);
+
+  app.work.update_current_roster_from_filesystem(new_roster, mask);
+  make_restricted_revision(old_rosters, new_roster, mask, restricted_rev,
+                           excluded, name);
+  restricted_rev.check_sane();
+  N(restricted_rev.is_nontrivial(), F("no changes to commit"));
+
+  revision_id restricted_rev_id;
+  revision_data dat;
+
+  calculate_ident(restricted_rev, restricted_rev_id);
+  write_revision(restricted_rev, dat);
+
+  L(FL("dumping revision %s") % restricted_rev_id);
   output.write(dat.inner()().data(), dat.inner()().size());
 }
 
+
 // Name: get_base_revision_id
 // Arguments: none
 // Added in: 2.0
============================================================
--- cmd_automate.cc     5ed92bb941b4c560f73a7c5b86899235e40b3f5c
+++ cmd_automate.cc     021d4b0fb4a4f02eda3e47d5a5532f597d3b8b07
@@ -60,7 +60,7 @@ automate_command(utf8 cmd, vector<utf8> 
   find_automation(cmd, root_cmd_name).run(args, root_cmd_name, app, output);
 }
 
-static string const interface_version = "4.1";
+static string const interface_version = "5.0";
 
 // Name: interface_version
 // Arguments: none
============================================================
--- monotone.texi       c092a9b69224b93d76b9f43aa5f98cddcdeedfa9
+++ monotone.texi       0c02b1e82164290eb47edb3ec63e378cf3fb2ecc
@@ -6587,15 +6587,16 @@ @section Automation
 
 @end table
 
address@hidden mtn automate get_revision
 @item mtn automate get_revision @var{id}
 
 @table @strong
 @item Arguments:
 
 Specifying the option @var{id} argument outputs the changeset 
-information for the specified @var{id}. Otherwise, @var{id} is 
-determined from the workspace.
+information for the specified @var{id}. Before interface version 5.0 the
address@hidden argument was optional and defaulted to the workspace revision.
+This functionality is now served by 
address@hidden automate get_current_revision}.
 
 @item Added in:
 
@@ -6692,7 +6693,55 @@ @section Automation
 @end table
 
 
address@hidden mtn automate get_current_revision address@hidden ...] 
address@hidden ...]
 
address@hidden @strong
address@hidden Arguments:
+
+Zero or more workspace paths.
+
address@hidden Added in:
+
+5.0
+
address@hidden Purpose:
+
+Prints change information of the current workspace, optionally restricted by
+one or more workspace paths. This command is useful in conjunction with
address@hidden automate put_revision} to programmatically create a restricted 
+revision from an existing workspace for a later commit.
+
address@hidden Sample output:
+
address@hidden
+format_version "1"
+
+new_manifest [bfe2df785c07bebeb369e537116ab9bb7a4b5e19]
+
+old_revision [429fea55e9e819a046843f618d90674486695745]
+
+patch "ChangeLog"
+ from [7dc21d3a46c6ecd94685ab21e67b131b32002f12]
+   to [234513e3838d423b24d5d6c98f70ce995c8bab6e]
+
+patch "std_hooks.lua"
+ from [0408707bb6b97eae7f8da61af7b35364dbd5a189]
+   to [d7bd0756c48ace573926197709e53eb24dae5f5f]
address@hidden verbatim
+
address@hidden Output format:
+
+The output is a revision formatted with basic_io stanzas. For a full 
description
+of the format, please check the @command{mtn automate get_revision} command.
+
address@hidden Error conditions:
+
+If the command is executed outside of a workspace, there are no changes in the 
+current workspace or the restriction is invalid or has no recorded changes,
+prints an error message to stderr and exits with status 1.
+
address@hidden table
+
 @item mtn automate get_base_revision_id
 
 @table @strong

reply via email to

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