File: cmd_othervcs.cc

package info (click to toggle)
monotone 0.48-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 20,096 kB
  • ctags: 8,077
  • sloc: cpp: 81,000; sh: 6,402; perl: 1,241; lisp: 1,045; makefile: 655; python: 566; sql: 112; ansic: 52
file content (154 lines) | stat: -rw-r--r-- 4,562 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
//               2009 Derek Scherger <derek@echologic.com>
//
// This program is made available under the GNU GPL version 2.0 or
// greater. See the accompanying file COPYING for details.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.

#include "base.hh"
#include "cmd.hh"
#include "app_state.hh"
#include "database.hh"
#include "git_change.hh"
#include "git_export.hh"
#include "project.hh"
#include "rcs_import.hh"
#include "revision.hh"
#include "keys.hh"
#include "key_store.hh"

using std::map;
using std::set;
using std::string;
using std::vector;

CMD(rcs_import, "rcs_import", "", CMD_REF(debug), N_("RCSFILE..."),
    N_("Parses versions in RCS files"),
    N_("This command doesn't reconstruct or import revisions.  "
       "You probably want to use cvs_import."),
    options::opts::branch)
{
  if (args.size() < 1)
    throw usage(execid);

  for (args_vector::const_iterator i = args.begin();
       i != args.end(); ++i)
    test_parse_rcs_file(system_path((*i)(), origin::user));
}


CMD(cvs_import, "cvs_import", "", CMD_REF(vcs), N_("CVSROOT"),
    N_("Imports all versions in a CVS repository"),
    "",
    options::opts::branch)
{
  database db(app);
  key_store keys(app);
  project_t project(db);

  if (args.size() != 1)
    throw usage(execid);

  E(!app.opts.branch().empty(), origin::user,
    F("need base --branch argument for importing"));

  system_path cvsroot(idx(args, 0)(), origin::user);
  require_path_is_directory(cvsroot,
                            F("path %s does not exist") % cvsroot,
                            F("'%s' is not a directory") % cvsroot);

  // make sure we can sign certs using the selected key; also requests
  // the password (if necessary) up front rather than after some arbitrary
  // amount of work
  cache_user_key(app.opts, app.lua, db, keys, project);

  import_cvs_repo(project, keys, cvsroot, app.opts.branch);
}


CMD(git_export, "git_export", "", CMD_REF(vcs), (""),
    N_("Produces a git fast-export data stream on stdout"),
    (""),
    options::opts::authors_file | options::opts::branches_file |
    options::opts::log_revids | options::opts::log_certs | 
    options::opts::use_one_changelog |
    options::opts::import_marks | options::opts::export_marks |
    options::opts::refs)
{
  database db(app);

  if (args.size() != 0)
    throw usage(execid);

  map<string, string> author_map;
  map<string, string> branch_map;

  if (!app.opts.authors_file.empty())
    {
      P(F("reading author mappings from '%s'") % app.opts.authors_file);
      read_mappings(app.opts.authors_file, author_map);
      validate_author_mappings(app.lua, author_map);
    }

  if (!app.opts.branches_file.empty())
    {
      P(F("reading branch mappings from '%s'") % app.opts.branches_file);
      read_mappings(app.opts.branches_file, branch_map);
    }

  map<revision_id, size_t> marked_revs;

  if (!app.opts.import_marks.empty())
    {
      P(F("importing revision marks from '%s'") % app.opts.import_marks);
      import_marks(app.opts.import_marks, marked_revs);
    }

  set<revision_id> revision_set;
  db.get_revision_ids(revision_set);

  // remove marked revs from the set to be exported
  for (map<revision_id, size_t>::const_iterator
         i = marked_revs.begin(); i != marked_revs.end(); ++i)
    revision_set.erase(i->first);

  vector<revision_id> revisions;
  toposort(db, revision_set, revisions);

  map<revision_id, git_change> change_map;

  load_changes(db, revisions, change_map);

  // needs author and branch maps
  export_changes(db, app.lua,
                 revisions, marked_revs,
                 author_map, branch_map, change_map,
                 app.opts.log_revids, app.opts.log_certs,
                 app.opts.use_one_changelog);

  if (app.opts.refs.find("revs") != app.opts.refs.end())
    export_rev_refs(revisions, marked_revs);

  if (app.opts.refs.find("roots") != app.opts.refs.end())
    export_root_refs(db, marked_revs);

  if (app.opts.refs.find("leaves") != app.opts.refs.end())
    export_leaf_refs(db, marked_revs);

  if (!app.opts.export_marks.empty())
    {
      P(F("exporting revision marks to '%s'") % app.opts.export_marks);
      export_marks(app.opts.export_marks, marked_revs);
    }
}

// Local Variables:
// mode: C++
// fill-column: 76
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: