Skip to content

Commit 7c431c3

Browse files
committed
ide: Get repository URL from the git config
1 parent 7e37789 commit 7c431c3

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

uppsrc/ide/About.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,39 @@ extern const char *bm_USER;
1818
extern const char *bm_GIT_REVCOUNT;
1919
extern const char *bm_GIT_BRANCH;
2020
extern const char *bm_GIT_HASH;
21+
extern const char *bm_GIT_URL;
22+
23+
String GetCommitUrl(const String &url, const String &rev) {
24+
String https = "https://";
25+
String s = url;
26+
27+
if (url.Find(https) == -1) {
28+
int pos = url.Find('@');
29+
if (pos > -1) {
30+
s = https + url.Mid(pos + 1);
31+
pos = s.Find(':', https.GetLength());
32+
if (pos > -1) {
33+
int i;
34+
for (i = pos + 1; i < s.GetLength(); ++i) {
35+
if (!IsNumberValueTypeNo(s[i]))
36+
break;
37+
}
38+
s.Remove(pos, i - pos);
39+
s.Insert(pos, '/');
40+
}
41+
}
42+
}
43+
44+
int pos = s.ReverseFind(".git");
45+
if (pos > -1) {
46+
s = s.Left(pos);
47+
}
48+
49+
String commit = "\1[^";
50+
commit << s << "/commit/" << rev << "^ ";
51+
52+
return commit;
53+
}
2154

2255
String SplashCtrl::GenerateVersionInfo(bool qtf, bool about)
2356
{
@@ -32,7 +65,7 @@ String SplashCtrl::GenerateVersionInfo(bool qtf, bool about)
3265
dr.Trim(8);
3366
h << "Revision: ";
3467
if(qtf && about)
35-
h << "\1[^https://github.com/ultimatepp/ultimatepp/commit/" << rev << "^ ";
68+
h << GetCommitUrl(bm_GIT_URL, rev);
3669
h << dr;
3770
if(qtf && about)
3871
h << "]\1";

uppsrc/ide/BuildInfo.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const char *bm_GIT_BRANCH =
2020
#endif
2121
;
2222
const char *bm_GIT_REVCOUNT =
23-
#ifdef bmGIT_HASH
23+
#ifdef bmGIT_REVCOUNT
2424
bmGIT_REVCOUNT
2525
#else
2626
""
@@ -33,3 +33,10 @@ const char *bm_GIT_HASH =
3333
""
3434
#endif
3535
;
36+
const char *bm_GIT_URL =
37+
#ifdef bmGIT_URL
38+
bmGIT_URL
39+
#else
40+
"https://github.com/ultimatepp/ultimatepp"
41+
#endif
42+
;

uppsrc/ide/Builders/CppBuilder.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -501,41 +501,23 @@ Vector<String> GitInfo(const String& package)
501501
Vector<String> info;
502502
String d = GetFileFolder(PackagePath(package));
503503
if(IsGitDir2(d)) {
504-
String command = "git -C " << d << " log -n 1 --pretty=format:\"\%h\"";
504+
String gitpath = GetGitPath();
505+
String command = gitpath << " -C " << d << " log -n 1 --pretty=format:\"\%h\"";
505506
String v = Sys(command);
506507
if(!v.IsEmpty())
507508
info.Add("#define bmGIT_REVISION " + AsCString(TrimBoth(v)));
508-
command = "git -C " << d << " rev-parse --abbrev-ref HEAD";
509+
command = gitpath << " -C " << d << " rev-parse --abbrev-ref HEAD";
509510
v = Sys(command);
510-
if(!v.IsEmpty())
511-
info.Add("#define bmGIT_BRANCH " + AsCString(TrimBoth(v)));
512-
command = "git -C " << d << " config --local branch." << TrimBoth(v) << ".remote";
511+
command = gitpath << " -C " << d << " config --local branch." << TrimBoth(v) << ".remote";
513512
v = Sys(command);
514-
command = "git -C " << d << " config --local remote." << TrimBoth(v) << ".url";
513+
command = gitpath << " -C " << d << " config --local remote." << TrimBoth(v) << ".url";
515514
v = Sys(command);
516515
if(!v.IsEmpty())
517516
info.Add("#define bmGIT_URL " + AsCString(TrimBoth(v)));
518517
}
519518
return info;
520519
}
521520

522-
bool IsSvnDir2(const String& p)
523-
{ // this is a cope of usvn/IsSvnDir to avoid modular issues
524-
if(IsNull(p))
525-
return false;
526-
if(DirectoryExists(AppendFileName(p, ".svn")) || DirectoryExists(AppendFileName(p, "_svn")))
527-
return true;
528-
String path = p;
529-
String path0;
530-
while(path != path0) {
531-
path0 = path;
532-
path = GetFileFolder(path);
533-
if(DirectoryExists(AppendFileName(path, ".svn")))
534-
return true;
535-
}
536-
return false;
537-
}
538-
539521
bool IsWin32Manifest(const String& s)
540522
{
541523
return s == "manifest.xml";

0 commit comments

Comments
 (0)