FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/core/GitGraph.cpp at master · pearsonca/rstudio · GitHub
pearsonca
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
GitGraph.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
162 lines (137 loc) · 4.66 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
GitGraph.cpp
Copy path
File metadata and controls
162 lines (137 loc) · 4.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* GitGraph.cpp
*
* Copyright (C) 2009-18 by RStudio, PBC
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
<
limits
>
#
include
<
algorithm
>
#
include
<
core/GitGraph.hpp
>
#
include
<
shared_core/SafeConvert.hpp
>
namespace
rstudio
{
namespace
core
{
namespace
gitgraph
{
namespace
{
//
If true, then this column terminates in this row's nexus.
bool
isColumnTerminating
(
const
Column& column)
{
return
column.
postCommit
.
empty
();
}
//
If true, then this column either starts in this row's nexus,
//
ends there, or passes through it. If false, then the column
//
has nothing going on in this row (well, it's possibly changing
//
positions as a result of other columns being added/removed).
bool
isColumnDynamic
(
const
Column& column)
{
return
column.
preCommit
!= column.
postCommit
;
}
}
//
namespace
size_t
Line::nexus
()
const
{
Line::const_iterator it =
std::find_if
(
begin
(),
end
(), &isColumnDynamic);
if
(it ==
end
())
return
std::numeric_limits<
size_t
>::
max
();
else
return
it -
begin
();
}
std::string
Line::string
()
const
{
std::string output;
bool
sawNexus =
false
;
for
(
size_t
i =
0
; i <
size
(); i++)
{
const
Column& c =
at
(i);
if
(
isColumnDynamic
(c))
{
if
(!sawNexus)
{
sawNexus =
true
;
output.
append
(
"
*
"
);
}
if
(c.
preCommit
.
empty
())
output.
append
(
"
+
"
);
if
(c.
postCommit
.
empty
())
output.
append
(
"
-
"
);
}
output.
append
(
safe_convert::numberToString
(c.
id
));
if
(i <
size
() -
1
)
output.
append
(
"
"
);
}
return
output;
}
Line
GitGraph::addCommit
(
const
std::string& commit,
const
std::vector<std::string>& parents)
{
//
If this commit is a merge (has multiple parents) then we'll want to
//
insert new columns immediately to the right of the existing column.
//
If this commit isn't the parent of a previously seen node, then we'll
//
definitely be adding one or more columns to the right of all the
//
existing columns.
auto
insertNewColumnsAt = pendingLine_.
end
();
//
Counts how many of the parents have been assigned to columns.
size_t
parentsUsed =
0
;
for
(
auto
it = pendingLine_.
begin
();
it != pendingLine_.
end
();
it++)
{
if
(it->
preCommit
== commit)
{
//
This column was expecting the current commit. We can either
//
terminate the column here, or, we can take the first parent
//
and set that as the new commit (postCommit) for this column.
//
We can only do the latter once, as we want all of the columns
//
for this commit to converge on one point in the graph.
//
This if clause is what ensures we'll only do this once.
if
(insertNewColumnsAt == pendingLine_.
end
())
{
//
If this is a merge, we'll insert the other branches just
//
to the right of us.
insertNewColumnsAt = it +
1
;
//
Either assign the first parent to this, or if this is an
//
unparented commit (e.g. initial commit in a repo) then just
//
terminate here.
if
(parentsUsed == parents.
size
())
it->
postCommit
=
"
"
;
else
it->
postCommit
= parents[parentsUsed++];
}
else
{
it->
postCommit
=
"
"
;
}
}
}
//
Make new columns for any parents we haven't already used.
while
(parentsUsed != parents.
size
())
{
insertNewColumnsAt =
1
+ pendingLine_.
insert
(
insertNewColumnsAt,
Column
(nextColumnId_++,
"
"
, parents[parentsUsed++]));
}
//
This line is ready. Make a copy of it.
Line result = pendingLine_;
/*
* Now fix up pendingLine_ to get ready for the next call to addCommit.
*/
//
First remove all columns that have empty postCommit--these terminated.
auto
newEnd =
std::remove_if
(
pendingLine_.
begin
(), pendingLine_.
end
(), &isColumnTerminating);
pendingLine_.
erase
(newEnd, pendingLine_.
end
());
//
Now copy all of the postCommits to preCommit.
for
(
auto
& column : pendingLine_)
{
column.
preCommit
= column.
postCommit
;
}
return
result;
}
}
//
namespace gitgraph
}
//
namespace core
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL