monotone-devel
[Top][All Lists]
Advanced

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

[Monotone-devel] [patch] cvs_import and CVS tags


From: Richard Levitte - VMS Whacker
Subject: [Monotone-devel] [patch] cvs_import and CVS tags
Date: Tue, 03 Aug 2004 10:24:52 +0200 (CEST)

Hi,

I hacked and rehacked to get CVS tags added to the synthesized
manifests.  The attached patch is the result.

There's a corner case with this: I'm not at all sure what happens with
tags that exist on one of several revisions that are slammed together
into one manifest, as discussed in another thread.  It's possible that
cvs_history::find_key_and_state() needs to be tweaked to take note of
tags.  I'm guessing that shouldn't be too difficult, as it's already
done when branchings occur.

-----
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/
# Old manifest: a4a197a9ad2f14ee2e4aee4ba8e5bf7f483f731c
# New manifest: 25ababbdcab89981fcba3646d58ea036d8a83144
# Summary of changes:
# 
#   patch ChangeLog
#    from e2ac5cabf1db3a2d95af7ac3c049a56863bd22f2
#      to 4a2b680f7f26ca74e30c1fb4358587c98a6fb131
# 
#   patch interner.hh
#    from 199531a1da252a8843a0fc6aad9f46546c7f82a0
#      to e26b6eb8b9738c48bdcba5cb62a8792f218c8439
# 
#   patch rcs_import.cc
#    from 66dc27e4a9b4aa059de70a396a97bace9eb40f93
#      to ec6e87d3f1d5cd5477a67d59a37235a8620c55a0
# 
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,19 @@
+2004-08-02  Richard Levitte  <address@hidden>
+
+       * rcs_import.cc, interner.hh: Changes to add CVS tags in the
+       monotone database.  The changes are:
+
+       * rcs_import.cc (struct cvs_key): Add a vector of ingeters to
+       represent all the tags present in this key.
+       (struct cvs_history): Add an interner for all the tags.
+       (find_tags_for_version): New function to find all the tags
+       associated with a CVS revision.
+       (cvs_key::cvs_key): Intern all the tags we found.
+       (store_auxiliary_certs): Store all the CVS tags in the manifest.
+
+       * interner.hh (struct intern): A functor to intern strings in
+       container using STL iterator algorithms.
+
 2004-07-31  graydon hoare  <address@hidden>
 
        * AUTHORS: Mention Richard Levitte.
--- interner.hh
+++ interner.hh
@@ -8,6 +8,7 @@
 
 #include <map>
 #include <string>
+#include <functional>
 
 #include "sanity.hh"
 
@@ -41,4 +42,12 @@
   }
 };
 
+template <typename T>
+struct intern : public std::unary_function<std::string, T>
+{
+  interner<T> & _interner;
+  intern(interner<T> & i) : _interner(i) {}
+  T operator()(std::string const & s) { return _interner.intern(s); }
+};
+
 #endif // __INTERNER_HH__
--- rcs_import.cc
+++ rcs_import.cc
@@ -46,6 +46,7 @@
 
 // cvs history recording stuff
 
+typedef unsigned long cvs_tagname;
 typedef unsigned long cvs_branchname;
 typedef unsigned long cvs_author;
 typedef unsigned long cvs_changelog;
@@ -91,6 +92,7 @@
        && branch > other.branch);
   }
 
+  vector<cvs_tagname> tags;
   cvs_branchname branch;
   cvs_changelog changelog;
   cvs_author author;
@@ -154,6 +155,7 @@
 cvs_history
 {
 
+  interner<unsigned long> tag_interner;
   interner<unsigned long> branch_interner;
   interner<unsigned long> author_interner;
   interner<unsigned long> changelog_interner;
@@ -680,6 +681,53 @@
     }
 }
 
+vector<string> 
+find_tags_for_version(multimap<string,string> const & symbols,
+                     string const & version,
+                     string const & base)
+{
+  typedef multimap<string,string>::const_iterator ity;
+  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
+
+  L(F("looking up tag name for %s\n") % version);
+
+  pair<ity,ity> range = symbols.equal_range(version);
+  vector<string> res;
+  int num_results = 0;
+  string all_res;
+
+  if (range.first != symbols.end())
+    {
+      while (range.first != range.second)
+       {
+         res.push_back(range.first->second);
+         if (!all_res.empty()) { all_res += " "; }
+         all_res += "'";
+         all_res += range.first->second;
+         all_res += "'";
+         range.first++;
+         num_results++;
+       }
+    }
+
+  switch (num_results)
+    {
+    case 0:
+      W(F("no entries for revision %s found\n")
+       % version);
+      break;
+    case 1:
+      L(F("unique entry for revision %s found: %s\n")
+       % version % all_res);
+      break;
+    default:
+      L(F("multiple entries (%d) for revision %s found, using:\n  %s\n")
+       % num_results % version % all_res);
+      break;
+    }
+  return res;
+}
+
 cvs_key::cvs_key(rcs_file const & r, string const & version,
                 cvs_history & cvs) 
 {
@@ -709,7 +756,16 @@
   string branch_name = find_branch_for_version(r.admin.symbols, 
                                               version, 
                                               cvs.base_branch);
+  vector<string> tag_names = find_tags_for_version(r.admin.symbols, 
+                                                  version,
+                                                  cvs.base_branch);
   branch = cvs.branch_interner.intern(branch_name);
+  if (!tag_names.empty())
+    {
+      transform(tag_names.begin(), tag_names.end(),
+               insert_iterator< vector<cvs_tagname> >(tags, tags.begin()),
+               intern<unsigned long>(cvs.tag_interner));
+    }
   changelog = cvs.changelog_interner.intern(deltatext->second->log);
   author = cvs.author_interner.intern(delta->second->author);
 }
@@ -1055,6 +1064,11 @@
 {
   packet_db_writer dbw(app);
   cert_manifest_in_branch(id, 
cert_value(cvs.branch_interner.lookup(key.branch)), app, dbw); 
+  for(vector<unsigned long>::const_iterator i = key.tags.begin();
+      i != key.tags.end(); i++)
+    {
+      cert_manifest_tag(id, cvs.tag_interner.lookup((*i)), app, dbw);
+    }
   cert_manifest_author(id, cvs.author_interner.lookup(key.author), app, dbw); 
   cert_manifest_changelog(id, cvs.changelog_interner.lookup(key.changelog), 
app, dbw);
   cert_manifest_date_time(id, key.time, app, dbw);

reply via email to

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