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 "constants.hh"
14#include "database.hh"
15#include "transforms.hh"
16
17using std::make_pair;
18using std::string;
19
20namespace legacy
21{
22 namespace
23 {
24 namespace syms
25 {
26 symbol const file("file");
27 }
28 };
29
30 // cf. work.cc:read_attr_map in the pre-roster code.
31 void
32 read_dot_mt_attrs(data const & dat, dot_mt_attrs_map & attr)
33 {
34 basic_io::input_source src(dat(), ".mt-attrs");
35 basic_io::tokenizer tok(src);
36 basic_io::parser parser(tok);
37
38 string file, name, value;
39
40 attr.clear();
41
42 while (parser.symp(syms::file))
43 {
44 parser.sym();
45 parser.str(file);
46 file_path fp = file_path_internal(file);
47
48 while (parser.symp() &&
49 !parser.symp(syms::file))
50 {
51 parser.sym(name);
52 parser.str(value);
53 attr[fp][name] = value;
54 }
55 }
56 }
57
58 namespace
59 {
60 namespace syms
61 {
62 symbol const new_manifest("new_manifest");
63 symbol const old_revision("old_revision");
64 symbol const old_manifest("old_manifest");
65 symbol const patch("patch");
66 symbol const from("from");
67 symbol const to("to");
68 symbol const add_file("add_file");
69 symbol const delete_file("delete_file");
70 symbol const delete_dir("delete_dir");
71 symbol const rename_file("rename_file");
72 symbol const rename_dir("rename_dir");
73 }
74 }
75
76 // cf. revision.cc:parse_edge and change_set.cc:parse_change_set and
77 // change_set.cc:parse_path_rearrangement in the pre-roster code.
78 static void
79 extract_renames(basic_io::parser & parser, renames_map & renames)
80 {
81 revision_id old_rev;
82 string tmp;
83 parser.esym(syms::old_revision);
84 parser.hex(tmp);
85 old_rev = revision_id(decode_hexenc(tmp));
86 parser.esym(syms::old_manifest);
87 parser.hex();
88
89 while (parser.symp())
90 {
91 // things that take a single string argument
92 if (parser.symp(syms::add_file)
93 || parser.symp(syms::delete_file)
94 || parser.symp(syms::delete_dir))
95 {
96 parser.sym();
97 parser.str();
98 }
99 else if (parser.symp(syms::rename_file)
100 || parser.symp(syms::rename_dir))
101 {
102 string from_str, to_str;
103 parser.sym();
104 parser.str(from_str);
105 parser.esym(syms::to);
106 parser.str(to_str);
107 renames[old_rev][file_path_internal(to_str)]
108 = file_path_internal(from_str);
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(database & db,
127 revision_id const & ident,
128 manifest_id & mid,
129 renames_map & renames)
130 {
131 revision_data dat;
132 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(decode_hexenc(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 file_id(decode_hexenc(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