# # # patch "commands.cc" # from [159c1be21ced0e2800d2461802f7dd4d30c9830b] # to [238d3fa8b6b3d60b3721d3f284596897f084938d] # # patch "lua_hooks.cc" # from [ff4053ed166f572c179628ec23c9ef263484e234] # to [7d279ed674702ac510dc392adf0d0ceaf5189ebb] # # patch "lua_hooks.hh" # from [0f79afa4f23d64a221b23ef4b39766528fec8a14] # to [6e35d15a966de50cfd78bd181c39cb7b90e0f851] # ============================================================ --- commands.cc 159c1be21ced0e2800d2461802f7dd4d30c9830b +++ commands.cc 238d3fa8b6b3d60b3721d3f284596897f084938d @@ -734,6 +734,34 @@ namespace commands if (cmd->use_workspace_options()) app.process_options(); + // don't attempt to expand branches if the hook doesn't exist + // to avoid the delay of getting the list of all branches + if (app.opts.branch_given && + !app.opts.branchname().empty() && + app.lua.hook_exists("expand_branch")) + { + branch_name const pattern = app.opts.branchname; + + set all_branches; + set matched_branches; + + // this needs to happen after the workspace options have been loaded + // to ensure that the database to look for the branch list in is known + app.get_project().get_branch_list(all_branches, app.opts.ignore_suspend_certs); + + app.lua.hook_expand_branch(pattern, + all_branches, + matched_branches); + + N(!matched_branches.empty(), + F("unable to expand branch; '%s' does not match any branches") % pattern); + + N(matched_branches.size() == 1, + F("unable to expand branch; '%s' matched multiple branches") % pattern); + + app.opts.branchname = *matched_branches.begin(); + } + cmd->exec(app, ident, args); } ============================================================ --- lua_hooks.cc ff4053ed166f572c179628ec23c9ef263484e234 +++ lua_hooks.cc 7d279ed674702ac510dc392adf0d0ceaf5189ebb @@ -334,6 +334,41 @@ lua_hooks::hook_ignore_branch(branch_nam return exec_ok && ignore_it; } +bool +lua_hooks::hook_expand_branch(branch_name const & pattern, + set const & all_branches, + set & matched_branches) +{ + Lua ll(st); + + ll.func("expand_branch") + .push_str(pattern()); + + ll.push_table(); + + int k = 1; + for (set::const_iterator + i = all_branches.begin(); i != all_branches.end(); ++i) + { + ll.push_int(k++); + ll.push_str((*i)()); + ll.set_table(); + } + + ll.call(2,1); + ll.begin(); + + matched_branches.clear(); + while(ll.next()) + { + string s; + ll.extract_str(s).pop(); + matched_branches.insert(branch_name(s)); + } + + return ll.ok(); +} + static inline bool shared_trust_function_body(Lua & ll, set const & signers, ============================================================ --- lua_hooks.hh 0f79afa4f23d64a221b23ef4b39766528fec8a14 +++ lua_hooks.hh 6e35d15a966de50cfd78bd181c39cb7b90e0f851 @@ -89,6 +89,10 @@ public: // local repo hooks bool hook_ignore_file(file_path const & p); bool hook_ignore_branch(branch_name const & branch); + bool hook_expand_branch(branch_name const & pattern, + std::set const & all_branches, + std::set & matched_branches); + bool hook_merge3(file_path const & anc_path, file_path const & left_path, file_path const & right_path,