FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gitlet/gitlet/gitlet/CommitStore.java at master · xUser5000/gitlet · GitHub
xUser5000
/
gitlet
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
6
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
gitlet
/
gitlet
/
gitlet
/
CommitStore.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (45 loc) · 1.52 KB
Breadcrumbs
gitlet
/
gitlet
/
gitlet
/
CommitStore.java
Copy path
File metadata and controls
54 lines (45 loc) · 1.52 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
package
gitlet
;
import
java
.
io
.
File
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
import
java
.
util
.
Objects
;
import
java
.
util
.
stream
.
Collectors
;
import
java
.
util
.
stream
.
Stream
;
import
static
gitlet
.
Utils
.*;
public
class
CommitStore
{
private
final
File
COMMITS_DIR
;
public
CommitStore
(
File
commitDirectory
) {
COMMITS_DIR
=
commitDirectory
;
if
(!
COMMITS_DIR
.
exists
()) {
COMMITS_DIR
.
mkdir
();
}
}
public
Commit
getCommitByHash
(
String
commitId
) {
if
(
commitId
==
null
)
return
null
;
File
commitFile
=
join
(
COMMITS_DIR
,
commitId
);
if
(
commitFile
.
exists
()) {
return
readObject
(
commitFile
,
Commit
.
class
);
}
return
allCommitsStream
()
.
filter
(
commit
->
commit
.
getHash
().
startsWith
(
commitId
))
.
findFirst
()
.
orElse
(
null
);
}
public
List
<
Commit
>
getCommitsByMessage
(
String
message
) {
return
allCommitsStream
()
.
filter
(
commit
->
commit
.
getMessage
().
equals
(
message
))
.
collect
(
Collectors
.
toList
());
}
public
void
saveCommit
(
Commit
commit
) {
File
commitFile
=
join
(
COMMITS_DIR
,
commit
.
getHash
());
writeObject
(
commitFile
,
commit
);
}
public
List
<
Commit
>
allCommits
() {
return
allCommitsStream
().
collect
(
Collectors
.
toList
());
}
public
Stream
<
Commit
>
allCommitsStream
() {
return
Objects
.
requireNonNull
(
plainFilenamesIn
(
COMMITS_DIR
))
.
stream
()
.
map
(
this
::
getCommitByHash
);
}
}
Back
|
FazBrowse Home
|
New Git URL