monotone

monotone Mtn Source Tree

Root/src/epoch.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 "epoch.hh"
12#include "netio.hh"
13#include "constants.hh"
14#include "transforms.hh"
15
16
17using std::string;
18
19void
20read_epoch(string const & in,
21 branch_name & branch, epoch_data & epoch)
22{
23 size_t pos = 0;
24 string raw_branch;
25 data raw_epoch;
26 extract_variable_length_string(in, raw_branch, pos, "epoch, branch name");
27 raw_epoch = data(extract_substring(in, pos, constants::epochlen_bytes,
28 "epoch, epoch data"),
29 origin::network);
30 branch = branch_name(raw_branch, origin::network);
31 epoch = epoch_data(raw_epoch);
32}
33
34void
35write_epoch(branch_name const & branch, epoch_data const & epoch,
36 string & out)
37{
38 insert_variable_length_string(branch(), out);
39 out += epoch.inner()();
40}
41
42void
43epoch_hash_code(branch_name const & branch, epoch_data const & epoch,
44 epoch_id & eid)
45{
46 string tmp(branch() + ":" + encode_hexenc(epoch.inner()(),
47 epoch.inner().made_from));
48 data tdat(tmp, origin::internal);
49 id out;
50 calculate_ident(tdat, out);
51 eid = epoch_id(out);
52}
53
54// Local Variables:
55// mode: C++
56// fill-column: 76
57// c-file-style: "gnu"
58// indent-tabs-mode: nil
59// End:
60// 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