@@ -101,60 +101,48 @@ TString GetYaBuildDate()
101
101
return GetProgramBuildDate ();
102
102
}
103
103
104
- namespace {
105
-
106
- // //////////////////////////////////////////////////////////////////////////////
107
-
108
- TString BuildRpcUserAgent () noexcept
104
+ const TString& GetRpcUserAgent ()
109
105
{
110
- // Fill user agent from build information.
111
- // For trunk:
112
- // - yt-cpp/r<revision>
113
- // For YT release branch.
114
- // - yt-cpp/<YT version string>
115
- // For arbitrary branch different from trunk:
116
- // - yt-cpp/<branch>~<commit>
117
- // For local build from detached head or arc sync'ed state:
118
- // - yt-cpp/local~<commit>
119
-
120
- TString branch (GetBranch ());
121
- TStringStream out;
122
-
123
- out << " yt-cpp/" ;
124
-
125
- if (branch == " trunk" ) {
126
- int svnRevision = GetProgramSvnRevision ();
127
- out << " trunk~r" << svnRevision;
128
- } else if (branch.StartsWith (" releases/yt" )) {
129
- // Simply re-use YT version string. It looks like the following:
130
- // 20.3.7547269-stable-ya~bb57c034bfb47caa.
131
- TString ytVersion (GetVersion ());
132
- out << ytVersion;
133
- } else {
134
- auto commit = GetCommitHash ();
135
- auto truncatedCommit = TruncateCommitHash (commit);
136
-
137
- // In detached head arc state branch seems to coincide with commit hash.
138
- // Let's use that in order to distinguish detached head from regular branch state.
139
- if (branch == commit) {
140
- branch = " local" ;
106
+ static const auto result = [&] {
107
+ // Fill user agent from build information.
108
+ // For trunk:
109
+ // - yt-cpp/r<revision>
110
+ // For YT release branch.
111
+ // - yt-cpp/<YT version string>
112
+ // For arbitrary branch different from trunk:
113
+ // - yt-cpp/<branch>~<commit>
114
+ // For local build from detached head or arc sync'ed state:
115
+ // - yt-cpp/local~<commit>
116
+
117
+ TString branch (GetBranch ());
118
+ TStringStream out;
119
+
120
+ out << " yt-cpp/" ;
121
+
122
+ if (branch == " trunk" ) {
123
+ int svnRevision = GetProgramSvnRevision ();
124
+ out << " trunk~r" << svnRevision;
125
+ } else if (branch.StartsWith (" releases/yt" )) {
126
+ // Simply re-use YT version string. It looks like the following:
127
+ // 20.3.7547269-stable-ya~bb57c034bfb47caa.
128
+ TString ytVersion (GetVersion ());
129
+ out << ytVersion;
130
+ } else {
131
+ auto commit = GetCommitHash ();
132
+ auto truncatedCommit = TruncateCommitHash (commit);
133
+
134
+ // In detached head arc state branch seems to coincide with commit hash.
135
+ // Let's use that in order to distinguish detached head from regular branch state.
136
+ if (branch == commit) {
137
+ branch = " local" ;
138
+ }
139
+
140
+ out << branch << " ~" << truncatedCommit;
141
141
}
142
142
143
- out << branch << " ~" << truncatedCommit;
144
- }
145
-
146
- return out.Str ();
147
- }
148
-
149
- const TString CachedUserAgent = BuildRpcUserAgent();
150
-
151
- // //////////////////////////////////////////////////////////////////////////////
152
-
153
- } // namespace
154
-
155
- const TString& GetRpcUserAgent ()
156
- {
157
- return CachedUserAgent;
143
+ return out.Str ();
144
+ }();
145
+ return result;
158
146
}
159
147
160
148
// //////////////////////////////////////////////////////////////////////////////
0 commit comments