1 //
2 // aegis - project change supervisor
3 // Copyright (C) 2007, 2008, 2010, 2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18
19 #include <common/ac/assert.h>
20
21 #include <common/nstring.h>
22 #include <libaegis/change/file.h>
23 #include <libaegis/input/file_text.h>
24 #include <libaegis/os.h>
25 #include <libaegis/sub.h>
26
27 #include <aede-policy/validation/files/merge-rcs.h>
28
29
~validation_files_merge_rcs()30 validation_files_merge_rcs::~validation_files_merge_rcs()
31 {
32 }
33
34
validation_files_merge_rcs()35 validation_files_merge_rcs::validation_files_merge_rcs()
36 {
37 }
38
39
40 validation::pointer
create(void)41 validation_files_merge_rcs::create(void)
42 {
43 return pointer(new validation_files_merge_rcs());
44 }
45
46
47 bool
check_binaries() const48 validation_files_merge_rcs::check_binaries()
49 const
50 {
51 return false;
52 }
53
54
55 bool
check(change::pointer cp,fstate_src_ty * src)56 validation_files_merge_rcs::check(change::pointer cp, fstate_src_ty *src)
57 {
58 nstring bad_juju = "<<<<<<<";
59
60 nstring path(cp->file_path(src));
61 assert(!path.empty());
62 if (path.empty())
63 return true;
64
65 os_become_orig();
66 input ip = input_file_text_open(path);
67 bool ok = true;
68 int line_number = 0;
69 for (;;)
70 {
71 nstring line;
72 if (!ip->one_line(line))
73 break;
74 ++line_number;
75 if (line.starts_with(bad_juju))
76 {
77 sub_context_ty sc;
78 sc.var_set_format
79 (
80 "File_Name",
81 "%s: %d",
82 src->file_name->str_text,
83 line_number
84 );
85 change_error(cp, &sc, i18n("$filename: merge conflicts"));
86 ok = false;
87 break;
88 }
89 }
90 ip.close();
91 os_become_undo();
92 return ok;
93 }
94
95
96 // vim: set ts=8 sw=4 et :
97