monotone

monotone Mtn Source Tree

Root/legacy.cc

1// Copyright (C) 2005 Nathaniel Smith <njs@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#include "legacy.hh"
11#include "basic_io.hh"
12#include "app_state.hh"
13#include "constants.hh"
14
15using std::make_pair;
16using std::string;
17
18namespace legacy
19{
20 namespace
21 {
22 namespace syms
23 {
24 symbol const file("file");
25 }
26 };
27
28 // cf. work.cc:read_attr_map in the pre-roster code.
29 void
30 read_dot_mt_attrs(data const & dat, dot_mt_attrs_map & attr)
31 {
32 basic_io::input_source src(dat(), ".mt-attrs");
33 basic_io::tokenizer tok(src);
34 basic_io::parser parser(tok);
35
36 string file, name, value;
37
38 attr.clear();
39
40 while (parser.symp(syms::file))
41 {
42 parser.sym();
43 parser.str(file);
44 file_path fp = file_path_internal(file);
45
46 while (parser.symp() &&
47 !parser.symp(syms::file))
48 {
49 parser.sym(name);
50 parser.str(value);
51 attr[fp][name] = value;
52 }
53 }
54 }
55
56 namespace
57 {
58 namespace syms
59 {
60 symbol const new_manifest("new_manifest");
61 symbol const old_revision("old_revision");
62 symbol const old_manifest("old_manifest");
63 symbol const patch("patch");
64 symbol const from("from");
65 symbol const to("to");
66 symbol const add_file("add_file");
67 symbol const delete_file("delete_file");
68 symbol const delete_dir("delete_dir");
69 symbol const rename_file("rename_file");
70 symbol const rename_dir("rename_dir");
71 }
72 }
73
74 // cf. revision.cc:parse_edge and change_set.cc:parse_change_set and
75 // change_set.cc:parse_path_rearrangement in the pre-roster code.
76 static void
77 extract_renames(basic_io::parser & parser, renames_map & renames)
78 {
79 revision_id old_rev;
80 string tmp;
81 parser.esym(syms::old_revision);
82 parser.hex(tmp);
83 old_rev = revision_id(tmp);
84 parser.esym(syms::old_manifest);
85 parser.hex();
86
87 while (parser.symp())
88 {
89 // things that take a single string argument
90 if (parser.symp(syms::add_file)
91 || parser.symp(syms::delete_file)
92 || parser.symp(syms::delete_dir))
93 {
94 parser.sym();
95 parser.str();
96 }
97 else if (parser.symp(syms::rename_file)
98 || parser.symp(syms::rename_dir))
99 {
100 string from_str, to_str;
101 parser.sym();
102 parser.str(from_str);
103 parser.esym(syms::to);
104 parser.str(to_str);
105 split_path from, to;
106 file_path_internal(from_str).split(from);
107 file_path_internal(to_str).split(to);
108 renames[old_rev][to] = from;
109 }
110 else if (parser.symp(syms::patch))
111 {
112 parser.sym();
113 parser.str();
114 parser.esym(syms::from);
115 parser.hex();
116 parser.esym(syms::to);
117 parser.hex();
118 }
119 else
120 break;
121 }
122 }
123
124 // cf. revision.cc:parse_revision in the pre-roster code.
125 void
126 get_manifest_and_renames_for_rev(app_state & app,
127 revision_id const & ident,
128 manifest_id & mid,
129 renames_map & renames)
130 {
131 revision_data dat;
132 app.db.get_revision(ident, dat);
133 basic_io::input_source src(dat.inner()(), "revision");
134 basic_io::tokenizer tok(src);
135 basic_io::parser pars(tok);
136
137 pars.esym(syms::new_manifest);
138 string tmp;
139 pars.hex(tmp);
140 mid = manifest_id(tmp);
141 while (pars.symp(syms::old_revision))
142 extract_renames(pars, renames);
143 }
144
145 // cf. manifest.cc:read_manifest_map in the pre-roster code.
146 void
147 read_manifest_map(manifest_data const & mdat,
148 manifest_map & man)
149 {
150 data const & dat = mdat.inner();
151 string::size_type pos = 0;
152 while (pos != dat().size())
153 {
154 // whenever we get here, pos points to the beginning of a manifest
155 // line
156 // manifest file has 40 characters hash, then 2 characters space, then
157 // everything until next \n is filename.
158 string ident = dat().substr(pos, constants::idlen);
159 string::size_type file_name_begin = pos + constants::idlen + 2;
160 pos = dat().find('\n', file_name_begin);
161 string file_name;
162 if (pos == string::npos)
163 file_name = dat().substr(file_name_begin);
164 else
165 file_name = dat().substr(file_name_begin, pos - file_name_begin);
166 man.insert(make_pair(file_path_internal(file_name),
167 hexenc<id>(ident)));
168 // skip past the '\n'
169 ++pos;
170 }
171 return;
172 }
173
174}
175
176// Local Variables:
177// mode: C++
178// fill-column: 76
179// c-file-style: "gnu"
180// indent-tabs-mode: nil
181// End:
182// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

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