Skip to content

Commit 4297273

Browse files
authored
Merge branch 'CodeEditApp:main' into main
2 parents ff43881 + d1ee5ac commit 4297273

File tree

11 files changed

+185
-30
lines changed

11 files changed

+185
-30
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,15 @@
704704
"contributions": [
705705
"code"
706706
]
707+
},
708+
{
709+
"login": "knotbin",
710+
"name": "Roscoe Rubin-Rottenberg",
711+
"avatar_url": "https://avatars.githubusercontent.com/u/118622417?v=4",
712+
"profile": "http://knotbin.xyz",
713+
"contributions": [
714+
"code"
715+
]
707716
}
708717
],
709718
"contributorsPerLine": 7,

CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"originHash" : "3f6921a5ec30d1ecb6d6b205cf27a816c318246bb00f0ea367b997cc66527d32",
23
"pins" : [
34
{
45
"identity" : "anycodable",

CodeEdit/Features/Contributors/ContributorRowView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ struct ContributorRowView: View {
4444
.resizable()
4545
.frame(width: 32, height: 32)
4646
.clipShape(Circle())
47+
.help(contributor.name)
4748
} placeholder: {
4849
Image(systemName: "person.circle.fill")
4950
.resizable()
5051
.frame(width: 32, height: 32)
52+
.help(contributor.name)
5153
}
5254
}
5355

CodeEdit/Features/Git/Client/GitClient+CommitHistory.swift

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,34 @@ extension GitClient {
3131
dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss Z"
3232

3333
let output = try await run(
34-
"log --pretty=%h¦%H¦%s¦%aN¦%ae¦%cn¦%ce¦%aD¦ \(maxCountString) \(branchNameString) \(fileLocalPath)"
34+
"log --pretty=%h¦%H¦%s¦%aN¦%ae¦%cn¦%ce¦%aD¦%b¦%D¦ \(maxCountString) \(branchNameString) \(fileLocalPath)"
3535
.trimmingCharacters(in: .whitespacesAndNewlines)
3636
)
37-
38-
let remote = try? await run("ls-remote --get-url")
39-
let remoteURL: URL? = if let remote {
40-
URL(string: remote.trimmingCharacters(in: .whitespacesAndNewlines))
41-
} else {
42-
nil
43-
}
37+
let remote = try await run("ls-remote --get-url")
38+
let remoteURL = URL(string: remote.trimmingCharacters(in: .whitespacesAndNewlines))
4439

4540
return output
4641
.split(separator: "\n")
4742
.map { line -> GitCommit in
48-
let parameters = line.components(separatedBy: "¦")
43+
let parameters = String(line).components(separatedBy: "¦")
44+
let infoRef = parameters[safe: 9]
45+
var refs: [String] = []
46+
var tag = ""
47+
if let infoRef = infoRef {
48+
if infoRef.contains("tag:") {
49+
tag = infoRef.components(separatedBy: "tag:")[1].trimmingCharacters(in: .whitespaces)
50+
} else {
51+
refs = infoRef.split(separator: ",").compactMap {
52+
var element = String($0)
53+
if element.contains("origin/HEAD") { return nil }
54+
if element.contains("HEAD -> ") {
55+
element = element.replacingOccurrences(of: "HEAD -> ", with: "")
56+
}
57+
return element.trimmingCharacters(in: .whitespaces)
58+
}
59+
}
60+
}
61+
4962
return GitCommit(
5063
hash: parameters[safe: 0] ?? "",
5164
commitHash: parameters[safe: 1] ?? "",
@@ -54,6 +67,9 @@ extension GitClient {
5467
authorEmail: parameters[safe: 4] ?? "",
5568
committer: parameters[safe: 5] ?? "",
5669
committerEmail: parameters[safe: 6] ?? "",
70+
body: parameters[safe: 8] ?? "",
71+
refs: refs,
72+
tag: tag,
5773
remoteURL: remoteURL,
5874
date: dateFormatter.date(from: parameters[safe: 7] ?? "") ?? Date()
5975
)

CodeEdit/Features/Git/Client/Models/GitCommit.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ struct GitCommit: Equatable, Hashable, Identifiable {
1717
let authorEmail: String
1818
let committer: String
1919
let committerEmail: String
20+
let body: String
21+
let refs: [String]
22+
let tag: String
2023
let remoteURL: URL?
2124
let date: Date
2225

CodeEdit/Features/InspectorArea/HistoryInspector/HistoryInspectorItemView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct HistoryInspectorItemView: View {
2525
}
2626

2727
var body: some View {
28-
CommitListItemView(commit: commit)
28+
CommitListItemView(commit: commit, showRef: false)
2929
.popover(isPresented: showPopup, arrowEdge: .leading) {
3030
HistoryPopoverView(commit: commit)
3131
}

CodeEdit/Features/NavigatorArea/SourceControlNavigator/History/Views/CommitDetailsHeaderView.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ struct CommitDetailsHeaderView: View {
7070
.resizable()
7171
.clipShape(Circle())
7272
.frame(width: 32, height: 32)
73+
.help(commit.author)
7374
} else if phase.error != nil {
7475
defaultAvatar
76+
.help(commit.author)
7577
} else {
7678
defaultAvatar
79+
.help(commit.author)
7780
}
7881
}
7982

@@ -98,8 +101,20 @@ struct CommitDetailsHeaderView: View {
98101
)
99102
.padding(.horizontal, 2.5)
100103
}
104+
.padding(.horizontal, 16)
105+
106+
Divider()
107+
101108
Text(commitDetails())
109+
.fontWeight(.bold)
110+
.padding(.horizontal, 16)
102111
.frame(alignment: .leading)
112+
113+
if !commit.body.isEmpty {
114+
Text(commit.body)
115+
.padding(.horizontal, 16)
116+
.frame(alignment: .leading)
117+
}
103118
}
104119
}
105120
}

CodeEdit/Features/NavigatorArea/SourceControlNavigator/History/Views/CommitDetailsView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ struct CommitDetailsView: View {
4141

4242
if let commit = commit {
4343
CommitDetailsHeaderView(commit: commit)
44-
.padding(.horizontal, 16)
4544
.padding(.vertical, 16)
4645
Divider()
4746

CodeEdit/Features/NavigatorArea/SourceControlNavigator/History/Views/CommitListItemView.swift

Lines changed: 110 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,126 @@ import SwiftUI
1010
struct CommitListItemView: View {
1111

1212
var commit: GitCommit
13+
var showRef: Bool
14+
var width: CGFloat
15+
16+
private var defaultAvatar: some View {
17+
Image(systemName: "person.crop.circle.fill")
18+
.symbolRenderingMode(.hierarchical)
19+
.resizable()
20+
.foregroundColor(avatarColor)
21+
.frame(width: 32, height: 32)
22+
}
23+
24+
private func generateAvatarHash() -> String {
25+
let hash = commit.authorEmail.md5(trim: true, caseSensitive: false)
26+
return "\(hash)?d=404&s=64" // send 404 if no image available, image size 64x64 (32x32 @2x)
27+
}
28+
29+
private var avatarColor: Color {
30+
let hash = generateAvatarHash().hash
31+
switch hash % 12 {
32+
case 0: return .red
33+
case 1: return .orange
34+
case 2: return .yellow
35+
case 3: return .green
36+
case 4: return .mint
37+
case 5: return .teal
38+
case 6: return .cyan
39+
case 7: return .blue
40+
case 8: return .indigo
41+
case 9: return .purple
42+
case 10: return .brown
43+
case 11: return .pink
44+
default: return .teal
45+
}
46+
}
1347

1448
@Environment(\.openURL)
1549
private var openCommit
1650

17-
init(commit: GitCommit) {
51+
init(commit: GitCommit, showRef: Bool) {
52+
self.commit = commit
53+
self.showRef = showRef
54+
self.width = 0
55+
}
56+
57+
init(commit: GitCommit, showRef: Bool, width: CGFloat) {
1858
self.commit = commit
59+
self.showRef = showRef
60+
self.width = width
1961
}
2062

2163
var body: some View {
2264
HStack(alignment: .top) {
65+
if width > 360 {
66+
AsyncImage(url: URL(string: "https://www.gravatar.com/avatar/\(generateAvatarHash())")) { phase in
67+
if let image = phase.image {
68+
image
69+
.resizable()
70+
.clipShape(Circle())
71+
.frame(width: 32, height: 32)
72+
.help(commit.author)
73+
} else if phase.error != nil {
74+
defaultAvatar
75+
.help(commit.author)
76+
} else {
77+
defaultAvatar
78+
.help(commit.author)
79+
}
80+
}
81+
}
2382
VStack(alignment: .leading, spacing: 0) {
24-
Text(commit.author)
25-
.fontWeight(.bold)
26-
.font(.system(size: 11))
27-
Text(commit.message)
83+
HStack {
84+
Text(commit.author)
85+
.fontWeight(.bold)
86+
.font(.system(size: 11))
87+
if showRef {
88+
if !commit.refs.isEmpty {
89+
HStack {
90+
ForEach(commit.refs, id: \.self) { ref in
91+
HStack {
92+
Image.branch
93+
.imageScale(.small)
94+
.foregroundColor(.primary)
95+
.help(ref)
96+
Text(ref)
97+
.font(.system(size: 10, design: .monospaced))
98+
}
99+
.frame(height: 13)
100+
.background(
101+
RoundedRectangle(cornerRadius: 3)
102+
.padding(.vertical, -1)
103+
.padding(.horizontal, -2.5)
104+
.foregroundColor(Color(nsColor: .quaternaryLabelColor))
105+
)
106+
.padding(.trailing, 2.5)
107+
}
108+
}
109+
}
110+
111+
if !commit.tag.isEmpty {
112+
HStack {
113+
Image.breakpoint
114+
.imageScale(.small)
115+
.foregroundColor(.primary)
116+
.help(commit.tag)
117+
Text(commit.tag)
118+
.font(.system(size: 10, design: .monospaced))
119+
}
120+
.frame(height: 13)
121+
.background(
122+
RoundedRectangle(cornerRadius: 3)
123+
.padding(.vertical, -1)
124+
.padding(.horizontal, -2.5)
125+
.foregroundColor(Color(nsColor: .selectedContentBackgroundColor))
126+
)
127+
.padding(.trailing, 2.5)
128+
}
129+
}
130+
}
131+
132+
Text("\(commit.message) \(commit.body)")
28133
.font(.system(size: 11))
29134
.lineLimit(2)
30135
}

CodeEdit/Features/NavigatorArea/SourceControlNavigator/History/Views/SourceControlNavigatorHistoryView.swift

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct SourceControlNavigatorHistoryView: View {
2121
@State var commitHistory: [GitCommit] = []
2222

2323
@State var selection: GitCommit?
24+
@State private var width: CGFloat = CGFloat.zero
2425

2526
func updateCommitHistory() async {
2627
do {
@@ -55,17 +56,25 @@ struct SourceControlNavigatorHistoryView: View {
5556
if commitHistory.isEmpty {
5657
CEContentUnavailableView("No History")
5758
} else {
58-
ZStack {
59-
List(selection: $selection) {
60-
ForEach(commitHistory) { commit in
61-
CommitListItemView(commit: commit)
62-
.tag(commit)
63-
.listRowSeparator(.hidden)
59+
GeometryReader { geometry in
60+
ZStack {
61+
List(selection: $selection) {
62+
ForEach(commitHistory) { commit in
63+
CommitListItemView(commit: commit, showRef: true, width: width)
64+
.tag(commit)
65+
.listRowSeparator(.hidden)
66+
}
6467
}
68+
.opacity(selection == nil ? 1 : 0)
69+
if selection != nil {
70+
CommitDetailsView(commit: $selection)
71+
}
72+
}
73+
.onAppear {
74+
self.width = geometry.size.width
6575
}
66-
.opacity(selection == nil ? 1 : 0)
67-
if selection != nil {
68-
CommitDetailsView(commit: $selection)
76+
.onChange(of: geometry.size.width) { newWidth in
77+
self.width = newWidth
6978
}
7079
}
7180
}
@@ -89,11 +98,6 @@ struct SourceControlNavigatorHistoryView: View {
8998
}
9099
}
91100
}
92-
.onReceive(sourceControlManager.$currentBranch) { _ in
93-
Task {
94-
await updateCommitHistory()
95-
}
96-
}
97101
.task {
98102
await updateCommitHistory()
99103
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ For issues we want to focus on that are most relevant at any given time, please
181181
<td align="center" valign="top" width="14.28%"><a href="https://github.com/phlpsong"><img src="https://avatars.githubusercontent.com/u/103433299?v=4?s=100" width="100px;" alt="phlpsong"/><br /><sub><b>phlpsong</b></sub></a><br /><a href="https://github.com/CodeEditApp/CodeEdit/issues?q=author%3Aphlpsong" title="Bug reports">🐛</a></td>
182182
<td align="center" valign="top" width="14.28%"><a href="http://ahnafmahmud.com"><img src="https://avatars.githubusercontent.com/u/44692189?v=4?s=100" width="100px;" alt="Ahnaf Mahmud"/><br /><sub><b>Ahnaf Mahmud</b></sub></a><br /><a href="https://github.com/CodeEditApp/CodeEdit/commits?author=infinitepower18" title="Code">💻</a></td>
183183
<td align="center" valign="top" width="14.28%"><a href="https://github.com/DanKlaver15"><img src="https://avatars.githubusercontent.com/u/9391497?v=4?s=100" width="100px;" alt="Dan K"/><br /><sub><b>Dan K</b></sub></a><br /><a href="https://github.com/CodeEditApp/CodeEdit/commits?author=DanKlaver15" title="Code">💻</a></td>
184+
<td align="center" valign="top" width="14.28%"><a href="http://knotbin.xyz"><img src="https://avatars.githubusercontent.com/u/118622417?v=4?s=100" width="100px;" alt="Roscoe Rubin-Rottenberg"/><br /><sub><b>Roscoe Rubin-Rottenberg</b></sub></a><br /><a href="https://github.com/CodeEditApp/CodeEdit/commits?author=knotbin" title="Code">💻</a></td>
184185
</tr>
185186
</tbody>
186187
</table>

0 commit comments

Comments
 (0)