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

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

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

85.71
/src/unique_path.cc
1
/**
2
 * Copyright (c) 2020, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

30
#include "unique_path.hh"
31

32
#include "config.h"
33
#include "fmt/format.h"
34

35
void
36
unique_path_generator::add_source(
1,223✔
37
    const std::shared_ptr<unique_path_source>& path_source)
38
{
39
    const auto path = path_source->get_path();
1,223✔
40

41
    path_source->set_unique_path(path.filename());
1,223✔
42
    path_source->set_path_prefix(path.parent_path());
1,223✔
43
    this->upg_unique_paths[path.filename()].push_back(path_source);
1,223✔
44
}
1,223✔
45

46
void
47
unique_path_generator::generate()
1,632✔
48
{
49
    int loop_count = 0;
1,632✔
50

51
    while (!this->upg_unique_paths.empty()) {
2,726✔
52
        std::vector<std::shared_ptr<unique_path_source>> collisions;
1,094✔
53

54
        for (const auto& pair : this->upg_unique_paths) {
2,314✔
55
            if (pair.second.size() == 1) {
1,220✔
56
                if (loop_count > 0) {
1,218✔
57
                    const auto src = pair.second[0];
×
58
                    auto lsquare = fmt::format(FMT_STRING("[{}"),
×
59
                                               src->get_unique_path().native());
×
60
                    src->set_unique_path(lsquare);
×
61
                }
62

63
                this->upg_max_len = std::max(
2,436✔
64
                    this->upg_max_len,
1,218✔
65
                    pair.second[0]->get_unique_path().native().size());
1,218✔
66
            } else {
67
                bool all_common = true;
2✔
68

69
                do {
4✔
70
                    std::string common;
4✔
71

72
                    for (const auto& src : pair.second) {
13✔
73
                        auto& path = src->get_path_prefix();
9✔
74

75
                        if (common.empty()) {
9✔
76
                            common = path.filename();
4✔
77
                            if (common.empty()) {
4✔
UNCOV
78
                                all_common = false;
×
79
                            }
80
                        } else if (common != path.filename()) {
5✔
81
                            all_common = false;
2✔
82
                        }
83
                    }
84

85
                    if (all_common) {
4✔
86
                        for (const auto& src : pair.second) {
6✔
87
                            auto& path = src->get_path_prefix();
4✔
88
                            auto par = path.parent_path();
4✔
89

90
                            if (path.empty() || path == par) {
4✔
UNCOV
91
                                all_common = false;
×
92
                            } else {
93
                                src->set_path_prefix(path.parent_path());
4✔
94
                            }
95
                        }
4✔
96
                    }
97
                } while (all_common);
4✔
98

99
                collisions.insert(
4✔
100
                    collisions.end(), pair.second.begin(), pair.second.end());
4✔
101
            }
102
        }
103

104
        this->upg_unique_paths.clear();
1,094✔
105

106
        for (auto& src : collisions) {
1,099✔
107
            const auto unique_path = src->get_unique_path();
5✔
108
            const auto& prefix = src->get_path_prefix();
5✔
109

110
            if (loop_count == 0) {
5✔
111
                src->set_unique_path(prefix.filename().string() + "]/"
20✔
112
                                     + unique_path.string());
20✔
113
            } else {
UNCOV
114
                src->set_unique_path(prefix.filename().string() + "/"
×
UNCOV
115
                                     + unique_path.string());
×
116
            }
117

118
            const auto parent = prefix.parent_path();
5✔
119

120
            src->set_path_prefix(parent);
5✔
121

122
            if (parent.empty() || parent == prefix) {
5✔
123
                auto lsquare = fmt::format(FMT_STRING("[{}"),
15✔
124
                                           src->get_unique_path().native());
5✔
125
                src->set_unique_path(lsquare);
5✔
126
            } else {
5✔
UNCOV
127
                this->upg_unique_paths[src->get_unique_path()].push_back(src);
×
128
            }
129
        }
5✔
130

131
        loop_count += 1;
1,094✔
132
    }
1,094✔
133
}
1,632✔
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