Changeset 294 for trunk/lib/Trac.cc


Ignore:
Timestamp:
May 8, 2007, 7:47:12 PM (16 years ago)
Author:
Peter Johansson
Message:

refs #180, support:
diff:@288:294,
diff:tags/release-0.4/bin//tags/release-0.5/bin or
diff:trunk/lib/Trac.cc@288//trunk/lib/Trac.cc@294

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Trac.cc

    r293 r294  
    9696      return false;
    9797    const std::string::const_iterator first_orig(first);
    98     if (match(first, last, "changeset:").empty()){
     98    if (match(first, last, Str("changeset:")).empty()){
    9999      first = first_orig;
    100100      return false;
     
    123123      if (changeset(first, str.end()))
    124124        continue;
     125      if (diff(first, str.end()))
     126        continue;
    125127      hs_ << *first;
    126128      ++first;
     
    136138
    137139    const std::string::const_iterator first_orig(first);
    138     if (match(first, last, "comment:ticket:").empty()){
     140    if (match(first, last, Str("comment:ticket:")).empty()){
    139141      first = first_orig;
    140142      return false;
     
    208210    const std::string::const_iterator first_orig(first);
    209211
    210     if (match(first, last, "ticket:").empty()){
     212    if (match(first, last, Str("ticket:")).empty()){
    211213      first = first_orig;
    212214      return false;
     
    217219    const Configuration& conf = Configuration::instance();
    218220    hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket,"#"+ticket);
     221    return true;
     222  }
     223
     224
     225  bool Trac::diff(std::string::const_iterator& first,
     226                  const std::string::const_iterator& last)
     227  {
     228    if (diff1(first, last))
     229      return true;
     230    if (diff3(first, last))
     231      return true;
     232    if (diff2(first, last))
     233      return true;
     234    return false;
     235  }
     236
     237
     238  bool Trac::diff1(std::string::const_iterator& first,
     239                   const std::string::const_iterator& last)
     240  {
     241    if (first==last)
     242      return false;
     243
     244    const std::string::const_iterator first_orig(first);
     245    if (match(first, last, Str("diff:")).empty()){
     246      first = first_orig;
     247      return false;
     248    }
     249    std::string node = match(first, last, notChar('@'));
     250    if (first==last){
     251      first = first_orig;
     252      return false;
     253    }
     254    ++first;
     255    std::string old_rev = match(first, last, Digit());
     256    if (old_rev.empty() || first == last || *first != ':') {
     257      first = first_orig;
     258      return false;
     259    }
     260    ++first;
     261    std::string new_rev = match(first, last, Digit());
     262    if (new_rev.empty() ) {
     263      first = first_orig;
     264      return false;
     265    }
     266    std::string href;
     267    if (node.empty())
     268      href = std::string(Configuration::instance().trac_root()+
     269                         "changeset?new="+new_rev+"&old="+old_rev);
     270    else
     271      href = std::string(Configuration::instance().trac_root()+
     272                         "changeset?new="+new_rev+"&new_path="+node+"&old="+
     273                         old_rev+"&oldpath="+node);
     274    hs_.stream() << anchor(href, std::string(first_orig, first));
     275    return true;
     276  }
     277
     278
     279  bool Trac::diff2(std::string::const_iterator& first,
     280                   const std::string::const_iterator& last)
     281  {
     282    if (first==last)
     283      return false;
     284
     285    const std::string::const_iterator first_orig(first);
     286    if (match(first, last, Str("diff:")).empty()){
     287      first = first_orig;
     288      return false;
     289    }
     290    std::string old_path(match(first, last, not2Str("//", " ")));
     291    std::string new_path;
     292    if (first==last || *first==' ')
     293      new_path = old_path;
     294    else {
     295      first += 2;
     296      new_path = match(first, last, notChar(' '));
     297    }
     298    if (new_path.empty() || old_path.empty()){
     299      first = first_orig;
     300      return false;
     301    }
     302    std::string href(Configuration::instance().trac_root()+
     303                     "changeset?new_path="+new_path+"&old_path="+old_path);
     304    hs_.stream() << anchor(href, std::string(first_orig, first));
     305    return true;
     306  }
     307
     308
     309  bool Trac::diff3(std::string::const_iterator& first,
     310                   const std::string::const_iterator& last)
     311  {
     312    if (first==last)
     313      return false;
     314
     315    const std::string::const_iterator first_orig(first);
     316    if (match(first, last, Str("diff:")).empty()){
     317      first = first_orig;
     318      return false;
     319    }
     320    std::string old_path(match(first, last, not2Char('@', ' ')));
     321    if (*first!='@'){
     322      first = first_orig;
     323      return false;
     324    }
     325    ++first;
     326    std::string old_rev(match(first, last, Digit()));
     327    if (!match_begin(first, first+1, std::string("//"))) {
     328      first = first_orig;
     329      return false;
     330    }
     331    first+2;
     332    std::string new_path = match(first, last, not2Char('@', ' '));
     333    if (*first!='@'){
     334      first = first_orig;
     335      return false;
     336    }
     337    ++first;
     338    std::string new_rev(match(first, last, Digit()));
     339    if (new_rev.empty()){
     340      first = first_orig;
     341      return false;
     342    }
     343   
     344    std::string href(Configuration::instance().trac_root()+
     345                     "changeset?new="+new_rev+"&new_path="+new_path+
     346                     "&old="+old_rev+"&old_path="+old_path);
     347    hs_.stream() << anchor(href, std::string(first_orig, first));
    219348    return true;
    220349  }
Note: See TracChangeset for help on using the changeset viewer.