From a752ad141d9b96866910d4bd8b92bd53becd33ce Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 14 Jul 2025 10:22:04 +0800 Subject: [PATCH] code_review: PR #1568 Signed-off-by: leo --- src/Models/Commit.cs | 13 +++++++++++++ src/Resources/Locales/de_DE.axaml | 4 ---- src/Resources/Locales/es_ES.axaml | 4 ---- src/Resources/Locales/fr_FR.axaml | 4 ---- src/Resources/Locales/it_IT.axaml | 4 ---- src/Resources/Locales/ja_JP.axaml | 4 ---- src/Resources/Locales/pt_BR.axaml | 4 ---- src/Resources/Locales/ru_RU.axaml | 4 ---- src/Resources/Locales/ta_IN.axaml | 4 ---- src/Resources/Locales/uk_UA.axaml | 4 ---- src/Resources/Locales/zh_CN.axaml | 8 ++++---- src/Resources/Locales/zh_TW.axaml | 8 ++++---- src/ViewModels/Histories.cs | 15 +------------- src/ViewModels/InProgressContexts.cs | 29 ++++++---------------------- 14 files changed, 28 insertions(+), 81 deletions(-) diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index ac38c243..61438424 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -52,6 +52,19 @@ namespace SourceGit.Models public Thickness Margin { get; set; } = new(0); public IBrush Brush => CommitGraph.Pens[Color].Brush; + public string GetFriendlyName() + { + var branchDecorator = Decorators.Find(x => x.Type is DecoratorType.LocalBranchHead or DecoratorType.RemoteBranchHead); + if (branchDecorator != null) + return branchDecorator.Name; + + var tagDecorator = Decorators.Find(x => x.Type is DecoratorType.Tag); + if (tagDecorator != null) + return tagDecorator.Name; + + return SHA[..10]; + } + public void ParseDecorators(string data) { if (data.Length < 3) diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 5cc3c96c..4f7fd7c6 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -124,17 +124,13 @@ SHA Betreff Benutzerdefinierte Aktion - Interactives Rebase von ${0}$ auf diesen Commit Merge in ${0}$ hinein Merge ... Push ${0}$ zu ${1}$ - Rebase von ${0}$ auf diesen Commit - Reset ${0}$ auf diesen Commit Commit rückgängig machen Umformulieren Als Patch speichern... Squash in den Vorgänger - Squash Nachfolger Commits bis hier ÄNDERUNGEN geänderte Datei(en) Änderungen durchsuchen... diff --git a/src/Resources/Locales/es_ES.axaml b/src/Resources/Locales/es_ES.axaml index f145f8ad..4106c742 100644 --- a/src/Resources/Locales/es_ES.axaml +++ b/src/Resources/Locales/es_ES.axaml @@ -122,17 +122,13 @@ SHA Asunto Acción personalizada - Rebase Interactivo ${0}$ hasta Aquí Merge a ${0}$ Merge ... Push ${0}$ a ${1}$ - Rebase ${0}$ hasta Aquí - Reset ${0}$ hasta Aquí Revertir Commit Reescribir Guardar como Parche... Squash en Parent - Squash Commits Hijos hasta Aquí CAMBIOS archivo(s) modificado(s) Buscar Cambios... diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index ce2fd424..e5e443ea 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -103,16 +103,12 @@ Comparer avec le worktree SHA Action personnalisée - Rebase interactif de ${0}$ ici Fusionner dans ${0}$ Fusionner ... - Rebaser ${0}$ ici - Réinitialiser ${0}$ ici Annuler le commit Reformuler Enregistrer en tant que patch... Squash dans le parent - Squash les commits enfants ici CHANGEMENTS Rechercher les changements... FICHIERS diff --git a/src/Resources/Locales/it_IT.axaml b/src/Resources/Locales/it_IT.axaml index f6c375db..c83a8bdb 100644 --- a/src/Resources/Locales/it_IT.axaml +++ b/src/Resources/Locales/it_IT.axaml @@ -114,16 +114,12 @@ SHA Oggetto Azione Personalizzata - Riallinea Interattivamente ${0}$ fino a Qui Unisci a ${0}$ Unisci ... - Riallinea ${0}$ fino a Qui - Ripristina ${0}$ fino a Qui Annulla Commit Modifica Salva come Patch... Compatta nel Genitore - Compatta Commit Figli fino a Qui MODIFICHE Cerca Modifiche... FILE diff --git a/src/Resources/Locales/ja_JP.axaml b/src/Resources/Locales/ja_JP.axaml index eeb7362c..63e4736d 100644 --- a/src/Resources/Locales/ja_JP.axaml +++ b/src/Resources/Locales/ja_JP.axaml @@ -102,16 +102,12 @@ ワークツリーと比較 SHA カスタムアクション - ${0}$ ブランチをここにインタラクティブリベース ${0}$ にマージ マージ... - ${0}$ をここにリベース - ${0}$ ブランチをここにリセット コミットを戻す 書き直す パッチとして保存... 親にスカッシュ - 子コミットをここにスカッシュ 変更 変更を検索... ファイル diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index d60820f3..87a14a3a 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -93,14 +93,10 @@ Comparar com Worktree SHA Ação customizada - Rebase Interativo ${0}$ até Aqui - Rebase ${0}$ até Aqui - Resetar ${0}$ até Aqui Reverter Commit Modificar Mensagem Salvar como Patch... Mesclar ao Commit Pai - Mesclar commits filhos para este ALTERAÇÕES Buscar Alterações... ARQUIVOS diff --git a/src/Resources/Locales/ru_RU.axaml b/src/Resources/Locales/ru_RU.axaml index ec0b6466..568c07ef 100644 --- a/src/Resources/Locales/ru_RU.axaml +++ b/src/Resources/Locales/ru_RU.axaml @@ -127,17 +127,13 @@ SHA Субъект Пользовательское действие - Интерактивное перемещение (rebase -i) ${0}$ сюда Влить в ${0}$ Влить ... Выложить ${0}$ в ${1}$ - Переместить ${0}$ сюда - Сбросить ${0}$ сюда Отменить ревизию Изменить комментарий Сохранить как заплатки... Объединить с предыдущей ревизией - Объединить все следующие ревизии с этим ИЗМЕНЕНИЯ изменённый(х) файл(ов) Найти изменения.... diff --git a/src/Resources/Locales/ta_IN.axaml b/src/Resources/Locales/ta_IN.axaml index 0646b716..7604b3bd 100644 --- a/src/Resources/Locales/ta_IN.axaml +++ b/src/Resources/Locales/ta_IN.axaml @@ -102,16 +102,12 @@ பணிமரத்துடன் ஒப்பிடுக பாகொவ-வை தனிப்பயன் செயல் - இங்கே ${0}$ ஐ ஊடாடும் வகையில் மறுதளம் ${0}$ இதற்கு ஒன்றிணை ஒன்றிணை ... - இங்கே ${0}$ ஐ மறுதளம் - ${0}$ ஐ இங்கே மீட்டமை உறுதிமொழி திரும்பபெறு வேறுமொழி ஒட்டாக சேமி... பெற்றோர்களில் நொறுக்கு - நொறுக்கு குழந்தைகள் இங்கே சேர் மாற்றங்கள் மாற்றங்களைத் தேடு... கோப்புகள் diff --git a/src/Resources/Locales/uk_UA.axaml b/src/Resources/Locales/uk_UA.axaml index ca820926..b4b4ccbf 100644 --- a/src/Resources/Locales/uk_UA.axaml +++ b/src/Resources/Locales/uk_UA.axaml @@ -103,16 +103,12 @@ Порівняти з робочим деревом SHA Спеціальна дія - Інтерактивно перебазувати ${0}$ сюди Злиття в ${0}$ Злити ... - Перебазувати ${0}$ сюди - Скинути ${0}$ сюди Скасувати коміт Змінити повідомлення Зберегти як патч... Склеїти з батьківським комітом - Склеїти дочірні коміти сюди ЗМІНИ Пошук змін... ФАЙЛИ diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 454fbe6c..7f176709 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -127,17 +127,17 @@ 提交指纹 主题 自定义操作 - 交互式变基(rebase -i) ${0}$ 到此处 + 交互式变基(rebase -i) ${0}$ 到 ${1}$ 合并(merge)此提交至 ${0}$ 合并(merge)... 推送(push) ${0}$ 到 ${1}$ - 变基(rebase) ${0}$ 到此处 - 重置(reset) ${0}$ 到此处 + 变基(rebase) ${0}$ 到 ${1} + 重置(reset) ${0}$ 到 ${1} 回滚此提交 编辑提交信息 另存为补丁 ... 合并此提交到上一个提交 - 合并之后的提交到此处 + 合并之后的提交到 ${0}$ 变更对比 个文件发生变更 查找变更... diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 5fe88e5c..4eecc714 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -127,17 +127,17 @@ 提交編號 標題 自訂動作 - 互動式重定基底 (rebase -i) ${0}$ 到此處 + 互動式重定基底 (rebase -i) ${0}$ 至 ${1}$ 合併 (merge) 此提交到 ${0}$ 合併 (merge)... 推送(push) ${0}$ 至 ${1}$ - 重定基底 (rebase) ${0}$ 到此處 - 重設 (reset) ${0}$ 到此處 + 重定基底 (rebase) ${0}$ 至 ${1}$ + 重設 (reset) ${0}$ 至 ${1}$ 復原此提交 編輯提交訊息 另存為修補檔 (patch)... 合併此提交到上一個提交 - 合併之後的提交到此處 + 合併之後的提交至 ${0}$ 變更對比 個檔案已變更 搜尋變更... diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 4d119f98..7d9b9573 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -483,7 +483,7 @@ namespace SourceGit.ViewModels if (!_repo.IsBare) { - var target = GetFriendlyNameOfCommit(commit); + var target = commit.GetFriendlyName(); if (current.Head != commit.SHA) { @@ -873,19 +873,6 @@ namespace SourceGit.ViewModels return menu; } - private static string GetFriendlyNameOfCommit(Models.Commit commit) - { - var branchDecorator = commit.Decorators.Find(x => x.Type is Models.DecoratorType.LocalBranchHead or Models.DecoratorType.RemoteBranchHead); - if (branchDecorator != null) - return branchDecorator.Name; - - var tagDecorator = commit.Decorators.Find(x => x.Type is Models.DecoratorType.Tag); - if (tagDecorator != null) - return tagDecorator.Name; - - return commit.SHA[..10]; - } - private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current) { var submenu = new MenuItem(); diff --git a/src/ViewModels/InProgressContexts.cs b/src/ViewModels/InProgressContexts.cs index a1e7448c..5104130e 100644 --- a/src/ViewModels/InProgressContexts.cs +++ b/src/ViewModels/InProgressContexts.cs @@ -42,19 +42,6 @@ namespace SourceGit.ViewModels }.ExecAsync(); } - protected string GetFriendlyNameOfCommit(Models.Commit commit) - { - var branchDecorator = commit.Decorators.Find(x => x.Type == Models.DecoratorType.LocalBranchHead || x.Type == Models.DecoratorType.RemoteBranchHead); - if (branchDecorator != null) - return branchDecorator.Name; - - var tagDecorator = commit.Decorators.Find(x => x.Type == Models.DecoratorType.Tag); - if (tagDecorator != null) - return tagDecorator.Name; - - return commit.SHA.Substring(0, 10); - } - protected string _repo = string.Empty; protected string _cmd = string.Empty; } @@ -64,18 +51,18 @@ namespace SourceGit.ViewModels public Models.Commit Head { get; - private set; } public string HeadName { - get => GetFriendlyNameOfCommit(Head); + get; } public CherryPickInProgress(Repository repo) : base(repo.FullPath, "cherry-pick") { var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "CHERRY_PICK_HEAD")).Trim(); Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).GetResultAsync().Result ?? new Models.Commit() { SHA = headSHA }; + HeadName = Head.GetFriendlyName(); } } @@ -84,24 +71,21 @@ namespace SourceGit.ViewModels public string HeadName { get; - private set; } public string BaseName { - get => GetFriendlyNameOfCommit(Onto); + get; } public Models.Commit StoppedAt { get; - private set; } public Models.Commit Onto { get; - private set; } public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase") @@ -122,6 +106,7 @@ namespace SourceGit.ViewModels var ontoSHA = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "onto")).Trim(); Onto = new Commands.QuerySingleCommit(repo.FullPath, ontoSHA).GetResultAsync().Result ?? new Models.Commit() { SHA = ontoSHA }; + BaseName = Onto.GetFriendlyName(); } public override Task ContinueAsync() @@ -141,7 +126,6 @@ namespace SourceGit.ViewModels public Models.Commit Head { get; - private set; } public RevertInProgress(Repository repo) : base(repo.FullPath, "revert") @@ -156,18 +140,16 @@ namespace SourceGit.ViewModels public string Current { get; - private set; } public Models.Commit Source { get; - private set; } public string SourceName { - get => GetFriendlyNameOfCommit(Source); + get; } public MergeInProgress(Repository repo) : base(repo.FullPath, "merge") @@ -176,6 +158,7 @@ namespace SourceGit.ViewModels var sourceSHA = File.ReadAllText(Path.Combine(repo.GitDir, "MERGE_HEAD")).Trim(); Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).GetResultAsync().Result ?? new Models.Commit() { SHA = sourceSHA }; + SourceName = Source.GetFriendlyName(); } public override Task SkipAsync()