monotone-commits-diffs
[Top][All Lists]
Advanced

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

[Monotone-commits-diffs] net.venge.monotone.branch-aliases: 8d0727b74579


From: code
Subject: [Monotone-commits-diffs] net.venge.monotone.branch-aliases: 8d0727b745792aaa707485097916f06892d620de
Date: Sun, 11 Mar 2012 13:35:43 +0100 (CET)

revision:            8d0727b745792aaa707485097916f06892d620de
date:                2012-03-11T12:35:54
author:              Richard Hopkins <address@hidden>
branch:              net.venge.monotone.branch-aliases
changelog:
Add get_real_branch_name hook to allow aliases in branch selectors

At the moment it's only used in branch selectors, but future commits will
allow it for any branch names from the user such as checkout and propagate.

Using the hook for netsync patterns would be useful but we'd probably have
to only call it for patterns without wildcards, or only allow wildcards
at the end; i.e. allowing aliases to be a prefix.

The default definition for this hook just returns branch_alias so
everything will be the same as before for people who don't want/need this hook.

manifest:
format_version "1"

new_manifest [482617d06f8cd9203e723188cf4e67c35a7778a6]

old_revision [2cb1b24a0643e108f8b2044449049053de601ac0]

patch "doc/monotone.texi"
 from [5d233f3ae943361cf83d586209e6ff04c083c9de]
   to [5d531516aea74ef5a86f8ff3347c563393ed9498]

patch "src/lua_hooks.cc"
 from [1c178085332c73dcefb4681d205d17b059e52080]
   to [c24a7fd5923d42ba4bc4e50b827f819644ceedd4]

patch "src/lua_hooks.hh"
 from [66412b9fa5db97cd3b3ec01cadf036fb346ac161]
   to [6f33f6f3d6a3c4f7d46592714b131cab77a33234]

patch "src/selectors.cc"
 from [3efba0ce3139290b4088cea0d6e82a912565471e]
   to [0c27b6f562e2fd328cc4b3d435dac038439b23fa]

patch "src/std_hooks.lua"
 from [ada658bd275399032411e0f520d9900bad966dc4]
   to [b45aad427a4f4fe82a9c3720f407476245d54fcf]
============================================================
--- src/lua_hooks.cc	1c178085332c73dcefb4681d205d17b059e52080
+++ src/lua_hooks.cc	c24a7fd5923d42ba4bc4e50b827f819644ceedd4
@@ -398,6 +398,21 @@ bool
 }
 
 bool
+lua_hooks::hook_get_real_branch_name(string const & branch_alias,
+                                     branch_name & real_branch_name)
+{
+  Lua ll(st);
+  string rbn;
+  ll.func("get_real_branch_name")
+    .push_str(branch_alias);
+  bool ok = ll.call(1,1)
+    .extract_str(rbn)
+    .ok();
+  real_branch_name = branch_name(rbn, origin::internal);
+  return ok;
+}
+
+bool
 lua_hooks::hook_edit_comment(external const & user_log_message,
                              external & result)
 {
============================================================
--- src/lua_hooks.hh	66412b9fa5db97cd3b3ec01cadf036fb346ac161
+++ src/lua_hooks.hh	6f33f6f3d6a3c4f7d46592714b131cab77a33234
@@ -65,6 +65,8 @@ public:
   bool hook_get_author(branch_name const & branchname,
                        key_identity_info const & info,
                        string & author);
+  bool hook_get_real_branch_name(string const & branch_alias,
+                                 branch_name & real_branch_name);
   bool hook_edit_comment(external const & user_log_message,
                          external & result);
   bool hook_persist_phrase_ok();
============================================================
--- doc/monotone.texi	5d233f3ae943361cf83d586209e6ff04c083c9de
+++ doc/monotone.texi	5d531516aea74ef5a86f8ff3347c563393ed9498
@@ -11592,6 +11592,29 @@ @subsection User Defaults
 @end group
 @end smallexample
 
address@hidden@item get_real_branch_name (@var{branch_alias})
+
+Called whenever monotone receives a branch name from the user, as the real branch
+name within the database is needed to perform actions. This allows the user to
+provide their own aliases to minimize key presses for common branch names.
+
+Example: "net.venge.monotone" is the real branch name for the monotone main development
+branch, and this hook allows a user to map the alias "nvm" to "net.venge.monotone".
+
address@hidden
address@hidden
+function get_real_branch_name(branch_alias)
+        if (branch_alias == "nvm") then
+                return "net.venge.monotone"
+        else
+                return branch_alias
+        end
+end
address@hidden group
address@hidden smallexample
+
+The default implementation of this hook returns @var{branch_alias}.
+
 @address@hidden get_default_database_locations ()
 Called whenever monotone converts a database name to an absolute path.
 
============================================================
--- src/std_hooks.lua	ada658bd275399032411e0f520d9900bad966dc4
+++ src/std_hooks.lua	b45aad427a4f4fe82a9c3720f407476245d54fcf
@@ -1540,3 +1540,7 @@ end
    end
 end
 
+function get_real_branch_name(branch_alias)
+	return branch_alias
+end
+
============================================================
--- src/selectors.cc	3efba0ce3139290b4088cea0d6e82a912565471e
+++ src/selectors.cc	0c27b6f562e2fd328cc4b3d435dac038439b23fa
@@ -108,13 +108,17 @@ public:
 {
   string value;
 public:
-  branch_selector(string const & arg, options const & opts) : value(arg)
+  branch_selector(string const & arg, options const & opts, lua_hooks & lua) : value(arg)
   {
     if (value.empty())
       {
         workspace::require_workspace(F("the empty branch selector b: refers to the current branch"));
         value = opts.branch();
       }
+
+    branch_name real_branch_name;
+    lua.hook_get_real_branch_name(value, real_branch_name);
+    dump(real_branch_name, value);
   }
   virtual set<revision_id> complete(project_t & project)
   {
@@ -662,7 +666,7 @@ selector::create_simple_selector(options
     case 'a':
       return shared_ptr<selector>(new author_selector(sel));
     case 'b':
-      return shared_ptr<selector>(new branch_selector(sel, opts));
+      return shared_ptr<selector>(new branch_selector(sel, opts, lua));
     case 'c':
       return shared_ptr<selector>(new cert_selector(sel));
     case 'd':

reply via email to

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