monotone

monotone Mtn Source Tree

Root/inodeprint.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 <string>
11#include <iterator>
12#include <sstream>
13#include <iostream>
14#include <algorithm>
15#include <iterator>
16
17#include "app_state.hh"
18#include "inodeprint.hh"
19#include "sanity.hh"
20#include "platform.hh"
21#include "constants.hh"
22#include "basic_io.hh"
23
24using std::ostream;
25using std::ostringstream;
26using std::string;
27
28// this file defines the inodeprint_map structure, and some operations on it.
29
30namespace
31{
32 namespace syms
33 {
34 // roster symbols
35 symbol const format_version("format_version");
36 symbol const file("file");
37 symbol const print("print");
38 }
39}
40// reading inodeprint_maps
41
42void
43read_inodeprint_map(data const & dat,
44 inodeprint_map & ipm)
45{
46 // don't bomb out if it's just an old-style inodeprints file
47 string start = dat().substr(0, syms::format_version().size());
48 if (start != syms::format_version())
49 {
50 L(FL("inodeprints file format is wrong, skipping it"));
51 return;
52 }
53
54 basic_io::input_source src(dat(), "inodeprint");
55 basic_io::tokenizer tok(src);
56 basic_io::parser pa(tok);
57
58 {
59 pa.esym(syms::format_version);
60 string vers;
61 pa.str(vers);
62 I(vers == "1");
63 }
64
65 while(pa.symp())
66 {
67 string path, print;
68
69 pa.esym(syms::file);
70 pa.str(path);
71 pa.esym(syms::print);
72 pa.hex(print);
73
74 ipm.insert(inodeprint_entry(file_path_internal(path),
75 hexenc<inodeprint>(print)));
76 }
77 I(src.lookahead == EOF);
78}
79
80void
81write_inodeprint_map(inodeprint_map const & ipm,
82 data & dat)
83{
84 basic_io::printer pr;
85 {
86 basic_io::stanza st;
87 st.push_str_pair(syms::format_version, "1");
88 pr.print_stanza(st);
89 }
90 for (inodeprint_map::const_iterator i = ipm.begin();
91 i != ipm.end(); ++i)
92 {
93 basic_io::stanza st;
94 st.push_file_pair(syms::file, i->first);
95 st.push_hex_pair(syms::print, i->second());
96 pr.print_stanza(st);
97 }
98 dat = pr.buf;
99}
100
101// Local Variables:
102// mode: C++
103// fill-column: 76
104// c-file-style: "gnu"
105// indent-tabs-mode: nil
106// End:
107// 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