• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GothenburgBitFactory / taskwarrior / 10152339701

29 Jul 2024 09:45PM UTC coverage: 84.437% (+0.07%) from 84.372%
10152339701

push

github

web-flow
Merge pull request #3566 from felixschurk/add-clang-format

Add clang-format to enforce style guide

12359 of 13760 new or added lines in 147 files covered. (89.82%)

123 existing lines in 42 files now uncovered.

19070 of 22585 relevant lines covered (84.44%)

19724.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.55
/src/columns/ColDepends.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included
13
// in all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
//
23
// https://www.opensource.org/licenses/mit-license.php
24
//
25
////////////////////////////////////////////////////////////////////////////////
26

27
#include <cmake.h>
28
// cmake.h include header must come first
29

30
#include <ColDepends.h>
31
#include <Context.h>
32
#include <format.h>
33
#include <main.h>
34
#include <shared.h>
35
#include <stdlib.h>
36
#include <utf8.h>
37
#include <util.h>
38

39
#include <algorithm>
40
#include <regex>
41

42
#define STRING_COLUMN_LABEL_DEP "Depends"
43

44
////////////////////////////////////////////////////////////////////////////////
45
ColumnDepends::ColumnDepends() {
4,926✔
46
  _name = "depends";
4,926✔
47
  _style = "list";
4,926✔
48
  _label = STRING_COLUMN_LABEL_DEP;
4,926✔
49
  _styles = {"list", "count", "indicator"};
19,704✔
50
  _examples = {"1 2 10", "[3]", Context::getContext().config.get("dependency.indicator")};
19,704✔
51

52
  _hyphenate = false;
4,926✔
53
}
4,926✔
54

55
////////////////////////////////////////////////////////////////////////////////
56
// Overriden so that style <----> label are linked.
57
// Note that you can not determine which gets called first.
58
void ColumnDepends::setStyle(const std::string& value) {
537✔
59
  Column::setStyle(value);
537✔
60

61
  if (_style == "indicator" && _label == STRING_COLUMN_LABEL_DEP)
537✔
62
    _label = _label.substr(0, Context::getContext().config.get("dependency.indicator").length());
461✔
63
  else if (_style == "count" && _label == STRING_COLUMN_LABEL_DEP)
76✔
64
    _label = "Dep";
1✔
65
}
537✔
66

67
////////////////////////////////////////////////////////////////////////////////
68
// Set the minimum and maximum widths for the value.
69
void ColumnDepends::measure(Task& task, unsigned int& minimum, unsigned int& maximum) {
1,006✔
70
  minimum = maximum = 0;
1,006✔
71
  auto deptasks = task.getDependencyTasks();
1,006✔
72

73
  if (deptasks.size() > 0) {
1,006✔
74
    if (_style == "indicator") {
24✔
75
      minimum = maximum = utf8_width(Context::getContext().config.get("dependency.indicator"));
22✔
76
    }
77

78
    else if (_style == "count") {
2✔
79
      minimum = maximum = 2 + format((int)deptasks.size()).length();
1✔
80
    }
81

82
    else if (_style == "default" || _style == "list") {
1✔
83
      minimum = maximum = 0;
1✔
84

85
      std::vector<int> blocking_ids;
1✔
86
      blocking_ids.reserve(deptasks.size());
1✔
87
      for (auto& i : deptasks) blocking_ids.push_back(i.id);
2✔
88

89
      auto all = join(" ", blocking_ids);
2✔
90
      maximum = all.length();
1✔
91

92
      unsigned int length;
93
      for (auto& i : deptasks) {
2✔
94
        length = format(i.id).length();
1✔
95
        if (length > minimum) minimum = length;
1✔
96
      }
97
    }
1✔
98
  }
99
}
1,006✔
100

101
////////////////////////////////////////////////////////////////////////////////
102
void ColumnDepends::render(std::vector<std::string>& lines, Task& task, int width, Color& color) {
156✔
103
  auto deptasks = task.getDependencyTasks();
156✔
104

105
  if (deptasks.size() > 0) {
156✔
106
    if (_style == "indicator") {
24✔
107
      renderStringRight(lines, width, color,
22✔
108
                        Context::getContext().config.get("dependency.indicator"));
44✔
109
    }
110

111
    else if (_style == "count") {
2✔
112
      renderStringRight(lines, width, color, '[' + format(static_cast<int>(deptasks.size())) + ']');
1✔
113
    }
114

115
    else if (_style == "default" || _style == "list") {
1✔
116
      std::vector<int> blocking_ids;
1✔
117
      blocking_ids.reserve(deptasks.size());
1✔
118
      for (const auto& t : deptasks) blocking_ids.push_back(t.id);
2✔
119

120
      auto combined = join(" ", blocking_ids);
2✔
121

122
      std::vector<std::string> all;
1✔
123
      wrapText(all, combined, width, _hyphenate);
1✔
124

125
      for (const auto& i : all) renderStringLeft(lines, width, color, i);
2✔
126
    }
1✔
127
  }
128
}
156✔
129

130
////////////////////////////////////////////////////////////////////////////////
131
void ColumnDepends::modify(Task& task, const std::string& value) {
53✔
132
  // Apply or remove dendencies in turn.
133
  for (auto& dep : split(value, ',')) {
111✔
134
    bool removal = false;
63✔
135
    if (dep[0] == '-') {
63✔
136
      removal = true;
5✔
137
      dep = dep.substr(1);
5✔
138
    }
139

140
    auto hyphen = dep.find('-');
63✔
141
    long lower, upper;                                       // For ID ranges
142
    std::regex valid_uuid("[a-f0-9]{8}([a-f0-9-]{4,28})?");  // TODO: Make more precise
63✔
143

144
    // UUID
145
    if (dep.length() >= 8 && std::regex_match(dep, valid_uuid)) {
63✔
146
      // Full UUID, can be added directly
147
      if (dep.length() == 36)
8✔
148
        if (removal)
6✔
149
          task.removeDependency(dep);
1✔
150
        else
151
          task.addDependency(dep);
5✔
152

153
      // Short UUID, need to look up full form
154
      else {
155
        Task loaded_task;
2✔
156
        if (Context::getContext().tdb2.get(dep, loaded_task))
2✔
157
          if (removal)
2✔
158
            task.removeDependency(loaded_task.get("uuid"));
1✔
159
          else
160
            task.addDependency(loaded_task.get("uuid"));
1✔
161
        else
NEW
162
          throw format("Dependency could not be set - task with UUID '{1}' does not exist.", dep);
×
163
      }
2✔
164
    }
165
    // ID range
166
    else if (dep.find('-') != std::string::npos &&
112✔
167
             extractLongInteger(dep.substr(0, hyphen), lower) &&
111✔
168
             extractLongInteger(dep.substr(hyphen + 1), upper)) {
56✔
169
      for (long i = lower; i <= upper; i++)
3✔
170
        if (removal)
2✔
NEW
171
          task.removeDependency(i);
×
172
        else
173
          task.addDependency(i);
2✔
174
    }
175
    // Simple ID
176
    else if (extractLongInteger(dep, lower))
54✔
177
      if (removal)
54✔
178
        task.removeDependency(lower);
3✔
179
      else
180
        task.addDependency(lower);
51✔
181
    else
NEW
182
      throw format("Invalid dependency value: '{1}'", dep);
×
183
  }
116✔
184
}
48✔
185

186
////////////////////////////////////////////////////////////////////////////////
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc