monotone-devel
[Top][All Lists]
Advanced

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

Re: [Monotone-devel] [PATCH] head selector


From: Richard Levitte - VMS Whacker
Subject: Re: [Monotone-devel] [PATCH] head selector
Date: Sun, 26 Jun 2005 19:38:14 +0200 (CEST)

In message <address@hidden> on Sun, 26 Jun 2005 19:36:42 +0200 (CEST), Richard 
Levitte - VMS Whacker <address@hidden> said:

richard> Patch attached.

oops, forgot it...

Cheers,
Richard

-----
Please consider sponsoring my work on free software.
See http://www.free.lp.se/sponsoring.html for details.

-- 
Richard Levitte                         address@hidden
                                        http://richard.levitte.org/

"When I became a man I put away childish things, including
 the fear of childishness and the desire to be very grown up."
                                                -- C.S. Lewis
# 
# patch "automate.cc"
#  from [646411d161574bb13a8cb76ff8f8abd28de310ba]
#    to [92e8d98cdb761a20eeee7617b893e7dd7de93569]
# 
# patch "commands.cc"
#  from [f9e412756872786e2b1e29b7628331844712d796]
#    to [70ef6ccdbd805c4eb24d7d8dc8fc730f647aa2cb]
# 
# patch "database.cc"
#  from [1ce26993177acbeb3e3d18aba17f43700372fa3c]
#    to [a6ab34e6a42f8e14aaa1643abf0edbc3b42596d6]
# 
# patch "selectors.cc"
#  from [af2e5813aba3cdf936fbcbb31dbb05ddf3690ccc]
#    to [da71cd6ab6708f9cb5eceff282d60a13f86eef22]
# 
# patch "selectors.hh"
#  from [54ed172da5c3a3c4721152012d831f51e693cab9]
#    to [5173696dee24bd0cc6815ecfba30a26139623abb]
# 
--- automate.cc
+++ automate.cc
@@ -494,15 +494,29 @@
   if (args.size() != 1)
     throw usage(help_name);
 
+  bool get_heads = false;
   std::vector<std::pair<selectors::selector_type, std::string> >
-    sels(selectors::parse_selector(args[0](), app));
+    sels(selectors::parse_selector(args[0](), get_heads, app));
 
   // we jam through an "empty" selection on sel_ident type
-  std::set<std::string> completions;
+  std::set<revision_id> completions;
   selectors::selector_type ty = selectors::sel_ident;
-  selectors::complete_selector("", sels, ty, completions, app);
+  {
+    bool dummy_get_heads = false;
+    std::set<std::string> completion_strings;
+    selectors::complete_selector("", sels, ty, dummy_get_heads,
+                                 completion_strings, app, true);
+    for (std::set<std::string>::const_iterator i = completion_strings.begin();
+         i != completion_strings.end(); ++i)
+      completions.insert(revision_id(*i));
+  }
 
-  for (std::set<std::string>::const_iterator i = completions.begin();
+  if (get_heads && completions.size() > 1)
+    {
+      erase_ancestors(completions, app);
+    }
+
+  for (std::set<revision_id>::const_iterator i = completions.begin();
        i != completions.end(); ++i)
     output << *i << std::endl;
 }
--- commands.cc
+++ commands.cc
@@ -428,28 +428,42 @@
       return;
     }
 
+  bool get_heads = false;
   vector<pair<selectors::selector_type, string> >
-    sels(selectors::parse_selector(str, app));
+    sels(selectors::parse_selector(str, get_heads, app));
 
   P(F("expanding selection '%s'\n") % str);
 
   // we jam through an "empty" selection on sel_ident type
-  set<string> completions;
+  set<revision_id> completions;
   selectors::selector_type ty = selectors::sel_ident;
-  selectors::complete_selector("", sels, ty, completions, app);
+  {
+    bool dummy_get_heads = false;
+    std::set<std::string> completion_strings;
+    selectors::complete_selector("", sels, ty, dummy_get_heads,
+                                 completion_strings, app, true);
+    for (std::set<std::string>::const_iterator i = completion_strings.begin();
+         i != completion_strings.end(); ++i)
+      completions.insert(revision_id(*i));
+  }
 
   N(completions.size() != 0,
     F("no match for selection '%s'") % str);
+
+  if (get_heads && completions.size() > 1)
+    {
+      erase_ancestors(completions, app);
+    }
   if (completions.size() > 1)
     {
       string err = (F("selection '%s' has multiple ambiguous expansions: \n") 
% str).str();
-      for (set<string>::const_iterator i = completions.begin();
+      for (set<revision_id>::const_iterator i = completions.begin();
            i != completions.end(); ++i)
-        err += (describe_revision(app, revision_id(*i)) + "\n");
+        err += (describe_revision(app, *i) + "\n");
       N(completions.size() == 1, boost::format(err));
     }
-  completion = revision_id(*(completions.begin()));  
-  P(F("expanded to '%s'\n") %  completion);  
+  completion = *(completions.begin());
+  P(F("expanded to '%s'\n") %  completion);
 }
 
 static void 
--- database.cc
+++ database.cc
@@ -2176,6 +2176,7 @@
       s = author_cert_name;
       break;
     case selectors::sel_branch:
+    case selectors::sel_branch_head:
       s = branch_cert_name;
       break;
     case selectors::sel_date:
@@ -2188,6 +2189,7 @@
       break;
     case selectors::sel_ident:
     case selectors::sel_cert:
+    case selectors::sel_cert_head:
     case selectors::sel_unknown:
       I(false); // don't do this.
       break;
@@ -2221,11 +2223,11 @@
             first_limit = false;
           else
             lim += " INTERSECT ";
-          
+
           if (i->first == selectors::sel_ident)
             {
               lim += "SELECT id FROM revision_certs ";
-              lim += (F("WHERE id GLOB '%s*'") 
+              lim += (F("WHERE id GLOB '%s*'")
                       % i->second).str();
             }
           else if (i->first == selectors::sel_cert)
@@ -2259,12 +2261,12 @@
             {
               lim += "SELECT id FROM revision_certs ";
               lim += (F(" WHERE (name='%s' OR name='%s' OR name='%s')")
-                      % author_cert_name 
-                      % tag_cert_name 
+                      % author_cert_name
+                      % tag_cert_name
                       % branch_cert_name).str();
               lim += (F(" AND unbase64(value) glob '*%s*'")
-                      % i->second).str();     
+                      % i->second).str();
             }
           else
             {
--- selectors.cc
+++ selectors.cc
@@ -15,13 +15,24 @@
   static void
   decode_selector(std::string const & orig_sel,
                   selector_type & type,
+                  bool & get_heads,
                   std::string & sel,
-                  app_state & app)
+                  app_state & app,
+                  bool first_selector)
   {
     sel = orig_sel;
 
     L(F("decoding selector '%s'\n") % sel);
 
+    if (first_selector)
+      {
+        if (sel[0] == 'h' && sel[1] == ':')
+          {
+            get_heads = true;
+            sel.erase(0,2);
+          }
+      }
+
     std::string tmp;
     if (sel.size() < 2 || sel[1] != ':')
       {
@@ -46,6 +57,9 @@
           case 'b':
             type = sel_branch;
             break;
+          case 'B':
+            type = sel_branch_head;
+            break;
           case 'd':
             type = sel_date;
             break;
@@ -58,6 +72,9 @@
           case 'c':
             type = sel_cert;
             break;
+          case 'C':
+            type = sel_cert_head;
+            break;
           case 'l':
             type = sel_later;
             break;
@@ -70,12 +87,12 @@
           }
         sel.erase(0,2);
 
-        /* a selector date-related should be validated */      
+        /* a selector date-related should be validated */
         if (sel_date==type || sel_later==type || sel_earlier==type)
           {
             N (app.lua.hook_expand_date(sel, tmp), 
-            F ("selector '%s' is not a valid date\n") % sel);
-            
+               F ("selector '%s' is not a valid date\n") % sel);
+
             if (tmp.size()<8 && (sel_later==type || sel_earlier==type))
               tmp += "-01T00:00:00";
             else if (tmp.size()<11 && (sel_later==type || sel_earlier==type))
@@ -94,16 +111,19 @@
   complete_selector(std::string const & orig_sel,
                     std::vector<std::pair<selector_type, std::string> > const 
& limit,
                     selector_type & type,
+                    bool & get_heads,
                     std::set<std::string> & completions,
-                    app_state & app)
+                    app_state & app,
+                    bool first_selector)
   {
     std::string sel;
-    decode_selector(orig_sel, type, sel, app);
+    decode_selector(orig_sel, type, get_heads, sel, app, first_selector);
     app.db.complete(type, sel, limit, completions);
   }
 
   std::vector<std::pair<selector_type, std::string> >
   parse_selector(std::string const & str,
+                 bool & get_heads,
                  app_state & app)
   {
     std::vector<std::pair<selector_type, std::string> > sels;
@@ -124,14 +144,16 @@
         std::vector<std::string> selector_strings;
         copy(tokens.begin(), tokens.end(), back_inserter(selector_strings));
 
+        bool first = true;
         for (std::vector<std::string>::const_iterator i = 
selector_strings.begin();
              i != selector_strings.end(); ++i)
           {
             std::string sel;
             selector_type type = sel_unknown;
 
-            decode_selector(*i, type, sel, app);
+            decode_selector(*i, type, get_heads, sel, app, first);
             sels.push_back(std::make_pair(type, sel));
+            first = false;
           }
       }
 
--- selectors.hh
+++ selectors.hh
@@ -21,10 +21,12 @@
     {
       sel_author,
       sel_branch,
+      sel_branch_head,
       sel_date,
       sel_tag,
       sel_ident,
       sel_cert,
+      sel_cert_head,
       sel_earlier,
       sel_later,
       sel_unknown
@@ -35,10 +37,13 @@
   complete_selector(std::string const & orig_sel,
                     std::vector<std::pair<selector_type, std::string> > const 
& limit,
                     selector_type & type,
+                    bool & get_heads,
                     std::set<std::string> & completions,
-                    app_state & app);
+                    app_state & app,
+                    bool first_selector);
   std::vector<std::pair<selector_type, std::string> >
   parse_selector(std::string const & str,
+                 bool & get_heads,
                  app_state & app);
 
 }; // namespace selectors

reply via email to

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