# # # patch "automate.cc" # from [9a700bfc52a6a21e3b5d2d930ad634d455dafcae] # to [39f349c665414f3b466c7d3e83b859d3262bde1b] # # patch "options_list.hh" # from [cd0ff5a0d051b4644c02a5f81ed262a512c65360] # to [95ef5f739f0168a179e5889686581dd1a775b8e1] # ============================================================ --- automate.cc 9a700bfc52a6a21e3b5d2d930ad634d455dafcae +++ automate.cc 39f349c665414f3b466c7d3e83b859d3262bde1b @@ -13,6 +13,7 @@ #include #include #include +#include #include "vector.hh" #include @@ -61,6 +62,7 @@ using std::vector; using std::streamsize; using std::string; using std::vector; +using std::ostream_iterator; // Name: heads @@ -502,7 +504,9 @@ CMD_AUTOMATE(select, N_("SELECTOR"), CMD_AUTOMATE(select, N_("SELECTOR"), N_("Lists the revisions that match a selector"), "", - options::opts::none) + options::opts::sort_revs| + options::opts::limit| + options::opts::reverse) { N(args.size() == 1, F("wrong argument count")); @@ -512,9 +516,38 @@ CMD_AUTOMATE(select, N_("SELECTOR"), set completions; expand_selector(app.opts, app.lua, project, idx(args, 0)(), completions); - for (set::const_iterator i = completions.begin(); - i != completions.end(); ++i) - output << *i << '\n'; + if (app.opts.sort_revs.empty()) + { + copy(completions.begin(), completions.end(), + ostream_iterator(output, "\n")); + } + else + { + vector result; + + if (app.opts.sort_revs == "topological") + { + toposort(db, completions, result); + } + else + { + // TBD: add more sorting options here + copy(completions.begin(), completions.end(), + back_inserter(result)); + } + long count = std::min(boost::lexical_cast(result.size()), app.opts.limit); + + if (app.opts.reverse) + { + copy(result.rbegin(), result.rbegin()+count, + ostream_iterator(output, "\n")); + } + else + { + copy(result.begin(), result.begin()+count, + ostream_iterator(output, "\n")); + } + } } struct node_info ============================================================ --- options_list.hh cd0ff5a0d051b4644c02a5f81ed262a512c65360 +++ options_list.hh 95ef5f739f0168a179e5889686581dd1a775b8e1 @@ -535,6 +535,37 @@ OPT(set_default, "set-default", bool, fa } #endif +OPT(sort_revs, "sort-revs", std::string, , + gettext_noop("specify how to sort the revisions list")) +#ifdef option_bodies +{ + sort_revs = arg; + + if (arg.empty()) + throw bad_arg_internal(F("--sort requires a value ").str()); + // if (arg != "topological" ) + // throw bad_arg_internal(F("invalid arg for --sort").str()); +} +#endif + +OPT(limit, "limit", long, 0, + gettext_noop("limit the number of revisions returned")) +#ifdef option_bodies +{ + limit = boost::lexical_cast(arg); + if (limit < 0) + throw bad_arg_internal(F("limit cannot be negative").str()); +} +#endif + +OPT(reverse, "reverse", bool, false, + gettext_noop("revert the order for the list of revisions returned")) +#ifdef option_bodies +{ + reverse = true; +} +#endif + GOPT(ticker, "ticker", std::string, , gettext_noop("set ticker style (count|dot|none)")) #ifdef option_bodies