Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e2bf9cc

Browse files
code_style: move some code from Views.Histories to ViewModels.Histories
Signed-off-by: leo <longshuang@msn.cn>
1 parent 5ff3450 commit e2bf9cc

File tree

3 files changed

+146
-125
lines changed

3 files changed

+146
-125
lines changed

‎src/ViewModels/Histories.cs‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,95 @@ public void CheckoutBranchByCommit(Models.Commit commit)
285285
}
286286
}
287287

288+
public async Task CherryPickAsync(Models.Commit commit)
289+
{
290+
if (_repo.CanCreatePopup())
291+
{
292+
if (commit.Parents.Count <= 1)
293+
{
294+
_repo.ShowPopup(new CherryPick(_repo, [commit]));
295+
}
296+
else
297+
{
298+
var parents = new List<Models.Commit>();
299+
foreach (var sha in commit.Parents)
300+
{
301+
var parent = _commits.Find(x => x.SHA == sha);
302+
if (parent == null)
303+
parent = await new Commands.QuerySingleCommit(_repo.FullPath, sha).GetResultAsync();
304+
305+
if (parent != null)
306+
parents.Add(parent);
307+
}
308+
309+
_repo.ShowPopup(new CherryPick(_repo, commit, parents));
310+
}
311+
}
312+
}
313+
314+
public async Task RewordHeadAsync(Models.Commit head)
315+
{
316+
if (_repo.CanCreatePopup())
317+
{
318+
var message = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).GetResultAsync();
319+
_repo.ShowPopup(new Reword(_repo, head, message));
320+
}
321+
}
322+
323+
public async Task SquashHeadAsync(Models.Commit head)
324+
{
325+
if (head.Parents.Count == 1)
326+
{
327+
var message = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).GetResultAsync();
328+
var parent = _commits.Find(x => x.SHA.Equals(head.Parents[0]));
329+
if (parent != null && _repo.CanCreatePopup())
330+
_repo.ShowPopup(new Squash(_repo, parent, message));
331+
}
332+
}
333+
334+
public async Task InteractiveRebaseAsync(Models.Commit commit, Models.InteractiveRebaseAction act)
335+
{
336+
var prefill = new InteractiveRebasePrefill(commit.SHA, act);
337+
var start = act switch
338+
{
339+
Models.InteractiveRebaseAction.Squash or Models.InteractiveRebaseAction.Fixup => $"{commit.SHA}~~",
340+
_ => $"{commit.SHA}~",
341+
};
342+
343+
var on = await new Commands.QuerySingleCommit(_repo.FullPath, start).GetResultAsync();
344+
if (on == null)
345+
App.RaiseException(_repo.FullPath, $"Can not squash current commit into parent!");
346+
else
347+
await App.ShowDialog(new InteractiveRebase(_repo, on, prefill));
348+
}
349+
350+
public async Task CopyCommitFullMessageAsync(Models.Commit commit)
351+
{
352+
var message = await new Commands.QueryCommitFullMessage(_repo.FullPath, commit.SHA).GetResultAsync();
353+
await App.CopyTextAsync(message);
354+
}
355+
356+
public async Task<Models.Commit> CompareWithHeadAsync(Models.Commit commit)
357+
{
358+
var head = _commits.Find(x => x.IsCurrentHead);
359+
if (head == null)
360+
{
361+
_repo.SelectedSearchedCommit = null;
362+
head = await new Commands.QuerySingleCommit(_repo.FullPath, "HEAD").GetResultAsync();
363+
if (head != null)
364+
DetailContext = new RevisionCompare(_repo.FullPath, commit, head);
365+
366+
return null;
367+
}
368+
369+
return head;
370+
}
371+
372+
public void CompareWithWorktree(Models.Commit commit)
373+
{
374+
DetailContext = new RevisionCompare(_repo.FullPath, commit, null);
375+
}
376+
288377
private void NavigateTo(Models.Commit commit)
289378
{
290379
AutoSelectedCommit = commit;

‎src/ViewModels/Repository.cs‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,8 +1623,33 @@ public void ClearStashes()
16231623
ShowPopup(new ClearStashes(this));
16241624
}
16251625

1626-
public async Task<bool> SaveCommitAsPatchAsync(Models.Commit commit, string saveTo)
1626+
public async Task<bool> SaveCommitAsPatchAsync(Models.Commit commit, string folder,intindex=0)
16271627
{
1628+
var ignore_chars = new HashSet<char> { '/', '\\', ':', ',', '*', '?', '\"', '<', '>', '|', '`', '$', '^', '%', '[', ']', '+', '-' };
1629+
var builder = new StringBuilder();
1630+
builder.Append(index.ToString("D4"));
1631+
builder.Append('-');
1632+
1633+
var chars = commit.Subject.ToCharArray();
1634+
var len = 0;
1635+
foreach (var c in chars)
1636+
{
1637+
if (!ignore_chars.Contains(c))
1638+
{
1639+
if (c == ' ' || c == '\t')
1640+
builder.Append('-');
1641+
else
1642+
builder.Append(c);
1643+
1644+
len++;
1645+
1646+
if (len >= 48)
1647+
break;
1648+
}
1649+
}
1650+
builder.Append(".patch");
1651+
1652+
var saveTo = Path.Combine(folder, builder.ToString());
16281653
var log = CreateLog("Save Commit as Patch");
16291654
var succ = await new Commands.FormatPatch(_fullpath, commit.SHA, saveTo).Use(log).ExecAsync();
16301655
log.Complete();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /