monotone

monotone Mtn Source Tree

Root/manifest.hh

1#ifndef __MANIFEST_HH__
2#define __MANIFEST_HH__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9#include <map>
10#include <set>
11#include <string>
12
13#include "quick_alloc.hh"
14#include "vocab.hh"
15
16// this file defines the class of manifest_map objects, and various
17// comparison and i/o functions on them. a manifest_map is an unpacked
18// (analyzed) manifest_data blob. it specifies exactly which versions of
19// each file reside at which path location in a given tree. the textual
20// encoding of a manifest looks like this:
21//
22// ...
23// f2e5719b975e319c2371c98ed2c7231313fac9b5 fs/readdir.c
24// 81f0c9a0df254bc8d51bb785713a9f6d0b020b22 fs/read_write.c
25// 943851e7da46014cb07473b90d55dd5145f24de0 fs/pipe.c
26// ddc2686e000e97f670180c60a3066989e56a11a3 fs/open.c
27// 295d276e6c9ce64846d309a8e39507bcb0a14248 fs/namespace.c
28// 71e0274f16cd68bdf9a2bf5743b86fcc1e597cdc fs/namei.c
29// 1112c0f8054cebc9978aa77384e3e45c0f3b6472 fs/iobuf.c
30// 8ddcfcc568f33db6205316d072825d2e5c123275 fs/inode.c
31// ...
32//
33// which is essentially the result of running:
34//
35// 'find -type f | xargs sha1sum'
36//
37// with some minor tidying up of pathnames and sorting. manifests must
38// have only one entry for each pathname. the same sha1 can occur multiple
39// times in a manifest.
40
41typedef std::set<file_path> path_set;
42extern std::string const manifest_file_name;
43typedef std::pair<file_path, file_id> entry;
44typedef std::pair<file_path const, file_id> manifest_map_entry;
45typedef std::map<file_path, file_id,
46 std::less<file_path>,
47 QA(manifest_map_entry) > manifest_map;
48
49// this helper exists solely to save us writing ->first and ->second all
50// over the place when dealing with entries / members of manifest_maps. they're
51// unreadable enough to make some otherwise clear functions obscure and
52// buggy. maybe you can keep it clear in your head, but I can't always.
53
54class path_id_pair
55{
56 entry dat;
57public:
58 path_id_pair() {}
59 path_id_pair(manifest_map::const_iterator i) : dat(*i) {}
60 path_id_pair(entry const & e) : dat(e) {}
61 entry const & get_entry() { return dat; }
62
63 file_path const & path() const { return dat.first; }
64 path_id_pair & path(file_path const & p) { dat.first = p; return *this; }
65
66 file_id const & ident() const { return dat.second; }
67 path_id_pair & ident(file_id const & i) { dat.second = i; return *this; }
68};
69
70// analyzed changes to a manifest_map (not just blob-delta)
71struct manifest_changes
72{
73 std::set<entry> adds;
74 std::set<entry> dels;
75};
76
77void calculate_manifest_changes(manifest_map const & a,
78manifest_map const & b,
79manifest_changes & changes);
80
81void apply_manifest_changes(manifest_map const & a,
82 manifest_changes const & changes,
83 manifest_map & b);
84
85void write_manifest_changes(manifest_changes const & changes,
86 data & dat);
87
88std::ostream & operator<<(std::ostream & out, entry const & e);
89
90class app_state;
91
92// from cwd
93void build_manifest_map(app_state & app,
94manifest_map & man);
95
96// from some safe sub-dir within cwd
97void build_manifest_map(file_path const & path,
98app_state & app,
99manifest_map & man);
100
101void build_manifest_map(path_set const & paths,
102manifest_map & man,
103app_state & app);
104
105void append_manifest_map(manifest_map const & m1,
106 manifest_map & m2);
107
108void read_manifest_map(data const & dat,
109 manifest_map & man);
110
111void read_manifest_map(manifest_data const & dat,
112 manifest_map & man);
113
114void write_manifest_map(manifest_map const & man,
115manifest_data & dat);
116
117void write_manifest_map(manifest_map const & man,
118data & dat);
119
120#endif // __MANIFEST_HH__

Archive Download this file

Branches

Tags

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