monotone

monotone Mtn Source Tree

Root/selectors.cc

1// -*- mode: C++; c-file-style: "gnu"; indent-tabs-mode: nil -*-
2// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
3// all rights reserved.
4// licensed to the public under the terms of the GNU GPL (>= 2)
5// see the file COPYING for details
6
7#include "selectors.hh"
8#include "sanity.hh"
9#include "app_state.hh"
10#include "constants.hh"
11
12namespace selectors
13{
14
15 static void
16 decode_selector(std::string const & orig_sel,
17 selector_type & type,
18 std::string & sel,
19 app_state & app)
20 {
21 sel = orig_sel;
22
23 L(F("decoding selector '%s'\n") % sel);
24
25 if (sel.size() < 2 || sel[1] != ':')
26 {
27std::string tmp;
28if (!app.lua.hook_expand_selector(sel, tmp))
29 {
30 L(F("expansion of selector '%s' failed\n") % sel);
31 }
32else
33 {
34 P(F("expanded selector '%s' -> '%s'\n") % sel % tmp);
35 sel = tmp;
36 }
37 }
38
39 if (sel.size() >= 2 && sel[1] == ':')
40 {
41switch (sel[0])
42 {
43 case 'a':
44 type = sel_author;
45 break;
46 case 'b':
47 type = sel_branch;
48 break;
49 case 'd':
50 type = sel_date;
51 break;
52 case 'i':
53 type = sel_ident;
54 break;
55 case 't':
56 type = sel_tag;
57 break;
58 case 'c':
59 type = sel_cert;
60 break;
61 default:
62 W(F("unknown selector type: %c\n") % sel[0]);
63 break;
64 }
65sel.erase(0,2);
66 }
67 }
68
69 void
70 complete_selector(std::string const & orig_sel,
71 std::vector<std::pair<selector_type, std::string> > const & limit,
72 selector_type & type,
73 std::set<std::string> & completions,
74 app_state & app)
75 {
76 std::string sel;
77 decode_selector(orig_sel, type, sel, app);
78 app.db.complete(type, sel, limit, completions);
79 }
80
81 std::vector<std::pair<selector_type, std::string> >
82 parse_selector(std::string const & str,
83 app_state & app)
84 {
85 std::vector<std::pair<selector_type, std::string> > sels;
86
87 // this rule should always be enabled, even if the user specifies
88 // --norc: if you provide a revision id, you get a revision id.
89 if (str.find_first_not_of(constants::legal_id_bytes) == std::string::npos
90&& str.size() == constants::idlen)
91 {
92sels.push_back(std::make_pair(sel_ident, str));
93 }
94 else
95 {
96typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
97boost::char_separator<char> slash("/");
98tokenizer tokens(str, slash);
99
100std::vector<std::string> selector_strings;
101copy(tokens.begin(), tokens.end(), back_inserter(selector_strings));
102
103for (std::vector<std::string>::const_iterator i = selector_strings.begin();
104 i != selector_strings.end(); ++i)
105 {
106 std::string sel;
107 selector_type type = sel_unknown;
108
109 decode_selector(*i, type, sel, app);
110 sels.push_back(std::make_pair(type, sel));
111 }
112 }
113
114 return sels;
115 }
116
117}; // namespace selectors

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status