-
Notifications
You must be signed in to change notification settings - Fork 9
/
repo.d
140 lines (113 loc) · 2.88 KB
/
repo.d
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
module repo;
import std.array;
import std.algorithm;
import std.exception;
import std.file;
import std.parallelism : parallel;
import std.path;
import std.process;
import std.range;
import std.regex;
import std.string;
import ae.sys.file;
import ae.sys.d.manager;
import ae.utils.regex;
import common;
import config : config, opts;
import custom : parseSpec;
//alias BuildConfig = DManager.Config.Build;
final class DiggerManager : DManager
{
this()
{
this.config.build = cast().config.build;
this.config.local = cast().config.local;
this.verifyWorkTree = true; // for commands which don't take BuildOptions, like bisect
}
override void log(string s)
{
common.log(s);
}
void logProgress(string s)
{
log((" " ~ s ~ " ").center(70, '-'));
}
override SubmoduleState parseSpec(string spec)
{
return .parseSpec(spec);
}
override MetaRepository getMetaRepo()
{
if (!repoDir.exists)
log("First run detected.\nPlease be patient, " ~
"cloning everything might take a few minutes...\n");
return super.getMetaRepo();
}
override string getCallbackCommand()
{
return escapeShellFileName(thisExePath) ~ " do callback";
}
string[string] getBaseEnvironment()
{
return d.baseEnvironment.vars;
}
bool haveUpdate;
void needUpdate()
{
if (!haveUpdate)
{
d.update();
haveUpdate = true;
}
}
}
DiggerManager d;
static this()
{
d = new DiggerManager();
}
string parseRev(string rev)
{
auto args = ["log", "--pretty=format:%H"];
d.needUpdate();
auto metaRepo = d.getMetaRepo();
auto repo = &metaRepo.git();
// git's approxidate accepts anything, so a disambiguating prefix is required
if (rev.canFind('@') && !rev.canFind("@{"))
{
auto parts = rev.findSplit("@");
auto at = parts[2].strip();
// If this is a named tag, use the date of the tagged commit.
try
{
auto sha1 = metaRepo.getRef("refs/tags/" ~ at);
at = repo.query("log", "-1", "--pretty=format:%cI", sha1);
}
catch (Exception e) {}
if (at.startsWith("#")) // For the build-all command - skip this many commits
args ~= ["--skip", at[1..$]];
else
args ~= ["--until", at];
rev = parts[0].strip();
}
if (rev.empty)
rev = "origin/master";
try
if (metaRepo.getRef("origin/" ~ rev))
return repo.query(args ~ ["-n", "1", "origin/" ~ rev]);
catch (Exception e) {}
try
if (metaRepo.getRef(rev))
return repo.query(args ~ ["-n", "1", rev]);
catch (Exception e) {}
if (rev.startsWith("https://github.com"))
{
auto grep = repo.query("log", "-n", "2", "--pretty=format:%H", "--grep", "^" ~ escapeRE(rev), "origin/master").splitLines();
if (grep.length == 1)
return grep[0];
}
auto pickaxe = repo.query("log", "-n", "3", "--pretty=format:%H", "-S" ~ rev, "origin/master").splitLines();
if (pickaxe.length && pickaxe.length <= 2) // removed <- added
return pickaxe[$-1]; // the one where it was added
throw new Exception("Unknown/ambiguous revision: " ~ rev);
}