monotone

monotone Mtn Source Tree

Root/maybe_workspace_updater.cc

1// Copyright (C) 2010 and later by various people
2// see monotone commit logs for details and authors
3//
4// This program is made available under the GNU GPL version 2.0 or
5// greater. See the accompanying file COPYING for details.
6//
7// This program is distributed WITHOUT ANY WARRANTY; without even the
8// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9// PURPOSE.
10
11#include "base.hh"
12#include "maybe_workspace_updater.hh"
13
14#include "app_state.hh"
15#include "option.hh"
16#include "project.hh"
17#include "revision.hh"
18#include "work.hh"
19
20// defined in cmd_merging.cc
21void update(app_state & app, args_vector const & args);
22
23namespace {
24 enum updatability { is_head, is_not_head, not_updatable };
25 updatability get_updatability(app_state & app, project_t & project)
26 {
27 if (!workspace::found)
28 return not_updatable;
29 workspace work(app);
30 revision_t rev;
31 work.get_work_rev(rev);
32 if (rev.edges.size() != 1)
33 return not_updatable;
34 options workspace_opts;
35 work.get_options(workspace_opts);
36 std::set<revision_id> heads;
37 project.get_branch_heads(workspace_opts.branch, heads, false);
38
39 revision_id parent = edge_old_revision(rev.edges.begin());
40 if (heads.find(parent) != heads.end())
41 return is_head;
42 else
43 return is_not_head;
44 }
45}
46
47maybe_workspace_updater::maybe_workspace_updater(app_state & app,
48 project_t & project)
49 : can_do_update(app.opts.auto_update),
50 app(app), project(project)
51{
52 if (can_do_update)
53 can_do_update = (get_updatability(app, project) == is_head);
54}
55
56void maybe_workspace_updater::maybe_do_update()
57{
58 if (can_do_update && (get_updatability(app, project) == is_not_head))
59 {
60 update(app, args_vector());
61 }
62 else
63 {
64 P(F("note: your workspace has not been updated"));
65 }
66}
67
68// Local Variables:
69// mode: C++
70// fill-column: 76
71// c-file-style: "gnu"
72// indent-tabs-mode: nil
73// End:
74// 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