/
patch_find_bug.cc
113 lines (94 loc) · 2.88 KB
/
patch_find_bug.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#define INCLUDE_TESTSETUP_WITHOUT_BOOST
#include "zypp/../tests/lib/TestSetup.h"
#undef INCLUDE_TESTSETUP_WITHOUT_BOOST
#include "zypp/PoolQuery.h"
using namespace zypp;
using std::flush;
static std::string appname( "patch_find_bug" );
int errexit( const std::string & msg_r = std::string(), int exit_r = 101 )
{
if ( ! msg_r.empty() )
{
cerr << endl << msg_r << endl << endl;
}
return exit_r;
}
int usage( const std::string & msg_r = std::string(), int exit_r = 100 )
{
if ( ! msg_r.empty() )
{
cerr << endl << msg_r << endl << endl;
}
cerr << "Usage: " << appname << "[OPTIONS] bugnumber..." << endl;
cerr << " Find patches refering to bugnumber (substring)." << endl;
cerr << " --root SYSROOT: Load system located below directory SYSROOT" << endl;
return exit_r;
}
/******************************************************************
**
** FUNCTION NAME : main
** FUNCTION TYPE : int
*/
int main( int argc, char * argv[] )
{
INT << "===[START]==========================================" << endl;
appname = Pathname::basename( argv[0] );
--argc;
++argv;
if ( ! argc )
{
return usage();
}
///////////////////////////////////////////////////////////////////
ZConfig::instance();
Pathname sysRoot("/");
if ( (*argv) == std::string("--root") )
{
--argc,++argv;
if ( ! argc )
return errexit("--root requires an argument.");
if ( ! PathInfo( *argv ).isDir() )
return errexit("--root requires a directory.");
sysRoot = *argv;
--argc,++argv;
}
TestSetup::LoadSystemAt( sysRoot );
for ( ; argc; --argc,++argv )
{
PoolQuery q;
q.setMatchSubstring();
q.setCaseSensitive( false );
q.addAttribute( sat::SolvAttr::updateReferenceId, *argv );
if ( q.empty() )
{
cout << "BUG REFERENCE '" << *argv << "': No match found." << endl;
}
else
{
cout << "BUG REFERENCE '" << *argv << endl;
for_( it , q.begin(), q.end() )
{
// print the solvable that has a match:
cout << " - " << *it << endl;
if ( true )
{
// Print details about each match in that solvable:
for_( d, it.matchesBegin(), it.matchesEnd() )
{
// directly access specific attribute like "subFind(updateReferenceType)":
cout << " - " << d->inSolvAttr() << "\t\"" << d->asString() << "\" has type \""
<< d->subFind( sat::SolvAttr::updateReferenceType ).asString() << "\"" << endl;
// list the whole updateReference structure:
for_( s, d->subBegin(), d->subEnd() )
{
cout << " -" << s.inSolvAttr() << "\t\"" << s.asString() << "\"" << endl;
}
}
}
}
}
}
///////////////////////////////////////////////////////////////////
INT << "===[END]============================================" << endl << endl;
return 0;
}