monotone

monotone Mtn Source Tree

Root/inodeprint.cc

1// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
2// copyright (C) 2005 nathaniel smith <njs@pobox.com>
3// all rights reserved.
4// licensed to the public under the terms of the GNU GPL (>= 2)
5// see the file COPYING for details
6
7#include <string>
8#include <iterator>
9#include <sstream>
10#include <iostream>
11#include <algorithm>
12#include <iterator>
13
14#include "app_state.hh"
15#include "manifest.hh"
16#include "inodeprint.hh"
17#include "sanity.hh"
18#include "platform.hh"
19#include "constants.hh"
20
21// this file defines the inodeprint_map structure, and some operations on it.
22// it is currently heavily based on manifest.cc.
23
24// reading inodeprint_maps
25
26void
27read_inodeprint_map(data const & dat,
28 inodeprint_map & ipm)
29{
30 std::string::size_type pos = 0;
31 while (pos != dat().size())
32 {
33 // whenever we get here, pos points to the beginning of a inodeprint
34 // line
35 // inodeprint file has 40 characters hash, then 2 characters space, then
36 // everything until next \n is filename.
37 std::string ident = dat().substr(pos, constants::idlen);
38 std::string::size_type file_name_begin = pos + constants::idlen + 2;
39 pos = dat().find('\n', file_name_begin);
40 std::string file_name;
41 if (pos == std::string::npos)
42 file_name = dat().substr(file_name_begin);
43 else
44 file_name = dat().substr(file_name_begin, pos - file_name_begin);
45 ipm.insert(inodeprint_entry(file_path(file_name),
46 hexenc<inodeprint>(ident)));
47 // skip past the '\n'
48 ++pos;
49 }
50 return;
51}
52
53// writing inodeprint_maps
54
55std::ostream &
56operator<<(std::ostream & out, inodeprint_entry const & e)
57{
58 return (out << e.second << " " << e.first << "\n");
59}
60
61
62void
63write_inodeprint_map(inodeprint_map const & ipm,
64 data & dat)
65{
66 std::ostringstream sstr;
67 for (inodeprint_map::const_iterator i = ipm.begin();
68 i != ipm.end(); ++i)
69 sstr << *i;
70 dat = sstr.str();
71}

Archive Download this file

Branches

Tags

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