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