File: legacy.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 (182 lines) | stat: -rw-r--r-- 5,174 bytes parent folder | download | duplicates (5)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright (C) 2005 Nathaniel Smith <njs@pobox.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 "legacy.hh"
#include "basic_io.hh"
#include "constants.hh"
#include "database.hh"
#include "transforms.hh"

using std::make_pair;
using std::string;

namespace legacy
{
  namespace
  {
    namespace syms
    {
      symbol const file("file");
    }
  };

  // cf. work.cc:read_attr_map in the pre-roster code.
  void
  read_dot_mt_attrs(data const & dat, dot_mt_attrs_map & attr)
  {
    basic_io::input_source src(dat(), ".mt-attrs");
    basic_io::tokenizer tok(src);
    basic_io::parser parser(tok);

    string file, name, value;

    attr.clear();

    while (parser.symp(syms::file))
      {
        parser.sym();
        parser.str(file);
        file_path fp = file_path_internal(file);

        while (parser.symp() &&
               !parser.symp(syms::file))
          {
            parser.sym(name);
            parser.str(value);
            attr[fp][name] = value;
          }
      }
  }

  namespace
  {
    namespace syms
    {
      symbol const new_manifest("new_manifest");
      symbol const old_revision("old_revision");
      symbol const old_manifest("old_manifest");
      symbol const patch("patch");
      symbol const from("from");
      symbol const to("to");
      symbol const add_file("add_file");
      symbol const delete_file("delete_file");
      symbol const delete_dir("delete_dir");
      symbol const rename_file("rename_file");
      symbol const rename_dir("rename_dir");
    }
  }

  // cf. revision.cc:parse_edge and change_set.cc:parse_change_set and
  // change_set.cc:parse_path_rearrangement in the pre-roster code.
  static void
  extract_renames(basic_io::parser & parser, renames_map & renames)
  {
    revision_id old_rev;
    string tmp;
    parser.esym(syms::old_revision);
    parser.hex(tmp);
    old_rev = decode_hexenc_as<revision_id>(tmp, origin::internal);
    parser.esym(syms::old_manifest);
    parser.hex();

    while (parser.symp())
      {
        // things that take a single string argument
        if (parser.symp(syms::add_file)
            || parser.symp(syms::delete_file)
            || parser.symp(syms::delete_dir))
          {
            parser.sym();
            parser.str();
          }
        else if (parser.symp(syms::rename_file)
                 || parser.symp(syms::rename_dir))
          {
            string from_str, to_str;
            parser.sym();
            parser.str(from_str);
            parser.esym(syms::to);
            parser.str(to_str);
            renames[old_rev][file_path_internal(to_str)]
              = file_path_internal(from_str);
          }
        else if (parser.symp(syms::patch))
          {
            parser.sym();
            parser.str();
            parser.esym(syms::from);
            parser.hex();
            parser.esym(syms::to);
            parser.hex();
          }
        else
          break;
      }
  }

  // cf. revision.cc:parse_revision in the pre-roster code.
  void
  get_manifest_and_renames_for_rev(database & db,
                                   revision_id const & ident,
                                   manifest_id & mid,
                                   renames_map & renames)
  {
    revision_data dat;
    db.get_revision(ident, dat);
    basic_io::input_source src(dat.inner()(), "revision");
    basic_io::tokenizer tok(src);
    basic_io::parser pars(tok);

    pars.esym(syms::new_manifest);
    string tmp;
    pars.hex(tmp);
    mid = decode_hexenc_as<manifest_id>(tmp, origin::internal);
    while (pars.symp(syms::old_revision))
      extract_renames(pars, renames);
  }

  // cf. manifest.cc:read_manifest_map in the pre-roster code.
  void
  read_manifest_map(manifest_data const & mdat,
                    manifest_map & man)
  {
    data const & dat = mdat.inner();
    string::size_type pos = 0;
    while (pos != dat().size())
      {
        // whenever we get here, pos points to the beginning of a manifest
        // line
        // manifest file has 40 characters hash, then 2 characters space, then
        // everything until next \n is filename.
        string ident = dat().substr(pos, constants::idlen);
        string::size_type file_name_begin = pos + constants::idlen + 2;
        pos = dat().find('\n', file_name_begin);
        string file_name;
        if (pos == string::npos)
          file_name = dat().substr(file_name_begin);
        else
          file_name = dat().substr(file_name_begin, pos - file_name_begin);
        man.insert(make_pair(file_path_internal(file_name),
                             decode_hexenc_as<file_id>(ident, origin::internal)));
        // skip past the '\n'
        ++pos;
      }
    return;
  }

}

// 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: