mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-09-16 09:16:26 +02:00
Merge pull request #2088 from jesseduffield/merge-conflict-refactor
This commit is contained in:
@@ -30,13 +30,13 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## List Panel Navigation
|
## List Panel Navigation
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>H</kbd>: scroll left
|
|
||||||
<kbd>L</kbd>: scroll right
|
|
||||||
<kbd>,</kbd>: previous page
|
<kbd>,</kbd>: previous page
|
||||||
<kbd>.</kbd>: next page
|
<kbd>.</kbd>: next page
|
||||||
<kbd><</kbd>: scroll to top
|
<kbd><</kbd>: scroll to top
|
||||||
<kbd>/</kbd>: start search
|
<kbd>/</kbd>: start search
|
||||||
<kbd>></kbd>: scroll to bottom
|
<kbd>></kbd>: scroll to bottom
|
||||||
|
<kbd>H</kbd>: scroll left
|
||||||
|
<kbd>L</kbd>: scroll right
|
||||||
<kbd>]</kbd>: next tab
|
<kbd>]</kbd>: next tab
|
||||||
<kbd>[</kbd>: previous tab
|
<kbd>[</kbd>: previous tab
|
||||||
</pre>
|
</pre>
|
||||||
@@ -140,24 +140,24 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## Main Panel (Merging)
|
## Main Panel (Merging)
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>esc</kbd>: return to files panel
|
<kbd>e</kbd>: edit file
|
||||||
<kbd>M</kbd>: open external merge tool (git mergetool)
|
<kbd>o</kbd>: open file
|
||||||
<kbd>space</kbd>: pick hunk
|
|
||||||
<kbd>b</kbd>: pick all hunks
|
|
||||||
<kbd>◄</kbd>: select previous conflict
|
<kbd>◄</kbd>: select previous conflict
|
||||||
<kbd>►</kbd>: select next conflict
|
<kbd>►</kbd>: select next conflict
|
||||||
<kbd>▲</kbd>: select previous hunk
|
<kbd>▲</kbd>: select previous hunk
|
||||||
<kbd>▼</kbd>: select next hunk
|
<kbd>▼</kbd>: select next hunk
|
||||||
<kbd>e</kbd>: edit file
|
|
||||||
<kbd>o</kbd>: open file
|
|
||||||
<kbd>z</kbd>: undo
|
<kbd>z</kbd>: undo
|
||||||
|
<kbd>M</kbd>: open external merge tool (git mergetool)
|
||||||
|
<kbd>space</kbd>: pick hunk
|
||||||
|
<kbd>b</kbd>: pick all hunks
|
||||||
|
<kbd>esc</kbd>: return to files panel
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Main Panel (Normal)
|
## Main Panel (Normal)
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>mouse wheel down</kbd>: scroll down (fn+up)
|
<kbd>mouse wheel ▼</kbd>: scroll down (fn+up)
|
||||||
<kbd>mouse wheel up</kbd>: scroll up (fn+down)
|
<kbd>mouse wheel ▲</kbd>: scroll up (fn+down)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Main Panel (Patch Building)
|
## Main Panel (Patch Building)
|
||||||
|
@@ -30,13 +30,13 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## 一覧パネルの操作
|
## 一覧パネルの操作
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>H</kbd>: 左スクロール
|
|
||||||
<kbd>L</kbd>: 右スクロール
|
|
||||||
<kbd>,</kbd>: 前のページ
|
<kbd>,</kbd>: 前のページ
|
||||||
<kbd>.</kbd>: 次のページ
|
<kbd>.</kbd>: 次のページ
|
||||||
<kbd><</kbd>: 最上部までスクロール
|
<kbd><</kbd>: 最上部までスクロール
|
||||||
<kbd>/</kbd>: 検索を開始
|
<kbd>/</kbd>: 検索を開始
|
||||||
<kbd>></kbd>: 最下部までスクロール
|
<kbd>></kbd>: 最下部までスクロール
|
||||||
|
<kbd>H</kbd>: 左スクロール
|
||||||
|
<kbd>L</kbd>: 右スクロール
|
||||||
<kbd>]</kbd>: 次のタブ
|
<kbd>]</kbd>: 次のタブ
|
||||||
<kbd>[</kbd>: 前のタブ
|
<kbd>[</kbd>: 前のタブ
|
||||||
</pre>
|
</pre>
|
||||||
@@ -199,24 +199,24 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## メインパネル (Merging)
|
## メインパネル (Merging)
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>esc</kbd>: ファイル一覧に戻る
|
<kbd>e</kbd>: ファイルを編集
|
||||||
<kbd>M</kbd>: git mergetoolを開く
|
<kbd>o</kbd>: ファイルを開く
|
||||||
<kbd>space</kbd>: pick hunk
|
|
||||||
<kbd>b</kbd>: pick all hunks
|
|
||||||
<kbd>◄</kbd>: 前のコンフリクトを選択
|
<kbd>◄</kbd>: 前のコンフリクトを選択
|
||||||
<kbd>►</kbd>: 次のコンフリクトを選択
|
<kbd>►</kbd>: 次のコンフリクトを選択
|
||||||
<kbd>▲</kbd>: 前のhunkを選択
|
<kbd>▲</kbd>: 前のhunkを選択
|
||||||
<kbd>▼</kbd>: 次のhunkを選択
|
<kbd>▼</kbd>: 次のhunkを選択
|
||||||
<kbd>e</kbd>: ファイルを編集
|
|
||||||
<kbd>o</kbd>: ファイルを開く
|
|
||||||
<kbd>z</kbd>: アンドゥ
|
<kbd>z</kbd>: アンドゥ
|
||||||
|
<kbd>M</kbd>: git mergetoolを開く
|
||||||
|
<kbd>space</kbd>: pick hunk
|
||||||
|
<kbd>b</kbd>: pick all hunks
|
||||||
|
<kbd>esc</kbd>: ファイル一覧に戻る
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## メインパネル (Normal)
|
## メインパネル (Normal)
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>mouse wheel down</kbd>: 下にスクロール (fn+up)
|
<kbd>mouse wheel ▼</kbd>: 下にスクロール (fn+up)
|
||||||
<kbd>mouse wheel up</kbd>: 上にスクロール (fn+down)
|
<kbd>mouse wheel ▲</kbd>: 上にスクロール (fn+down)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## メインパネル (Patch Building)
|
## メインパネル (Patch Building)
|
||||||
|
@@ -30,13 +30,13 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## List Panel Navigation
|
## List Panel Navigation
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>H</kbd>: 우 스크롤
|
|
||||||
<kbd>L</kbd>: 좌 스크롤
|
|
||||||
<kbd>,</kbd>: 이전 페이지
|
<kbd>,</kbd>: 이전 페이지
|
||||||
<kbd>.</kbd>: 다음 페이지
|
<kbd>.</kbd>: 다음 페이지
|
||||||
<kbd><</kbd>: 맨 위로 스크롤
|
<kbd><</kbd>: 맨 위로 스크롤
|
||||||
<kbd>/</kbd>: 검색 시작
|
<kbd>/</kbd>: 검색 시작
|
||||||
<kbd>></kbd>: 맨 아래로 스크롤
|
<kbd>></kbd>: 맨 아래로 스크롤
|
||||||
|
<kbd>H</kbd>: 우 스크롤
|
||||||
|
<kbd>L</kbd>: 좌 스크롤
|
||||||
<kbd>]</kbd>: 이전 탭
|
<kbd>]</kbd>: 이전 탭
|
||||||
<kbd>[</kbd>: 다음 탭
|
<kbd>[</kbd>: 다음 탭
|
||||||
</pre>
|
</pre>
|
||||||
@@ -84,24 +84,24 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## 메인 패널 (Merging)
|
## 메인 패널 (Merging)
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>esc</kbd>: 파일 목록으로 돌아가기
|
<kbd>e</kbd>: 파일 편집
|
||||||
<kbd>M</kbd>: git mergetool를 열기
|
<kbd>o</kbd>: 파일 닫기
|
||||||
<kbd>space</kbd>: pick hunk
|
|
||||||
<kbd>b</kbd>: pick all hunks
|
|
||||||
<kbd>◄</kbd>: 이전 충돌을 선택
|
<kbd>◄</kbd>: 이전 충돌을 선택
|
||||||
<kbd>►</kbd>: 다음 충돌을 선택
|
<kbd>►</kbd>: 다음 충돌을 선택
|
||||||
<kbd>▲</kbd>: 이전 hunk를 선택
|
<kbd>▲</kbd>: 이전 hunk를 선택
|
||||||
<kbd>▼</kbd>: 다음 hunk를 선택
|
<kbd>▼</kbd>: 다음 hunk를 선택
|
||||||
<kbd>e</kbd>: 파일 편집
|
|
||||||
<kbd>o</kbd>: 파일 닫기
|
|
||||||
<kbd>z</kbd>: 되돌리기
|
<kbd>z</kbd>: 되돌리기
|
||||||
|
<kbd>M</kbd>: git mergetool를 열기
|
||||||
|
<kbd>space</kbd>: pick hunk
|
||||||
|
<kbd>b</kbd>: pick all hunks
|
||||||
|
<kbd>esc</kbd>: 파일 목록으로 돌아가기
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## 메인 패널 (Normal)
|
## 메인 패널 (Normal)
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>mouse wheel down</kbd>: 아래로 스크롤 (fn+up)
|
<kbd>mouse wheel ▼</kbd>: 아래로 스크롤 (fn+up)
|
||||||
<kbd>mouse wheel up</kbd>: 위로 스크롤 (fn+down)
|
<kbd>mouse wheel ▲</kbd>: 위로 스크롤 (fn+down)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## 메인 패널 (Patch Building)
|
## 메인 패널 (Patch Building)
|
||||||
|
@@ -30,13 +30,13 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## Lijstpaneel Navigatie
|
## Lijstpaneel Navigatie
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>H</kbd>: scroll left
|
|
||||||
<kbd>L</kbd>: scroll right
|
|
||||||
<kbd>,</kbd>: vorige pagina
|
<kbd>,</kbd>: vorige pagina
|
||||||
<kbd>.</kbd>: volgende pagina
|
<kbd>.</kbd>: volgende pagina
|
||||||
<kbd><</kbd>: scroll naar boven
|
<kbd><</kbd>: scroll naar boven
|
||||||
<kbd>/</kbd>: start met zoeken
|
<kbd>/</kbd>: start met zoeken
|
||||||
<kbd>></kbd>: scroll naar beneden
|
<kbd>></kbd>: scroll naar beneden
|
||||||
|
<kbd>H</kbd>: scroll left
|
||||||
|
<kbd>L</kbd>: scroll right
|
||||||
<kbd>]</kbd>: volgende tabblad
|
<kbd>]</kbd>: volgende tabblad
|
||||||
<kbd>[</kbd>: vorige tabblad
|
<kbd>[</kbd>: vorige tabblad
|
||||||
</pre>
|
</pre>
|
||||||
@@ -140,24 +140,24 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## Mergen
|
## Mergen
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>esc</kbd>: ga terug naar het bestanden paneel
|
<kbd>e</kbd>: verander bestand
|
||||||
<kbd>M</kbd>: open external merge tool (git mergetool)
|
<kbd>o</kbd>: open bestand
|
||||||
<kbd>space</kbd>: kies hunk
|
|
||||||
<kbd>b</kbd>: kies bijde hunks
|
|
||||||
<kbd>◄</kbd>: selecteer voorgaand conflict
|
<kbd>◄</kbd>: selecteer voorgaand conflict
|
||||||
<kbd>►</kbd>: selecteer volgende conflict
|
<kbd>►</kbd>: selecteer volgende conflict
|
||||||
<kbd>▲</kbd>: selecteer bovenste hunk
|
<kbd>▲</kbd>: selecteer bovenste hunk
|
||||||
<kbd>▼</kbd>: selecteer onderste hunk
|
<kbd>▼</kbd>: selecteer onderste hunk
|
||||||
<kbd>e</kbd>: verander bestand
|
|
||||||
<kbd>o</kbd>: open bestand
|
|
||||||
<kbd>z</kbd>: ongedaan maken
|
<kbd>z</kbd>: ongedaan maken
|
||||||
|
<kbd>M</kbd>: open external merge tool (git mergetool)
|
||||||
|
<kbd>space</kbd>: kies hunk
|
||||||
|
<kbd>b</kbd>: kies bijde hunks
|
||||||
|
<kbd>esc</kbd>: ga terug naar het bestanden paneel
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Normaal
|
## Normaal
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>mouse wheel down</kbd>: scroll omlaag (fn+up)
|
<kbd>mouse wheel ▼</kbd>: scroll omlaag (fn+up)
|
||||||
<kbd>mouse wheel up</kbd>: scroll omhoog (fn+down)
|
<kbd>mouse wheel ▲</kbd>: scroll omhoog (fn+down)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Patch Bouwen
|
## Patch Bouwen
|
||||||
|
@@ -30,13 +30,13 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## List Panel Navigation
|
## List Panel Navigation
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>H</kbd>: scroll left
|
|
||||||
<kbd>L</kbd>: scroll right
|
|
||||||
<kbd>,</kbd>: previous page
|
<kbd>,</kbd>: previous page
|
||||||
<kbd>.</kbd>: next page
|
<kbd>.</kbd>: next page
|
||||||
<kbd><</kbd>: scroll to top
|
<kbd><</kbd>: scroll to top
|
||||||
<kbd>/</kbd>: start search
|
<kbd>/</kbd>: start search
|
||||||
<kbd>></kbd>: scroll to bottom
|
<kbd>></kbd>: scroll to bottom
|
||||||
|
<kbd>H</kbd>: scroll left
|
||||||
|
<kbd>L</kbd>: scroll right
|
||||||
<kbd>]</kbd>: next tab
|
<kbd>]</kbd>: next tab
|
||||||
<kbd>[</kbd>: previous tab
|
<kbd>[</kbd>: previous tab
|
||||||
</pre>
|
</pre>
|
||||||
@@ -211,17 +211,17 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## Scalanie
|
## Scalanie
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>esc</kbd>: wróć do panelu plików
|
<kbd>e</kbd>: edytuj plik
|
||||||
<kbd>M</kbd>: open external merge tool (git mergetool)
|
<kbd>o</kbd>: otwórz plik
|
||||||
<kbd>space</kbd>: wybierz kawałek
|
|
||||||
<kbd>b</kbd>: wybierz wszystkie kawałki
|
|
||||||
<kbd>◄</kbd>: poprzedni konflikt
|
<kbd>◄</kbd>: poprzedni konflikt
|
||||||
<kbd>►</kbd>: następny konflikt
|
<kbd>►</kbd>: następny konflikt
|
||||||
<kbd>▲</kbd>: wybierz poprzedni kawałek
|
<kbd>▲</kbd>: wybierz poprzedni kawałek
|
||||||
<kbd>▼</kbd>: wybierz następny kawałek
|
<kbd>▼</kbd>: wybierz następny kawałek
|
||||||
<kbd>e</kbd>: edytuj plik
|
|
||||||
<kbd>o</kbd>: otwórz plik
|
|
||||||
<kbd>z</kbd>: cofnij
|
<kbd>z</kbd>: cofnij
|
||||||
|
<kbd>M</kbd>: open external merge tool (git mergetool)
|
||||||
|
<kbd>space</kbd>: wybierz kawałek
|
||||||
|
<kbd>b</kbd>: wybierz wszystkie kawałki
|
||||||
|
<kbd>esc</kbd>: wróć do panelu plików
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Schowek
|
## Schowek
|
||||||
@@ -286,6 +286,6 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## Zwykłe
|
## Zwykłe
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>mouse wheel down</kbd>: przewiń w dół (fn+up)
|
<kbd>mouse wheel ▼</kbd>: przewiń w dół (fn+up)
|
||||||
<kbd>mouse wheel up</kbd>: przewiń w górę (fn+down)
|
<kbd>mouse wheel ▲</kbd>: przewiń w górę (fn+down)
|
||||||
</pre>
|
</pre>
|
||||||
|
@@ -30,13 +30,13 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## 列表面板导航
|
## 列表面板导航
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>H</kbd>: 向左滚动
|
|
||||||
<kbd>L</kbd>: 向右滚动
|
|
||||||
<kbd>,</kbd>: 上一页
|
<kbd>,</kbd>: 上一页
|
||||||
<kbd>.</kbd>: 下一页
|
<kbd>.</kbd>: 下一页
|
||||||
<kbd><</kbd>: 滚动到顶部
|
<kbd><</kbd>: 滚动到顶部
|
||||||
<kbd>/</kbd>: 开始搜索
|
<kbd>/</kbd>: 开始搜索
|
||||||
<kbd>></kbd>: 滚动到底部
|
<kbd>></kbd>: 滚动到底部
|
||||||
|
<kbd>H</kbd>: 向左滚动
|
||||||
|
<kbd>L</kbd>: 向右滚动
|
||||||
<kbd>]</kbd>: 下一个标签
|
<kbd>]</kbd>: 下一个标签
|
||||||
<kbd>[</kbd>: 上一个标签
|
<kbd>[</kbd>: 上一个标签
|
||||||
</pre>
|
</pre>
|
||||||
@@ -209,17 +209,17 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## 正在合并
|
## 正在合并
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>esc</kbd>: 返回文件面板
|
<kbd>e</kbd>: 编辑文件
|
||||||
<kbd>M</kbd>: 打开外部合并工具 (git mergetool)
|
<kbd>o</kbd>: 打开文件
|
||||||
<kbd>space</kbd>: 选中区块
|
|
||||||
<kbd>b</kbd>: 选中所有区块
|
|
||||||
<kbd>◄</kbd>: 选择上一个冲突
|
<kbd>◄</kbd>: 选择上一个冲突
|
||||||
<kbd>►</kbd>: 选择下一个冲突
|
<kbd>►</kbd>: 选择下一个冲突
|
||||||
<kbd>▲</kbd>: 选择顶部块
|
<kbd>▲</kbd>: 选择顶部块
|
||||||
<kbd>▼</kbd>: 选择底部块
|
<kbd>▼</kbd>: 选择底部块
|
||||||
<kbd>e</kbd>: 编辑文件
|
|
||||||
<kbd>o</kbd>: 打开文件
|
|
||||||
<kbd>z</kbd>: 撤销
|
<kbd>z</kbd>: 撤销
|
||||||
|
<kbd>M</kbd>: 打开外部合并工具 (git mergetool)
|
||||||
|
<kbd>space</kbd>: 选中区块
|
||||||
|
<kbd>b</kbd>: 选中所有区块
|
||||||
|
<kbd>esc</kbd>: 返回文件面板
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## 正在暂存
|
## 正在暂存
|
||||||
@@ -243,8 +243,8 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
|||||||
## 正常
|
## 正常
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<kbd>mouse wheel down</kbd>: 向下滚动 (fn+up)
|
<kbd>mouse wheel ▼</kbd>: 向下滚动 (fn+up)
|
||||||
<kbd>mouse wheel up</kbd>: 向上滚动 (fn+down)
|
<kbd>mouse wheel ▲</kbd>: 向上滚动 (fn+down)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## 状态
|
## 状态
|
||||||
|
2
go.mod
2
go.mod
@@ -30,6 +30,7 @@ require (
|
|||||||
github.com/sahilm/fuzzy v0.1.0
|
github.com/sahilm/fuzzy v0.1.0
|
||||||
github.com/samber/lo v1.10.1
|
github.com/samber/lo v1.10.1
|
||||||
github.com/sanity-io/litter v1.5.2
|
github.com/sanity-io/litter v1.5.2
|
||||||
|
github.com/sasha-s/go-deadlock v0.3.1
|
||||||
github.com/sirupsen/logrus v1.4.2
|
github.com/sirupsen/logrus v1.4.2
|
||||||
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad
|
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.0
|
||||||
@@ -58,6 +59,7 @@ require (
|
|||||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
github.com/onsi/ginkgo v1.10.3 // indirect
|
github.com/onsi/ginkgo v1.10.3 // indirect
|
||||||
github.com/onsi/gomega v1.7.1 // indirect
|
github.com/onsi/gomega v1.7.1 // indirect
|
||||||
|
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
|
||||||
github.com/rivo/uniseg v0.3.4 // indirect
|
github.com/rivo/uniseg v0.3.4 // indirect
|
||||||
github.com/sergi/go-diff v1.1.0 // indirect
|
github.com/sergi/go-diff v1.1.0 // indirect
|
||||||
github.com/xanzy/ssh-agent v0.2.1 // indirect
|
github.com/xanzy/ssh-agent v0.2.1 // indirect
|
||||||
|
4
go.sum
4
go.sum
@@ -125,6 +125,8 @@ github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY=
|
|||||||
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ=
|
github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ=
|
||||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||||
|
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
|
||||||
|
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
|
||||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
@@ -140,6 +142,8 @@ github.com/samber/lo v1.10.1 h1:0D3h7i0U3hRAbaCeQ82DLe67n0A7Bbl0/cEoWqFGp+U=
|
|||||||
github.com/samber/lo v1.10.1/go.mod h1:2I7tgIv8Q1SG2xEIkRq0F2i2zgxVpnyPOP0d3Gj2r+A=
|
github.com/samber/lo v1.10.1/go.mod h1:2I7tgIv8Q1SG2xEIkRq0F2i2zgxVpnyPOP0d3Gj2r+A=
|
||||||
github.com/sanity-io/litter v1.5.2 h1:AnC8s9BMORWH5a4atZ4D6FPVvKGzHcnc5/IVTa87myw=
|
github.com/sanity-io/litter v1.5.2 h1:AnC8s9BMORWH5a4atZ4D6FPVvKGzHcnc5/IVTa87myw=
|
||||||
github.com/sanity-io/litter v1.5.2/go.mod h1:5Z71SvaYy5kcGtyglXOC9rrUi3c1E8CamFWjQsazTh0=
|
github.com/sanity-io/litter v1.5.2/go.mod h1:5Z71SvaYy5kcGtyglXOC9rrUi3c1E8CamFWjQsazTh0=
|
||||||
|
github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0=
|
||||||
|
github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM=
|
||||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||||
|
@@ -106,7 +106,7 @@ func localisedTitle(tr *i18n.TranslationSet, str string) string {
|
|||||||
"information": tr.InformationTitle,
|
"information": tr.InformationTitle,
|
||||||
"main": tr.NormalTitle,
|
"main": tr.NormalTitle,
|
||||||
"patchBuilding": tr.PatchBuildingTitle,
|
"patchBuilding": tr.PatchBuildingTitle,
|
||||||
"merging": tr.MergingTitle,
|
"mergeConflicts": tr.MergingTitle,
|
||||||
"staging": tr.StagingTitle,
|
"staging": tr.StagingTitle,
|
||||||
"menu": tr.MenuTitle,
|
"menu": tr.MenuTitle,
|
||||||
"search": tr.SearchTitle,
|
"search": tr.SearchTitle,
|
||||||
@@ -142,7 +142,7 @@ func getBindingSections(bindings []*types.Binding, tr *i18n.TranslationSet) []*b
|
|||||||
bindingsByHeader,
|
bindingsByHeader,
|
||||||
func(header header, hBindings []*types.Binding) headerWithBindings {
|
func(header header, hBindings []*types.Binding) headerWithBindings {
|
||||||
uniqBindings := lo.UniqBy(hBindings, func(binding *types.Binding) string {
|
uniqBindings := lo.UniqBy(hBindings, func(binding *types.Binding) string {
|
||||||
return binding.Description + keybindings.GetKeyDisplay(binding.Key)
|
return binding.Description + keybindings.LabelFromKey(binding.Key)
|
||||||
})
|
})
|
||||||
|
|
||||||
return headerWithBindings{
|
return headerWithBindings{
|
||||||
@@ -202,10 +202,10 @@ func formatBinding(binding *types.Binding) string {
|
|||||||
if binding.Alternative != "" {
|
if binding.Alternative != "" {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
" <kbd>%s</kbd>: %s (%s)\n",
|
" <kbd>%s</kbd>: %s (%s)\n",
|
||||||
keybindings.GetKeyDisplay(binding.Key),
|
keybindings.LabelFromKey(binding.Key),
|
||||||
binding.Description,
|
binding.Description,
|
||||||
binding.Alternative,
|
binding.Alternative,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(" <kbd>%s</kbd>: %s\n", keybindings.GetKeyDisplay(binding.Key), binding.Description)
|
return fmt.Sprintf(" <kbd>%s</kbd>: %s\n", keybindings.LabelFromKey(binding.Key), binding.Description)
|
||||||
}
|
}
|
||||||
|
@@ -5,9 +5,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
|
|
||||||
gogit "github.com/jesseduffield/go-git/v5"
|
gogit "github.com/jesseduffield/go-git/v5"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
@@ -57,7 +57,7 @@ func NewGitCommand(
|
|||||||
cmn *common.Common,
|
cmn *common.Common,
|
||||||
osCommand *oscommands.OSCommand,
|
osCommand *oscommands.OSCommand,
|
||||||
gitConfig git_config.IGitConfig,
|
gitConfig git_config.IGitConfig,
|
||||||
syncMutex *sync.Mutex,
|
syncMutex *deadlock.Mutex,
|
||||||
) (*GitCommand, error) {
|
) (*GitCommand, error) {
|
||||||
if err := navigateToRepoRootDirectory(os.Stat, os.Chdir); err != nil {
|
if err := navigateToRepoRootDirectory(os.Stat, os.Chdir); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -89,7 +89,7 @@ func NewGitCommandAux(
|
|||||||
gitConfig git_config.IGitConfig,
|
gitConfig git_config.IGitConfig,
|
||||||
dotGitDir string,
|
dotGitDir string,
|
||||||
repo *gogit.Repository,
|
repo *gogit.Repository,
|
||||||
syncMutex *sync.Mutex,
|
syncMutex *deadlock.Mutex,
|
||||||
) *GitCommand {
|
) *GitCommand {
|
||||||
cmd := NewGitCmdObjBuilder(cmn.Log, osCommand.Cmd)
|
cmd := NewGitCmdObjBuilder(cmn.Log, osCommand.Cmd)
|
||||||
|
|
||||||
|
@@ -1,11 +1,10 @@
|
|||||||
package git_commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
gogit "github.com/jesseduffield/go-git/v5"
|
gogit "github.com/jesseduffield/go-git/v5"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/common"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GitCommon struct {
|
type GitCommon struct {
|
||||||
@@ -16,7 +15,7 @@ type GitCommon struct {
|
|||||||
repo *gogit.Repository
|
repo *gogit.Repository
|
||||||
config *ConfigCommands
|
config *ConfigCommands
|
||||||
// mutex for doing things like push/pull/fetch
|
// mutex for doing things like push/pull/fetch
|
||||||
syncMutex *sync.Mutex
|
syncMutex *deadlock.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGitCommon(
|
func NewGitCommon(
|
||||||
@@ -26,7 +25,7 @@ func NewGitCommon(
|
|||||||
dotGitDir string,
|
dotGitDir string,
|
||||||
repo *gogit.Repository,
|
repo *gogit.Repository,
|
||||||
config *ConfigCommands,
|
config *ConfigCommands,
|
||||||
syncMutex *sync.Mutex,
|
syncMutex *deadlock.Mutex,
|
||||||
) *GitCommon {
|
) *GitCommon {
|
||||||
return &GitCommon{
|
return &GitCommon{
|
||||||
Common: cmn,
|
Common: cmn,
|
||||||
|
@@ -3,7 +3,6 @@ package commands
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -12,6 +11,7 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -220,7 +220,7 @@ func TestNewGitCommand(t *testing.T) {
|
|||||||
NewGitCommand(utils.NewDummyCommon(),
|
NewGitCommand(utils.NewDummyCommon(),
|
||||||
oscommands.NewDummyOSCommand(),
|
oscommands.NewDummyOSCommand(),
|
||||||
git_config.NewFakeGitConfig(nil),
|
git_config.NewFakeGitConfig(nil),
|
||||||
&sync.Mutex{},
|
&deadlock.Mutex{},
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,8 @@ package oscommands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sync"
|
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A command object is a general way to represent a command to be run on the
|
// A command object is a general way to represent a command to be run on the
|
||||||
@@ -51,8 +52,8 @@ type ICmdObj interface {
|
|||||||
PromptOnCredentialRequest() ICmdObj
|
PromptOnCredentialRequest() ICmdObj
|
||||||
FailOnCredentialRequest() ICmdObj
|
FailOnCredentialRequest() ICmdObj
|
||||||
|
|
||||||
WithMutex(mutex *sync.Mutex) ICmdObj
|
WithMutex(mutex *deadlock.Mutex) ICmdObj
|
||||||
Mutex() *sync.Mutex
|
Mutex() *deadlock.Mutex
|
||||||
|
|
||||||
GetCredentialStrategy() CredentialStrategy
|
GetCredentialStrategy() CredentialStrategy
|
||||||
}
|
}
|
||||||
@@ -76,7 +77,7 @@ type CmdObj struct {
|
|||||||
credentialStrategy CredentialStrategy
|
credentialStrategy CredentialStrategy
|
||||||
|
|
||||||
// can be set so that we don't run certain commands simultaneously
|
// can be set so that we don't run certain commands simultaneously
|
||||||
mutex *sync.Mutex
|
mutex *deadlock.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type CredentialStrategy int
|
type CredentialStrategy int
|
||||||
@@ -139,11 +140,11 @@ func (self *CmdObj) IgnoreEmptyError() ICmdObj {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CmdObj) Mutex() *sync.Mutex {
|
func (self *CmdObj) Mutex() *deadlock.Mutex {
|
||||||
return self.mutex
|
return self.mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CmdObj) WithMutex(mutex *sync.Mutex) ICmdObj {
|
func (self *CmdObj) WithMutex(mutex *deadlock.Mutex) ICmdObj {
|
||||||
self.mutex = mutex
|
self.mutex = mutex
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
@@ -7,12 +7,13 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sync"
|
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Buffer struct {
|
type Buffer struct {
|
||||||
b bytes.Buffer
|
b bytes.Buffer
|
||||||
m sync.Mutex
|
m deadlock.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Buffer) Read(p []byte) (n int, err error) {
|
func (b *Buffer) Read(p []byte) (n int, err error) {
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jesseduffield/generics/slices"
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// statusManager's job is to handle rendering of loading states and toast notifications
|
// statusManager's job is to handle rendering of loading states and toast notifications
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
type statusManager struct {
|
type statusManager struct {
|
||||||
statuses []appStatus
|
statuses []appStatus
|
||||||
nextId int
|
nextId int
|
||||||
mutex sync.Mutex
|
mutex deadlock.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type appStatus struct {
|
type appStatus struct {
|
||||||
@@ -94,7 +94,7 @@ func (gui *Gui) renderAppStatus() {
|
|||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
appStatus := gui.statusManager.getStatusString()
|
appStatus := gui.statusManager.getStatusString()
|
||||||
gui.OnUIThread(func() error {
|
gui.c.OnUIThread(func() error {
|
||||||
return gui.renderString(gui.Views.AppStatus, appStatus)
|
return gui.renderString(gui.Views.AppStatus, appStatus)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ func (gui *Gui) withWaitingStatus(message string, f func() error) error {
|
|||||||
gui.renderAppStatus()
|
gui.renderAppStatus()
|
||||||
|
|
||||||
if err := f(); err != nil {
|
if err := f(); err != nil {
|
||||||
gui.OnUIThread(func() error {
|
gui.c.OnUIThread(func() error {
|
||||||
return gui.c.Error(err)
|
return gui.c.Error(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/constants"
|
"github.com/jesseduffield/lazygit/pkg/constants"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
)
|
)
|
||||||
@@ -53,7 +54,7 @@ func (gui *Gui) LogCommand(cmdStr string, commandLine bool) {
|
|||||||
func (gui *Gui) printCommandLogHeader() {
|
func (gui *Gui) printCommandLogHeader() {
|
||||||
introStr := fmt.Sprintf(
|
introStr := fmt.Sprintf(
|
||||||
gui.c.Tr.CommandLogHeader,
|
gui.c.Tr.CommandLogHeader,
|
||||||
gui.getKeyDisplay(gui.c.UserConfig.Keybinding.Universal.ExtrasMenu),
|
keybindings.Label(gui.c.UserConfig.Keybinding.Universal.ExtrasMenu),
|
||||||
)
|
)
|
||||||
fmt.Fprintln(gui.Views.Extras, style.FgCyan.Sprint(introStr))
|
fmt.Fprintln(gui.Views.Extras, style.FgCyan.Sprint(introStr))
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ func (gui *Gui) getRandomTip() string {
|
|||||||
config := gui.c.UserConfig.Keybinding
|
config := gui.c.UserConfig.Keybinding
|
||||||
|
|
||||||
formattedKey := func(key string) string {
|
formattedKey := func(key string) string {
|
||||||
return gui.getKeyDisplay(key)
|
return keybindings.Label(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
tips := []string{
|
tips := []string{
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,9 +13,9 @@ func (gui *Gui) handleCommitMessageFocused() error {
|
|||||||
message := utils.ResolvePlaceholderString(
|
message := utils.ResolvePlaceholderString(
|
||||||
gui.c.Tr.CommitMessageConfirm,
|
gui.c.Tr.CommitMessageConfirm,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"keyBindClose": gui.getKeyDisplay(gui.c.UserConfig.Keybinding.Universal.Return),
|
"keyBindClose": keybindings.Label(gui.c.UserConfig.Keybinding.Universal.Return),
|
||||||
"keyBindConfirm": gui.getKeyDisplay(gui.c.UserConfig.Keybinding.Universal.Confirm),
|
"keyBindConfirm": keybindings.Label(gui.c.UserConfig.Keybinding.Universal.Confirm),
|
||||||
"keyBindNewLine": gui.getKeyDisplay(gui.c.UserConfig.Keybinding.Universal.AppendNewline),
|
"keyBindNewLine": keybindings.Label(gui.c.UserConfig.Keybinding.Universal.AppendNewline),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
@@ -220,22 +221,22 @@ func (gui *Gui) setKeyBindings(opts types.CreatePopupPanelOpts) error {
|
|||||||
bindings := []*types.Binding{
|
bindings := []*types.Binding{
|
||||||
{
|
{
|
||||||
ViewName: "confirmation",
|
ViewName: "confirmation",
|
||||||
Key: gui.getKey(keybindingConfig.Universal.Confirm),
|
Key: keybindings.GetKey(keybindingConfig.Universal.Confirm),
|
||||||
Handler: onConfirm,
|
Handler: onConfirm,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "confirmation",
|
ViewName: "confirmation",
|
||||||
Key: gui.getKey(keybindingConfig.Universal.ConfirmAlt1),
|
Key: keybindings.GetKey(keybindingConfig.Universal.ConfirmAlt1),
|
||||||
Handler: onConfirm,
|
Handler: onConfirm,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "confirmation",
|
ViewName: "confirmation",
|
||||||
Key: gui.getKey(keybindingConfig.Universal.Return),
|
Key: keybindings.GetKey(keybindingConfig.Universal.Return),
|
||||||
Handler: gui.wrappedConfirmationFunction(opts.HandleClose),
|
Handler: gui.wrappedConfirmationFunction(opts.HandleClose),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "confirmation",
|
ViewName: "confirmation",
|
||||||
Key: gui.getKey(keybindingConfig.Universal.TogglePanel),
|
Key: keybindings.GetKey(keybindingConfig.Universal.TogglePanel),
|
||||||
Handler: func() error {
|
Handler: func() error {
|
||||||
if len(gui.State.Suggestions) > 0 {
|
if len(gui.State.Suggestions) > 0 {
|
||||||
return gui.replaceContext(gui.State.Contexts.Suggestions)
|
return gui.replaceContext(gui.State.Contexts.Suggestions)
|
||||||
@@ -245,22 +246,22 @@ func (gui *Gui) setKeyBindings(opts types.CreatePopupPanelOpts) error {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "suggestions",
|
ViewName: "suggestions",
|
||||||
Key: gui.getKey(keybindingConfig.Universal.Confirm),
|
Key: keybindings.GetKey(keybindingConfig.Universal.Confirm),
|
||||||
Handler: onSuggestionConfirm,
|
Handler: onSuggestionConfirm,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "suggestions",
|
ViewName: "suggestions",
|
||||||
Key: gui.getKey(keybindingConfig.Universal.ConfirmAlt1),
|
Key: keybindings.GetKey(keybindingConfig.Universal.ConfirmAlt1),
|
||||||
Handler: onSuggestionConfirm,
|
Handler: onSuggestionConfirm,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "suggestions",
|
ViewName: "suggestions",
|
||||||
Key: gui.getKey(keybindingConfig.Universal.Return),
|
Key: keybindings.GetKey(keybindingConfig.Universal.Return),
|
||||||
Handler: gui.wrappedConfirmationFunction(opts.HandleClose),
|
Handler: gui.wrappedConfirmationFunction(opts.HandleClose),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "suggestions",
|
ViewName: "suggestions",
|
||||||
Key: gui.getKey(keybindingConfig.Universal.TogglePanel),
|
Key: keybindings.GetKey(keybindingConfig.Universal.TogglePanel),
|
||||||
Handler: func() error { return gui.replaceContext(gui.State.Contexts.Confirmation) },
|
Handler: func() error { return gui.replaceContext(gui.State.Contexts.Confirmation) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -276,12 +277,12 @@ func (gui *Gui) setKeyBindings(opts types.CreatePopupPanelOpts) error {
|
|||||||
|
|
||||||
func (gui *Gui) clearConfirmationViewKeyBindings() {
|
func (gui *Gui) clearConfirmationViewKeyBindings() {
|
||||||
keybindingConfig := gui.c.UserConfig.Keybinding
|
keybindingConfig := gui.c.UserConfig.Keybinding
|
||||||
_ = gui.g.DeleteKeybinding("confirmation", gui.getKey(keybindingConfig.Universal.Confirm), gocui.ModNone)
|
_ = gui.g.DeleteKeybinding("confirmation", keybindings.GetKey(keybindingConfig.Universal.Confirm), gocui.ModNone)
|
||||||
_ = gui.g.DeleteKeybinding("confirmation", gui.getKey(keybindingConfig.Universal.ConfirmAlt1), gocui.ModNone)
|
_ = gui.g.DeleteKeybinding("confirmation", keybindings.GetKey(keybindingConfig.Universal.ConfirmAlt1), gocui.ModNone)
|
||||||
_ = gui.g.DeleteKeybinding("confirmation", gui.getKey(keybindingConfig.Universal.Return), gocui.ModNone)
|
_ = gui.g.DeleteKeybinding("confirmation", keybindings.GetKey(keybindingConfig.Universal.Return), gocui.ModNone)
|
||||||
_ = gui.g.DeleteKeybinding("suggestions", gui.getKey(keybindingConfig.Universal.Confirm), gocui.ModNone)
|
_ = gui.g.DeleteKeybinding("suggestions", keybindings.GetKey(keybindingConfig.Universal.Confirm), gocui.ModNone)
|
||||||
_ = gui.g.DeleteKeybinding("suggestions", gui.getKey(keybindingConfig.Universal.ConfirmAlt1), gocui.ModNone)
|
_ = gui.g.DeleteKeybinding("suggestions", keybindings.GetKey(keybindingConfig.Universal.ConfirmAlt1), gocui.ModNone)
|
||||||
_ = gui.g.DeleteKeybinding("suggestions", gui.getKey(keybindingConfig.Universal.Return), gocui.ModNone)
|
_ = gui.g.DeleteKeybinding("suggestions", keybindings.GetKey(keybindingConfig.Universal.Return), gocui.ModNone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshSuggestions() {
|
func (gui *Gui) refreshSuggestions() {
|
||||||
@@ -297,8 +298,8 @@ func (gui *Gui) handleAskFocused() error {
|
|||||||
message := utils.ResolvePlaceholderString(
|
message := utils.ResolvePlaceholderString(
|
||||||
gui.c.Tr.CloseConfirm,
|
gui.c.Tr.CloseConfirm,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"keyBindClose": gui.getKeyDisplay(keybindingConfig.Universal.Return),
|
"keyBindClose": keybindings.Label(keybindingConfig.Universal.Return),
|
||||||
"keyBindConfirm": gui.getKeyDisplay(keybindingConfig.Universal.Confirm),
|
"keyBindConfirm": keybindings.Label(keybindingConfig.Universal.Confirm),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ const (
|
|||||||
STAGING_SECONDARY_CONTEXT_KEY types.ContextKey = "stagingSecondary"
|
STAGING_SECONDARY_CONTEXT_KEY types.ContextKey = "stagingSecondary"
|
||||||
PATCH_BUILDING_MAIN_CONTEXT_KEY types.ContextKey = "patchBuilding"
|
PATCH_BUILDING_MAIN_CONTEXT_KEY types.ContextKey = "patchBuilding"
|
||||||
PATCH_BUILDING_SECONDARY_CONTEXT_KEY types.ContextKey = "patchBuildingSecondary"
|
PATCH_BUILDING_SECONDARY_CONTEXT_KEY types.ContextKey = "patchBuildingSecondary"
|
||||||
MERGING_MAIN_CONTEXT_KEY types.ContextKey = "merging"
|
MERGE_CONFLICTS_CONTEXT_KEY types.ContextKey = "mergeConflicts"
|
||||||
|
|
||||||
// these shouldn't really be needed for anything but I'm giving them unique keys nonetheless
|
// these shouldn't really be needed for anything but I'm giving them unique keys nonetheless
|
||||||
OPTIONS_CONTEXT_KEY types.ContextKey = "options"
|
OPTIONS_CONTEXT_KEY types.ContextKey = "options"
|
||||||
@@ -60,7 +60,7 @@ var AllContextKeys = []types.ContextKey{
|
|||||||
STAGING_SECONDARY_CONTEXT_KEY,
|
STAGING_SECONDARY_CONTEXT_KEY,
|
||||||
PATCH_BUILDING_MAIN_CONTEXT_KEY,
|
PATCH_BUILDING_MAIN_CONTEXT_KEY,
|
||||||
PATCH_BUILDING_SECONDARY_CONTEXT_KEY,
|
PATCH_BUILDING_SECONDARY_CONTEXT_KEY,
|
||||||
MERGING_MAIN_CONTEXT_KEY,
|
MERGE_CONFLICTS_CONTEXT_KEY,
|
||||||
|
|
||||||
MENU_CONTEXT_KEY,
|
MENU_CONTEXT_KEY,
|
||||||
CONFIRMATION_CONTEXT_KEY,
|
CONFIRMATION_CONTEXT_KEY,
|
||||||
@@ -93,7 +93,7 @@ type ContextTree struct {
|
|||||||
StagingSecondary *PatchExplorerContext
|
StagingSecondary *PatchExplorerContext
|
||||||
CustomPatchBuilder *PatchExplorerContext
|
CustomPatchBuilder *PatchExplorerContext
|
||||||
CustomPatchBuilderSecondary types.Context
|
CustomPatchBuilderSecondary types.Context
|
||||||
Merging types.Context
|
MergeConflicts *MergeConflictsContext
|
||||||
Confirmation types.Context
|
Confirmation types.Context
|
||||||
CommitMessage types.Context
|
CommitMessage types.Context
|
||||||
CommandLog types.Context
|
CommandLog types.Context
|
||||||
@@ -127,7 +127,7 @@ func (self *ContextTree) Flatten() []types.Context {
|
|||||||
self.Confirmation,
|
self.Confirmation,
|
||||||
self.CommitMessage,
|
self.CommitMessage,
|
||||||
|
|
||||||
self.Merging,
|
self.MergeConflicts,
|
||||||
self.StagingSecondary,
|
self.StagingSecondary,
|
||||||
self.Staging,
|
self.Staging,
|
||||||
self.CustomPatchBuilderSecondary,
|
self.CustomPatchBuilderSecondary,
|
||||||
|
@@ -89,7 +89,7 @@ func (self *MenuViewModel) GetDisplayStrings(_startIdx int, _length int) [][]str
|
|||||||
return slices.Map(self.menuItems, func(item *types.MenuItem) []string {
|
return slices.Map(self.menuItems, func(item *types.MenuItem) []string {
|
||||||
displayStrings := item.LabelColumns
|
displayStrings := item.LabelColumns
|
||||||
if showKeys {
|
if showKeys {
|
||||||
displayStrings = slices.Prepend(displayStrings, style.FgCyan.Sprint(keybindings.GetKeyDisplay(item.Key)))
|
displayStrings = slices.Prepend(displayStrings, style.FgCyan.Sprint(keybindings.LabelFromKey(item.Key)))
|
||||||
}
|
}
|
||||||
return displayStrings
|
return displayStrings
|
||||||
})
|
})
|
||||||
|
117
pkg/gui/context/merge_conflicts_context.go
Normal file
117
pkg/gui/context/merge_conflicts_context.go
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
package context
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MergeConflictsContext struct {
|
||||||
|
types.Context
|
||||||
|
viewModel *ConflictsViewModel
|
||||||
|
c *types.HelperCommon
|
||||||
|
mutex *deadlock.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConflictsViewModel struct {
|
||||||
|
state *mergeconflicts.State
|
||||||
|
|
||||||
|
// userVerticalScrolling tells us if the user has started scrolling through the file themselves
|
||||||
|
// in which case we won't auto-scroll to a conflict.
|
||||||
|
userVerticalScrolling bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMergeConflictsContext(
|
||||||
|
view *gocui.View,
|
||||||
|
|
||||||
|
opts ContextCallbackOpts,
|
||||||
|
|
||||||
|
c *types.HelperCommon,
|
||||||
|
getOptionsMap func() map[string]string,
|
||||||
|
) *MergeConflictsContext {
|
||||||
|
viewModel := &ConflictsViewModel{
|
||||||
|
state: mergeconflicts.NewState(),
|
||||||
|
userVerticalScrolling: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &MergeConflictsContext{
|
||||||
|
viewModel: viewModel,
|
||||||
|
mutex: &deadlock.Mutex{},
|
||||||
|
Context: NewSimpleContext(
|
||||||
|
NewBaseContext(NewBaseContextOpts{
|
||||||
|
Kind: types.MAIN_CONTEXT,
|
||||||
|
View: view,
|
||||||
|
WindowName: "main",
|
||||||
|
Key: MERGE_CONFLICTS_CONTEXT_KEY,
|
||||||
|
OnGetOptionsMap: getOptionsMap,
|
||||||
|
Focusable: true,
|
||||||
|
}),
|
||||||
|
opts,
|
||||||
|
),
|
||||||
|
c: c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) GetState() *mergeconflicts.State {
|
||||||
|
return self.viewModel.state
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) SetState(state *mergeconflicts.State) {
|
||||||
|
self.viewModel.state = state
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) GetMutex() *deadlock.Mutex {
|
||||||
|
return self.mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) SetUserScrolling(isScrolling bool) {
|
||||||
|
self.viewModel.userVerticalScrolling = isScrolling
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) IsUserScrolling() bool {
|
||||||
|
return self.viewModel.userVerticalScrolling
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) RenderAndFocus(isFocused bool) error {
|
||||||
|
self.setContent(isFocused)
|
||||||
|
self.focusSelection()
|
||||||
|
|
||||||
|
self.c.Render()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) Render(isFocused bool) error {
|
||||||
|
self.setContent(isFocused)
|
||||||
|
|
||||||
|
self.c.Render()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) GetContentToRender(isFocused bool) string {
|
||||||
|
if self.GetState() == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return mergeconflicts.ColoredConflictFile(self.GetState(), isFocused)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) setContent(isFocused bool) {
|
||||||
|
self.GetView().SetContent(self.GetContentToRender(isFocused))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) focusSelection() {
|
||||||
|
if !self.IsUserScrolling() {
|
||||||
|
_ = self.GetView().SetOrigin(self.GetView().OriginX(), self.GetOriginY())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsContext) GetOriginY() int {
|
||||||
|
view := self.GetView()
|
||||||
|
conflictMiddle := self.GetState().GetConflictMiddle()
|
||||||
|
return int(math.Max(0, float64(conflictMiddle-(view.Height()/2))))
|
||||||
|
}
|
@@ -1,11 +1,10 @@
|
|||||||
package context
|
package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
deadlock "github.com/sasha-s/go-deadlock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PatchExplorerContext struct {
|
type PatchExplorerContext struct {
|
||||||
@@ -15,7 +14,7 @@ type PatchExplorerContext struct {
|
|||||||
viewTrait *ViewTrait
|
viewTrait *ViewTrait
|
||||||
getIncludedLineIndices func() []int
|
getIncludedLineIndices func() []int
|
||||||
c *types.HelperCommon
|
c *types.HelperCommon
|
||||||
mutex *sync.Mutex
|
mutex *deadlock.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ types.IPatchExplorerContext = (*PatchExplorerContext)(nil)
|
var _ types.IPatchExplorerContext = (*PatchExplorerContext)(nil)
|
||||||
@@ -35,7 +34,7 @@ func NewPatchExplorerContext(
|
|||||||
state: nil,
|
state: nil,
|
||||||
viewTrait: NewViewTrait(view),
|
viewTrait: NewViewTrait(view),
|
||||||
c: c,
|
c: c,
|
||||||
mutex: &sync.Mutex{},
|
mutex: &deadlock.Mutex{},
|
||||||
getIncludedLineIndices: getIncludedLineIndices,
|
getIncludedLineIndices: getIncludedLineIndices,
|
||||||
SimpleContext: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
|
SimpleContext: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
|
||||||
View: view,
|
View: view,
|
||||||
@@ -67,19 +66,16 @@ func (self *PatchExplorerContext) GetIncludedLineIndices() []int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *PatchExplorerContext) RenderAndFocus(isFocused bool) error {
|
func (self *PatchExplorerContext) RenderAndFocus(isFocused bool) error {
|
||||||
self.GetView().SetContent(self.GetContentToRender(isFocused))
|
self.setContent(isFocused)
|
||||||
|
|
||||||
if err := self.focusSelection(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
self.focusSelection()
|
||||||
self.c.Render()
|
self.c.Render()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *PatchExplorerContext) Render(isFocused bool) error {
|
func (self *PatchExplorerContext) Render(isFocused bool) error {
|
||||||
self.GetView().SetContent(self.GetContentToRender(isFocused))
|
self.setContent(isFocused)
|
||||||
|
|
||||||
self.c.Render()
|
self.c.Render()
|
||||||
|
|
||||||
@@ -87,16 +83,17 @@ func (self *PatchExplorerContext) Render(isFocused bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *PatchExplorerContext) Focus() error {
|
func (self *PatchExplorerContext) Focus() error {
|
||||||
if err := self.focusSelection(); err != nil {
|
self.focusSelection()
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
self.c.Render()
|
self.c.Render()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *PatchExplorerContext) focusSelection() error {
|
func (self *PatchExplorerContext) setContent(isFocused bool) {
|
||||||
|
self.GetView().SetContent(self.GetContentToRender(isFocused))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *PatchExplorerContext) focusSelection() {
|
||||||
view := self.GetView()
|
view := self.GetView()
|
||||||
state := self.GetState()
|
state := self.GetState()
|
||||||
_, viewHeight := view.Size()
|
_, viewHeight := view.Size()
|
||||||
@@ -107,11 +104,8 @@ func (self *PatchExplorerContext) focusSelection() error {
|
|||||||
|
|
||||||
newOrigin := state.CalculateOrigin(origin, bufferHeight)
|
newOrigin := state.CalculateOrigin(origin, bufferHeight)
|
||||||
|
|
||||||
if err := view.SetOriginY(newOrigin); err != nil {
|
_ = view.SetOriginY(newOrigin)
|
||||||
return err
|
_ = view.SetCursor(0, selectedLineIdx-newOrigin)
|
||||||
}
|
|
||||||
|
|
||||||
return view.SetCursor(0, selectedLineIdx-newOrigin)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *PatchExplorerContext) GetContentToRender(isFocused bool) string {
|
func (self *PatchExplorerContext) GetContentToRender(isFocused bool) string {
|
||||||
@@ -129,6 +123,6 @@ func (self *PatchExplorerContext) NavigateTo(isFocused bool, selectedLineIdx int
|
|||||||
return self.RenderAndFocus(isFocused)
|
return self.RenderAndFocus(isFocused)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *PatchExplorerContext) GetMutex() *sync.Mutex {
|
func (self *PatchExplorerContext) GetMutex() *deadlock.Mutex {
|
||||||
return self.mutex
|
return self.mutex
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ func (gui *Gui) contextTree() *context.ContextTree {
|
|||||||
Global: context.NewSimpleContext(
|
Global: context.NewSimpleContext(
|
||||||
context.NewBaseContext(context.NewBaseContextOpts{
|
context.NewBaseContext(context.NewBaseContextOpts{
|
||||||
Kind: types.GLOBAL_CONTEXT,
|
Kind: types.GLOBAL_CONTEXT,
|
||||||
View: nil,
|
View: nil, // TODO: see if this breaks anything
|
||||||
WindowName: "",
|
WindowName: "",
|
||||||
Key: context.GLOBAL_CONTEXT_KEY,
|
Key: context.GLOBAL_CONTEXT_KEY,
|
||||||
Focusable: false,
|
Focusable: false,
|
||||||
@@ -158,27 +158,27 @@ func (gui *Gui) contextTree() *context.ContextTree {
|
|||||||
}),
|
}),
|
||||||
context.ContextCallbackOpts{},
|
context.ContextCallbackOpts{},
|
||||||
),
|
),
|
||||||
Merging: context.NewSimpleContext(
|
MergeConflicts: context.NewMergeConflictsContext(
|
||||||
context.NewBaseContext(context.NewBaseContextOpts{
|
gui.Views.MergeConflicts,
|
||||||
Kind: types.MAIN_CONTEXT,
|
|
||||||
View: gui.Views.Merging,
|
|
||||||
WindowName: "main",
|
|
||||||
Key: context.MERGING_MAIN_CONTEXT_KEY,
|
|
||||||
OnGetOptionsMap: gui.getMergingOptions,
|
|
||||||
Focusable: true,
|
|
||||||
}),
|
|
||||||
context.ContextCallbackOpts{
|
context.ContextCallbackOpts{
|
||||||
OnFocus: OnFocusWrapper(func() error {
|
OnFocus: OnFocusWrapper(func() error {
|
||||||
gui.Views.Merging.Wrap = false
|
gui.Views.MergeConflicts.Wrap = false
|
||||||
|
|
||||||
return gui.renderConflictsWithLock(true)
|
return gui.refreshMergePanel(true)
|
||||||
}),
|
}),
|
||||||
OnFocusLost: func(types.OnFocusLostOpts) error {
|
OnFocusLost: func(opts types.OnFocusLostOpts) error {
|
||||||
gui.Views.Merging.Wrap = true
|
gui.State.Contexts.MergeConflicts.SetUserScrolling(false)
|
||||||
|
gui.State.Contexts.MergeConflicts.GetState().ResetConflictSelection()
|
||||||
|
gui.Views.MergeConflicts.Wrap = true
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
gui.c,
|
||||||
|
func() map[string]string {
|
||||||
|
// wrapping in a function because contexts are initialized before helpers
|
||||||
|
return gui.helpers.MergeConflicts.GetMergingOptions()
|
||||||
|
},
|
||||||
),
|
),
|
||||||
Confirmation: context.NewSimpleContext(
|
Confirmation: context.NewSimpleContext(
|
||||||
context.NewBaseContext(context.NewBaseContextOpts{
|
context.NewBaseContext(context.NewBaseContextOpts{
|
||||||
@@ -222,12 +222,11 @@ func (gui *Gui) contextTree() *context.ContextTree {
|
|||||||
),
|
),
|
||||||
CommandLog: context.NewSimpleContext(
|
CommandLog: context.NewSimpleContext(
|
||||||
context.NewBaseContext(context.NewBaseContextOpts{
|
context.NewBaseContext(context.NewBaseContextOpts{
|
||||||
Kind: types.EXTRAS_CONTEXT,
|
Kind: types.EXTRAS_CONTEXT,
|
||||||
View: gui.Views.Extras,
|
View: gui.Views.Extras,
|
||||||
WindowName: "extras",
|
WindowName: "extras",
|
||||||
Key: context.COMMAND_LOG_CONTEXT_KEY,
|
Key: context.COMMAND_LOG_CONTEXT_KEY,
|
||||||
OnGetOptionsMap: gui.getMergingOptions,
|
Focusable: true,
|
||||||
Focusable: true,
|
|
||||||
}),
|
}),
|
||||||
context.ContextCallbackOpts{
|
context.ContextCallbackOpts{
|
||||||
OnFocusLost: func(opts types.OnFocusLostOpts) error {
|
OnFocusLost: func(opts types.OnFocusLostOpts) error {
|
||||||
|
@@ -22,7 +22,7 @@ func (gui *Gui) resetControllers() {
|
|||||||
model,
|
model,
|
||||||
)
|
)
|
||||||
|
|
||||||
rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon, gui.State.Contexts, gui.git, gui.takeOverMergeConflictScrolling, refsHelper)
|
rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon, gui.State.Contexts, gui.git, refsHelper)
|
||||||
suggestionsHelper := helpers.NewSuggestionsHelper(helperCommon, model, gui.refreshSuggestions)
|
suggestionsHelper := helpers.NewSuggestionsHelper(helperCommon, model, gui.refreshSuggestions)
|
||||||
gui.helpers = &helpers.Helpers{
|
gui.helpers = &helpers.Helpers{
|
||||||
Refs: refsHelper,
|
Refs: refsHelper,
|
||||||
@@ -35,6 +35,7 @@ func (gui *Gui) resetControllers() {
|
|||||||
Tags: helpers.NewTagsHelper(helperCommon, gui.git),
|
Tags: helpers.NewTagsHelper(helperCommon, gui.git),
|
||||||
GPG: helpers.NewGpgHelper(helperCommon, gui.os, gui.git),
|
GPG: helpers.NewGpgHelper(helperCommon, gui.os, gui.git),
|
||||||
MergeAndRebase: rebaseHelper,
|
MergeAndRebase: rebaseHelper,
|
||||||
|
MergeConflicts: helpers.NewMergeConflictsHelper(helperCommon, gui.State.Contexts, gui.git),
|
||||||
CherryPick: helpers.NewCherryPickHelper(
|
CherryPick: helpers.NewCherryPickHelper(
|
||||||
helperCommon,
|
helperCommon,
|
||||||
gui.git,
|
gui.git,
|
||||||
@@ -51,7 +52,6 @@ func (gui *Gui) resetControllers() {
|
|||||||
gui.git,
|
gui.git,
|
||||||
gui.State.Contexts,
|
gui.State.Contexts,
|
||||||
gui.helpers,
|
gui.helpers,
|
||||||
gui.getKey,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
common := controllers.NewControllerCommon(
|
common := controllers.NewControllerCommon(
|
||||||
@@ -112,8 +112,8 @@ func (gui *Gui) resetControllers() {
|
|||||||
gui.enterSubmodule,
|
gui.enterSubmodule,
|
||||||
setCommitMessage,
|
setCommitMessage,
|
||||||
getSavedCommitMessage,
|
getSavedCommitMessage,
|
||||||
gui.switchToMerge,
|
|
||||||
)
|
)
|
||||||
|
mergeConflictsController := controllers.NewMergeConflictsController(common)
|
||||||
remotesController := controllers.NewRemotesController(
|
remotesController := controllers.NewRemotesController(
|
||||||
common,
|
common,
|
||||||
func(branches []*models.RemoteBranch) { gui.State.Model.RemoteBranches = branches },
|
func(branches []*models.RemoteBranch) { gui.State.Model.RemoteBranches = branches },
|
||||||
@@ -187,6 +187,10 @@ func (gui *Gui) resetControllers() {
|
|||||||
verticalScrollControllerFactory.Create(gui.State.Contexts.CustomPatchBuilder),
|
verticalScrollControllerFactory.Create(gui.State.Contexts.CustomPatchBuilder),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
controllers.AttachControllers(gui.State.Contexts.MergeConflicts,
|
||||||
|
mergeConflictsController,
|
||||||
|
)
|
||||||
|
|
||||||
controllers.AttachControllers(gui.State.Contexts.Files,
|
controllers.AttachControllers(gui.State.Contexts.Files,
|
||||||
filesController,
|
filesController,
|
||||||
filesRemoveController,
|
filesRemoveController,
|
||||||
|
@@ -22,7 +22,6 @@ type FilesController struct {
|
|||||||
enterSubmodule func(submodule *models.SubmoduleConfig) error
|
enterSubmodule func(submodule *models.SubmoduleConfig) error
|
||||||
setCommitMessage func(message string)
|
setCommitMessage func(message string)
|
||||||
getSavedCommitMessage func() string
|
getSavedCommitMessage func() string
|
||||||
switchToMergeFn func(path string) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ types.IController = &FilesController{}
|
var _ types.IController = &FilesController{}
|
||||||
@@ -32,14 +31,12 @@ func NewFilesController(
|
|||||||
enterSubmodule func(submodule *models.SubmoduleConfig) error,
|
enterSubmodule func(submodule *models.SubmoduleConfig) error,
|
||||||
setCommitMessage func(message string),
|
setCommitMessage func(message string),
|
||||||
getSavedCommitMessage func() string,
|
getSavedCommitMessage func() string,
|
||||||
switchToMergeFn func(path string) error,
|
|
||||||
) *FilesController {
|
) *FilesController {
|
||||||
return &FilesController{
|
return &FilesController{
|
||||||
controllerCommon: common,
|
controllerCommon: common,
|
||||||
enterSubmodule: enterSubmodule,
|
enterSubmodule: enterSubmodule,
|
||||||
setCommitMessage: setCommitMessage,
|
setCommitMessage: setCommitMessage,
|
||||||
getSavedCommitMessage: getSavedCommitMessage,
|
getSavedCommitMessage: getSavedCommitMessage,
|
||||||
switchToMergeFn: switchToMergeFn,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +158,7 @@ func (self *FilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*
|
|||||||
FocusedView: self.context().GetViewName(),
|
FocusedView: self.context().GetViewName(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "merging",
|
ViewName: "mergeConflicts",
|
||||||
Key: gocui.MouseLeft,
|
Key: gocui.MouseLeft,
|
||||||
Handler: self.onClickMain,
|
Handler: self.onClickMain,
|
||||||
FocusedView: self.context().GetViewName(),
|
FocusedView: self.context().GetViewName(),
|
||||||
@@ -268,10 +265,6 @@ func (self *FilesController) pressWithLock(node *filetree.FileNode) error {
|
|||||||
if node.IsFile() {
|
if node.IsFile() {
|
||||||
file := node.File
|
file := node.File
|
||||||
|
|
||||||
if file.HasInlineMergeConflicts {
|
|
||||||
return self.c.PushContext(self.contexts.Merging)
|
|
||||||
}
|
|
||||||
|
|
||||||
if file.HasUnstagedChanges {
|
if file.HasUnstagedChanges {
|
||||||
self.c.LogAction(self.c.Tr.Actions.StageFile)
|
self.c.LogAction(self.c.Tr.Actions.StageFile)
|
||||||
|
|
||||||
@@ -328,6 +321,10 @@ func (self *FilesController) pressWithLock(node *filetree.FileNode) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *FilesController) press(node *filetree.FileNode) error {
|
func (self *FilesController) press(node *filetree.FileNode) error {
|
||||||
|
if node.IsFile() && node.File.HasInlineMergeConflicts {
|
||||||
|
return self.switchToMerge()
|
||||||
|
}
|
||||||
|
|
||||||
if err := self.pressWithLock(node); err != nil {
|
if err := self.pressWithLock(node); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -750,7 +747,7 @@ func (self *FilesController) switchToMerge() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.switchToMergeFn(file.Name)
|
return self.helpers.MergeConflicts.SwitchToMerge(file.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *FilesController) createStashMenu() error {
|
func (self *FilesController) createStashMenu() error {
|
||||||
|
@@ -8,6 +8,7 @@ type Helpers struct {
|
|||||||
WorkingTree *WorkingTreeHelper
|
WorkingTree *WorkingTreeHelper
|
||||||
Tags *TagsHelper
|
Tags *TagsHelper
|
||||||
MergeAndRebase *MergeAndRebaseHelper
|
MergeAndRebase *MergeAndRebaseHelper
|
||||||
|
MergeConflicts *MergeConflictsHelper
|
||||||
CherryPick *CherryPickHelper
|
CherryPick *CherryPickHelper
|
||||||
Host *HostHelper
|
Host *HostHelper
|
||||||
PatchBuilding *PatchBuildingHelper
|
PatchBuilding *PatchBuildingHelper
|
||||||
@@ -24,6 +25,7 @@ func NewStubHelpers() *Helpers {
|
|||||||
WorkingTree: &WorkingTreeHelper{},
|
WorkingTree: &WorkingTreeHelper{},
|
||||||
Tags: &TagsHelper{},
|
Tags: &TagsHelper{},
|
||||||
MergeAndRebase: &MergeAndRebaseHelper{},
|
MergeAndRebase: &MergeAndRebaseHelper{},
|
||||||
|
MergeConflicts: &MergeConflictsHelper{},
|
||||||
CherryPick: &CherryPickHelper{},
|
CherryPick: &CherryPickHelper{},
|
||||||
Host: &HostHelper{},
|
Host: &HostHelper{},
|
||||||
PatchBuilding: &PatchBuildingHelper{},
|
PatchBuilding: &PatchBuildingHelper{},
|
||||||
|
@@ -14,26 +14,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MergeAndRebaseHelper struct {
|
type MergeAndRebaseHelper struct {
|
||||||
c *types.HelperCommon
|
c *types.HelperCommon
|
||||||
contexts *context.ContextTree
|
contexts *context.ContextTree
|
||||||
git *commands.GitCommand
|
git *commands.GitCommand
|
||||||
takeOverMergeConflictScrolling func()
|
refsHelper *RefsHelper
|
||||||
refsHelper *RefsHelper
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMergeAndRebaseHelper(
|
func NewMergeAndRebaseHelper(
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
contexts *context.ContextTree,
|
contexts *context.ContextTree,
|
||||||
git *commands.GitCommand,
|
git *commands.GitCommand,
|
||||||
takeOverMergeConflictScrolling func(),
|
|
||||||
refsHelper *RefsHelper,
|
refsHelper *RefsHelper,
|
||||||
) *MergeAndRebaseHelper {
|
) *MergeAndRebaseHelper {
|
||||||
return &MergeAndRebaseHelper{
|
return &MergeAndRebaseHelper{
|
||||||
c: c,
|
c: c,
|
||||||
contexts: contexts,
|
contexts: contexts,
|
||||||
git: git,
|
git: git,
|
||||||
takeOverMergeConflictScrolling: takeOverMergeConflictScrolling,
|
refsHelper: refsHelper,
|
||||||
refsHelper: refsHelper,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,8 +186,6 @@ func (self *MergeAndRebaseHelper) workingTreeStateNoun() string {
|
|||||||
|
|
||||||
// PromptToContinueRebase asks the user if they want to continue the rebase/merge that's in progress
|
// PromptToContinueRebase asks the user if they want to continue the rebase/merge that's in progress
|
||||||
func (self *MergeAndRebaseHelper) PromptToContinueRebase() error {
|
func (self *MergeAndRebaseHelper) PromptToContinueRebase() error {
|
||||||
self.takeOverMergeConflictScrolling()
|
|
||||||
|
|
||||||
return self.c.Confirm(types.ConfirmOpts{
|
return self.c.Confirm(types.ConfirmOpts{
|
||||||
Title: "continue",
|
Title: "continue",
|
||||||
Prompt: self.c.Tr.ConflictsResolved,
|
Prompt: self.c.Tr.ConflictsResolved,
|
||||||
|
115
pkg/gui/controllers/helpers/merge_conflicts_helper.go
Normal file
115
pkg/gui/controllers/helpers/merge_conflicts_helper.go
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
package helpers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MergeConflictsHelper struct {
|
||||||
|
c *types.HelperCommon
|
||||||
|
contexts *context.ContextTree
|
||||||
|
git *commands.GitCommand
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMergeConflictsHelper(
|
||||||
|
c *types.HelperCommon,
|
||||||
|
contexts *context.ContextTree,
|
||||||
|
git *commands.GitCommand,
|
||||||
|
) *MergeConflictsHelper {
|
||||||
|
return &MergeConflictsHelper{
|
||||||
|
c: c,
|
||||||
|
contexts: contexts,
|
||||||
|
git: git,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsHelper) GetMergingOptions() map[string]string {
|
||||||
|
keybindingConfig := self.c.UserConfig.Keybinding
|
||||||
|
|
||||||
|
return map[string]string{
|
||||||
|
fmt.Sprintf("%s %s", keybindings.Label(keybindingConfig.Universal.PrevItem), keybindings.Label(keybindingConfig.Universal.NextItem)): self.c.Tr.LcSelectHunk,
|
||||||
|
fmt.Sprintf("%s %s", keybindings.Label(keybindingConfig.Universal.PrevBlock), keybindings.Label(keybindingConfig.Universal.NextBlock)): self.c.Tr.LcNavigateConflicts,
|
||||||
|
keybindings.Label(keybindingConfig.Universal.Select): self.c.Tr.LcPickHunk,
|
||||||
|
keybindings.Label(keybindingConfig.Main.PickBothHunks): self.c.Tr.LcPickAllHunks,
|
||||||
|
keybindings.Label(keybindingConfig.Universal.Undo): self.c.Tr.LcUndo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsHelper) SetMergeState(path string) (bool, error) {
|
||||||
|
self.context().GetMutex().Lock()
|
||||||
|
defer self.context().GetMutex().Unlock()
|
||||||
|
|
||||||
|
return self.setMergeStateWithoutLock(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsHelper) setMergeStateWithoutLock(path string) (bool, error) {
|
||||||
|
content, err := self.git.File.Cat(path)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if path != self.context().GetState().GetPath() {
|
||||||
|
self.context().SetUserScrolling(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.context().GetState().SetContent(content, path)
|
||||||
|
|
||||||
|
return !self.context().GetState().NoConflicts(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsHelper) ResetMergeState() {
|
||||||
|
self.context().GetMutex().Lock()
|
||||||
|
defer self.context().GetMutex().Unlock()
|
||||||
|
|
||||||
|
self.resetMergeState()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsHelper) resetMergeState() {
|
||||||
|
self.context().SetUserScrolling(false)
|
||||||
|
self.context().GetState().Reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsHelper) EscapeMerge() error {
|
||||||
|
self.resetMergeState()
|
||||||
|
|
||||||
|
// doing this in separate UI thread so that we're not still holding the lock by the time refresh the file
|
||||||
|
self.c.OnUIThread(func() error {
|
||||||
|
return self.c.PushContext(self.contexts.Files)
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsHelper) SetConflictsAndRender(path string, isFocused bool) (bool, error) {
|
||||||
|
hasConflicts, err := self.setMergeStateWithoutLock(path)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if hasConflicts {
|
||||||
|
return true, self.context().Render(isFocused)
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsHelper) SwitchToMerge(path string) error {
|
||||||
|
if self.context().GetState().GetPath() != path {
|
||||||
|
hasConflicts, err := self.SetMergeState(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !hasConflicts {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.c.PushContext(self.contexts.MergeConflicts)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsHelper) context() *context.MergeConflictsContext {
|
||||||
|
return self.contexts.MergeConflicts
|
||||||
|
}
|
317
pkg/gui/controllers/merge_conflicts_controller.go
Normal file
317
pkg/gui/controllers/merge_conflicts_controller.go
Normal file
@@ -0,0 +1,317 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MergeConflictsController struct {
|
||||||
|
baseController
|
||||||
|
*controllerCommon
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ types.IController = &MergeConflictsController{}
|
||||||
|
|
||||||
|
func NewMergeConflictsController(
|
||||||
|
common *controllerCommon,
|
||||||
|
) *MergeConflictsController {
|
||||||
|
return &MergeConflictsController{
|
||||||
|
baseController: baseController{},
|
||||||
|
controllerCommon: common,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||||
|
bindings := []*types.Binding{
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.Edit),
|
||||||
|
Handler: self.HandleEditFile,
|
||||||
|
Description: self.c.Tr.LcEditFile,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.OpenFile),
|
||||||
|
Handler: self.HandleOpenFile,
|
||||||
|
Description: self.c.Tr.LcOpenFile,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.PrevBlock),
|
||||||
|
Handler: self.withRenderAndFocus(self.PrevConflict),
|
||||||
|
Description: self.c.Tr.PrevConflict,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.NextBlock),
|
||||||
|
Handler: self.withRenderAndFocus(self.NextConflict),
|
||||||
|
Description: self.c.Tr.NextConflict,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.PrevItem),
|
||||||
|
Handler: self.withRenderAndFocus(self.PrevConflictHunk),
|
||||||
|
Description: self.c.Tr.SelectPrevHunk,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.NextItem),
|
||||||
|
Handler: self.withRenderAndFocus(self.NextConflictHunk),
|
||||||
|
Description: self.c.Tr.SelectNextHunk,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.PrevBlockAlt),
|
||||||
|
Handler: self.withRenderAndFocus(self.PrevConflict),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.NextBlockAlt),
|
||||||
|
Handler: self.withRenderAndFocus(self.NextConflict),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.PrevItemAlt),
|
||||||
|
Handler: self.withRenderAndFocus(self.PrevConflictHunk),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.NextItemAlt),
|
||||||
|
Handler: self.withRenderAndFocus(self.NextConflictHunk),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.ScrollLeft),
|
||||||
|
Handler: self.withRenderAndFocus(self.HandleScrollLeft),
|
||||||
|
Description: self.c.Tr.LcScrollLeft,
|
||||||
|
Tag: "navigation",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.ScrollRight),
|
||||||
|
Handler: self.withRenderAndFocus(self.HandleScrollRight),
|
||||||
|
Description: self.c.Tr.LcScrollRight,
|
||||||
|
Tag: "navigation",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.Undo),
|
||||||
|
Handler: self.withRenderAndFocus(self.HandleUndo),
|
||||||
|
Description: self.c.Tr.LcUndo,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Files.OpenMergeTool),
|
||||||
|
Handler: self.helpers.WorkingTree.OpenMergeTool,
|
||||||
|
Description: self.c.Tr.LcOpenMergeTool,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.Select),
|
||||||
|
Handler: self.withRenderAndFocus(self.HandlePickHunk),
|
||||||
|
Description: self.c.Tr.PickHunk,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Main.PickBothHunks),
|
||||||
|
Handler: self.withRenderAndFocus(self.HandlePickAllHunks),
|
||||||
|
Description: self.c.Tr.PickAllHunks,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.Return),
|
||||||
|
Handler: self.Escape,
|
||||||
|
Description: self.c.Tr.ReturnToFilesPanel,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return bindings
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
||||||
|
return []*gocui.ViewMouseBinding{
|
||||||
|
{
|
||||||
|
ViewName: self.context().GetViewName(),
|
||||||
|
Key: gocui.MouseWheelUp,
|
||||||
|
Handler: func(gocui.ViewMouseBindingOpts) error {
|
||||||
|
return self.HandleScrollUp()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ViewName: self.context().GetViewName(),
|
||||||
|
Key: gocui.MouseWheelDown,
|
||||||
|
Handler: func(gocui.ViewMouseBindingOpts) error {
|
||||||
|
return self.HandleScrollDown()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) HandleScrollUp() error {
|
||||||
|
self.context().SetUserScrolling(true)
|
||||||
|
self.context().GetViewTrait().ScrollUp(self.c.UserConfig.Gui.ScrollHeight)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) HandleScrollDown() error {
|
||||||
|
self.context().SetUserScrolling(true)
|
||||||
|
self.context().GetViewTrait().ScrollDown(self.c.UserConfig.Gui.ScrollHeight)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) Context() types.Context {
|
||||||
|
return self.context()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) context() *context.MergeConflictsContext {
|
||||||
|
return self.contexts.MergeConflicts
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) Escape() error {
|
||||||
|
return self.c.PushContext(self.contexts.Files)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) HandleEditFile() error {
|
||||||
|
lineNumber := self.context().GetState().GetSelectedLine()
|
||||||
|
return self.helpers.Files.EditFileAtLine(self.context().GetState().GetPath(), lineNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) HandleOpenFile() error {
|
||||||
|
lineNumber := self.context().GetState().GetSelectedLine()
|
||||||
|
return self.helpers.Files.OpenFileAtLine(self.context().GetState().GetPath(), lineNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) HandleScrollLeft() error {
|
||||||
|
self.context().GetViewTrait().ScrollLeft()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) HandleScrollRight() error {
|
||||||
|
self.context().GetViewTrait().ScrollRight()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) HandleUndo() error {
|
||||||
|
state := self.context().GetState()
|
||||||
|
|
||||||
|
ok := state.Undo()
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
self.c.LogAction("Restoring file to previous state")
|
||||||
|
self.c.LogCommand("Undoing last conflict resolution", false)
|
||||||
|
if err := ioutil.WriteFile(state.GetPath(), []byte(state.GetContent()), 0o644); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) PrevConflictHunk() error {
|
||||||
|
self.context().SetUserScrolling(false)
|
||||||
|
self.context().GetState().SelectPrevConflictHunk()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) NextConflictHunk() error {
|
||||||
|
self.context().SetUserScrolling(false)
|
||||||
|
self.context().GetState().SelectNextConflictHunk()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) NextConflict() error {
|
||||||
|
self.context().SetUserScrolling(false)
|
||||||
|
self.context().GetState().SelectNextConflict()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) PrevConflict() error {
|
||||||
|
self.context().SetUserScrolling(false)
|
||||||
|
self.context().GetState().SelectPrevConflict()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) HandlePickHunk() error {
|
||||||
|
return self.pickSelection(self.context().GetState().Selection())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) HandlePickAllHunks() error {
|
||||||
|
return self.pickSelection(mergeconflicts.ALL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) pickSelection(selection mergeconflicts.Selection) error {
|
||||||
|
ok, err := self.resolveConflict(selection)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.context().GetState().AllConflictsResolved() {
|
||||||
|
return self.onLastConflictResolved()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) resolveConflict(selection mergeconflicts.Selection) (bool, error) {
|
||||||
|
self.context().SetUserScrolling(false)
|
||||||
|
|
||||||
|
state := self.context().GetState()
|
||||||
|
|
||||||
|
ok, content, err := state.ContentAfterConflictResolve(selection)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var logStr string
|
||||||
|
switch selection {
|
||||||
|
case mergeconflicts.TOP:
|
||||||
|
logStr = "Picking top hunk"
|
||||||
|
case mergeconflicts.MIDDLE:
|
||||||
|
logStr = "Picking middle hunk"
|
||||||
|
case mergeconflicts.BOTTOM:
|
||||||
|
logStr = "Picking bottom hunk"
|
||||||
|
case mergeconflicts.ALL:
|
||||||
|
logStr = "Picking all hunks"
|
||||||
|
}
|
||||||
|
self.c.LogAction("Resolve merge conflict")
|
||||||
|
self.c.LogCommand(logStr, false)
|
||||||
|
state.PushContent(content)
|
||||||
|
return true, ioutil.WriteFile(state.GetPath(), []byte(content), 0o644)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) onLastConflictResolved() error {
|
||||||
|
// as part of refreshing files, we handle the situation where a file has had
|
||||||
|
// its merge conflicts resolved.
|
||||||
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) isFocused() bool {
|
||||||
|
return self.c.CurrentContext().GetKey() == self.context().GetKey()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) withRenderAndFocus(f func() error) func() error {
|
||||||
|
return self.withLock(func() error {
|
||||||
|
if err := f(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.context().RenderAndFocus(self.isFocused())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MergeConflictsController) withLock(f func() error) func() error {
|
||||||
|
return func() error {
|
||||||
|
self.context().GetMutex().Lock()
|
||||||
|
defer self.context().GetMutex().Unlock()
|
||||||
|
|
||||||
|
if self.context().GetState() == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return f()
|
||||||
|
}
|
||||||
|
}
|
@@ -4,10 +4,11 @@ import (
|
|||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) handleEditorKeypress(textArea *gocui.TextArea, key gocui.Key, ch rune, mod gocui.Modifier, allowMultiline bool) bool {
|
func (gui *Gui) handleEditorKeypress(textArea *gocui.TextArea, key gocui.Key, ch rune, mod gocui.Modifier, allowMultiline bool) bool {
|
||||||
newlineKey, ok := gui.getKey(gui.c.UserConfig.Keybinding.Universal.AppendNewline).(gocui.Key)
|
newlineKey, ok := keybindings.GetKey(gui.c.UserConfig.Keybinding.Universal.AppendNewline).(gocui.Key)
|
||||||
if !ok {
|
if !ok {
|
||||||
newlineKey = gocui.KeyAltEnter
|
newlineKey = gocui.KeyAltEnter
|
||||||
}
|
}
|
||||||
|
@@ -6,8 +6,6 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
|
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
|
||||||
)
|
)
|
||||||
|
|
||||||
// list panel functions
|
|
||||||
|
|
||||||
func (gui *Gui) getSelectedFileNode() *filetree.FileNode {
|
func (gui *Gui) getSelectedFileNode() *filetree.FileNode {
|
||||||
return gui.State.Contexts.Files.GetSelected()
|
return gui.State.Contexts.Files.GetSelected()
|
||||||
}
|
}
|
||||||
@@ -20,15 +18,6 @@ func (gui *Gui) getSelectedFile() *models.File {
|
|||||||
return node.File
|
return node.File
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) getSelectedPath() string {
|
|
||||||
node := gui.getSelectedFileNode()
|
|
||||||
if node == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return node.GetPath()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) filesRenderToMain() error {
|
func (gui *Gui) filesRenderToMain() error {
|
||||||
node := gui.getSelectedFileNode()
|
node := gui.getSelectedFileNode()
|
||||||
|
|
||||||
@@ -43,16 +32,17 @@ func (gui *Gui) filesRenderToMain() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if node.File != nil && node.File.HasInlineMergeConflicts {
|
if node.File != nil && node.File.HasInlineMergeConflicts {
|
||||||
ok, err := gui.setConflictsAndRenderWithLock(node.GetPath(), false)
|
hasConflicts, err := gui.helpers.MergeConflicts.SetMergeState(node.GetPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if ok {
|
|
||||||
return nil
|
if hasConflicts {
|
||||||
|
return gui.refreshMergePanel(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.resetMergeStateWithLock()
|
gui.helpers.MergeConflicts.ResetMergeState()
|
||||||
|
|
||||||
pair := gui.normalMainContextPair()
|
pair := gui.normalMainContextPair()
|
||||||
if node.File != nil {
|
if node.File != nil {
|
||||||
@@ -92,13 +82,6 @@ func (gui *Gui) filesRenderToMain() error {
|
|||||||
return gui.refreshMainViews(refreshOpts)
|
return gui.refreshMainViews(refreshOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) onFocusFile() error {
|
|
||||||
gui.takeOverMergeConflictScrolling()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// test
|
|
||||||
|
|
||||||
func (gui *Gui) getSetTextareaTextFn(getView func() *gocui.View) func(string) {
|
func (gui *Gui) getSetTextareaTextFn(getView func() *gocui.View) func(string) {
|
||||||
return func(text string) {
|
return func(text string) {
|
||||||
// using a getView function so that we don't need to worry about when the view is created
|
// using a getView function so that we don't need to worry about when the view is created
|
||||||
@@ -108,5 +91,3 @@ func (gui *Gui) getSetTextareaTextFn(getView func() *gocui.View) func(string) {
|
|||||||
view.RenderTextArea()
|
view.RenderTextArea()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// test
|
|
||||||
|
@@ -75,10 +75,6 @@ func (gui *Gui) scrollDownView(view *gocui.View) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) scrollUpMain() error {
|
func (gui *Gui) scrollUpMain() error {
|
||||||
if gui.renderingConflicts() {
|
|
||||||
gui.State.Panels.Merging.UserVerticalScrolling = true
|
|
||||||
}
|
|
||||||
|
|
||||||
var view *gocui.View
|
var view *gocui.View
|
||||||
if gui.c.CurrentContext().GetWindowName() == "secondary" {
|
if gui.c.CurrentContext().GetWindowName() == "secondary" {
|
||||||
view = gui.secondaryView()
|
view = gui.secondaryView()
|
||||||
@@ -86,16 +82,20 @@ func (gui *Gui) scrollUpMain() error {
|
|||||||
view = gui.mainView()
|
view = gui.mainView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if view.Name() == "mergeConflicts" {
|
||||||
|
// although we have this same logic in the controller, this method can be invoked
|
||||||
|
// via the global scroll up/down keybindings, as opposed to just the mouse wheel keybinding.
|
||||||
|
// It would be nice to have a concept of a global keybinding that runs on the top context in a
|
||||||
|
// window but that might be overkill for this one use case.
|
||||||
|
gui.State.Contexts.MergeConflicts.SetUserScrolling(true)
|
||||||
|
}
|
||||||
|
|
||||||
gui.scrollUpView(view)
|
gui.scrollUpView(view)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) scrollDownMain() error {
|
func (gui *Gui) scrollDownMain() error {
|
||||||
if gui.renderingConflicts() {
|
|
||||||
gui.State.Panels.Merging.UserVerticalScrolling = true
|
|
||||||
}
|
|
||||||
|
|
||||||
var view *gocui.View
|
var view *gocui.View
|
||||||
if gui.c.CurrentContext().GetWindowName() == "secondary" {
|
if gui.c.CurrentContext().GetWindowName() == "secondary" {
|
||||||
view = gui.secondaryView()
|
view = gui.secondaryView()
|
||||||
@@ -103,6 +103,10 @@ func (gui *Gui) scrollDownMain() error {
|
|||||||
view = gui.mainView()
|
view = gui.mainView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if view.Name() == "mergeConflicts" {
|
||||||
|
gui.State.Contexts.MergeConflicts.SetUserScrolling(true)
|
||||||
|
}
|
||||||
|
|
||||||
gui.scrollDownView(view)
|
gui.scrollDownView(view)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -120,27 +124,6 @@ func (gui *Gui) secondaryView() *gocui.View {
|
|||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) scrollLeftMain() error {
|
|
||||||
gui.scrollLeft(gui.mainView())
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) scrollRightMain() error {
|
|
||||||
gui.scrollRight(gui.mainView())
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) scrollLeft(view *gocui.View) {
|
|
||||||
newOriginX := utils.Max(view.OriginX()-view.InnerWidth()/HORIZONTAL_SCROLL_FACTOR, 0)
|
|
||||||
_ = view.SetOriginX(newOriginX)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) scrollRight(view *gocui.View) {
|
|
||||||
_ = view.SetOriginX(view.OriginX() + view.InnerWidth()/HORIZONTAL_SCROLL_FACTOR)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) scrollUpSecondary() error {
|
func (gui *Gui) scrollUpSecondary() error {
|
||||||
gui.scrollUpView(gui.secondaryView())
|
gui.scrollUpView(gui.secondaryView())
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/modes/filtering"
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/filtering"
|
||||||
@@ -35,6 +35,7 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
"github.com/jesseduffield/lazygit/pkg/updates"
|
"github.com/jesseduffield/lazygit/pkg/updates"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
|
"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -169,7 +170,6 @@ type GuiRepoState struct {
|
|||||||
Suggestions []*types.Suggestion
|
Suggestions []*types.Suggestion
|
||||||
|
|
||||||
Updating bool
|
Updating bool
|
||||||
Panels *panelStates
|
|
||||||
SplitMainPanel bool
|
SplitMainPanel bool
|
||||||
LimitCommits bool
|
LimitCommits bool
|
||||||
|
|
||||||
@@ -199,20 +199,6 @@ type GuiRepoState struct {
|
|||||||
CurrentPopupOpts *types.CreatePopupPanelOpts
|
CurrentPopupOpts *types.CreatePopupPanelOpts
|
||||||
}
|
}
|
||||||
|
|
||||||
type MergingPanelState struct {
|
|
||||||
*mergeconflicts.State
|
|
||||||
|
|
||||||
// UserVerticalScrolling tells us if the user has started scrolling through the file themselves
|
|
||||||
// in which case we won't auto-scroll to a conflict.
|
|
||||||
UserVerticalScrolling bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// as we move things to the new context approach we're going to eventually
|
|
||||||
// remove this struct altogether and store this state on the contexts.
|
|
||||||
type panelStates struct {
|
|
||||||
Merging *MergingPanelState
|
|
||||||
}
|
|
||||||
|
|
||||||
type searchingState struct {
|
type searchingState struct {
|
||||||
view *gocui.View
|
view *gocui.View
|
||||||
isSearching bool
|
isSearching bool
|
||||||
@@ -299,13 +285,6 @@ func (gui *Gui) resetState(startArgs types.StartArgs, reuseState bool) {
|
|||||||
BisectInfo: git_commands.NewNullBisectInfo(),
|
BisectInfo: git_commands.NewNullBisectInfo(),
|
||||||
FilesTrie: patricia.NewTrie(),
|
FilesTrie: patricia.NewTrie(),
|
||||||
},
|
},
|
||||||
|
|
||||||
Panels: &panelStates{
|
|
||||||
Merging: &MergingPanelState{
|
|
||||||
State: mergeconflicts.NewState(),
|
|
||||||
UserVerticalScrolling: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Modes: &types.Modes{
|
Modes: &types.Modes{
|
||||||
Filtering: filtering.New(startArgs.FilterPath),
|
Filtering: filtering.New(startArgs.FilterPath),
|
||||||
CherryPicking: cherrypicking.New(),
|
CherryPicking: cherrypicking.New(),
|
||||||
@@ -380,13 +359,13 @@ func NewGui(
|
|||||||
// sake of backwards compatibility. We're making use of short circuiting here
|
// sake of backwards compatibility. We're making use of short circuiting here
|
||||||
ShowExtrasWindow: cmn.UserConfig.Gui.ShowCommandLog && !config.GetAppState().HideCommandLog,
|
ShowExtrasWindow: cmn.UserConfig.Gui.ShowCommandLog && !config.GetAppState().HideCommandLog,
|
||||||
Mutexes: types.Mutexes{
|
Mutexes: types.Mutexes{
|
||||||
RefreshingFilesMutex: &sync.Mutex{},
|
RefreshingFilesMutex: &deadlock.Mutex{},
|
||||||
RefreshingStatusMutex: &sync.Mutex{},
|
RefreshingStatusMutex: &deadlock.Mutex{},
|
||||||
SyncMutex: &sync.Mutex{},
|
SyncMutex: &deadlock.Mutex{},
|
||||||
LocalCommitsMutex: &sync.Mutex{},
|
LocalCommitsMutex: &deadlock.Mutex{},
|
||||||
SubprocessMutex: &sync.Mutex{},
|
SubprocessMutex: &deadlock.Mutex{},
|
||||||
PopupMutex: &sync.Mutex{},
|
PopupMutex: &deadlock.Mutex{},
|
||||||
PtyMutex: &sync.Mutex{},
|
PtyMutex: &deadlock.Mutex{},
|
||||||
},
|
},
|
||||||
InitialDir: initialDir,
|
InitialDir: initialDir,
|
||||||
}
|
}
|
||||||
@@ -438,7 +417,7 @@ var RuneReplacements = map[rune]string{
|
|||||||
graph.CommitSymbol: "o",
|
graph.CommitSymbol: "o",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) initGocui() (*gocui.Gui, error) {
|
func (gui *Gui) initGocui(headless bool) (*gocui.Gui, error) {
|
||||||
recordEvents := recordingEvents()
|
recordEvents := recordingEvents()
|
||||||
playMode := gocui.NORMAL
|
playMode := gocui.NORMAL
|
||||||
if recordEvents {
|
if recordEvents {
|
||||||
@@ -447,7 +426,7 @@ func (gui *Gui) initGocui() (*gocui.Gui, error) {
|
|||||||
playMode = gocui.REPLAYING
|
playMode = gocui.REPLAYING
|
||||||
}
|
}
|
||||||
|
|
||||||
g, err := gocui.NewGui(gocui.OutputTrue, OverlappingEdges, playMode, headless(), RuneReplacements)
|
g, err := gocui.NewGui(gocui.OutputTrue, OverlappingEdges, playMode, headless, RuneReplacements)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -496,7 +475,7 @@ func (gui *Gui) viewTabMap() map[string][]context.TabView {
|
|||||||
|
|
||||||
// Run: setup the gui with keybindings and start the mainloop
|
// Run: setup the gui with keybindings and start the mainloop
|
||||||
func (gui *Gui) Run(startArgs types.StartArgs) error {
|
func (gui *Gui) Run(startArgs types.StartArgs) error {
|
||||||
g, err := gui.initGocui()
|
g, err := gui.initGocui(headless())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -504,6 +483,13 @@ func (gui *Gui) Run(startArgs types.StartArgs) error {
|
|||||||
gui.g = g
|
gui.g = g
|
||||||
defer gui.g.Close()
|
defer gui.g.Close()
|
||||||
|
|
||||||
|
// if the deadlock package wants to report a deadlock, we first need to
|
||||||
|
// close the gui so that we can actually read what it prints.
|
||||||
|
deadlock.Opts.LogBuf = utils.NewOnceWriter(os.Stderr, func() {
|
||||||
|
gui.g.Close()
|
||||||
|
})
|
||||||
|
deadlock.Opts.Disable = !gui.Debug
|
||||||
|
|
||||||
if replaying() {
|
if replaying() {
|
||||||
gui.g.RecordingConfig = gocui.RecordingConfig{
|
gui.g.RecordingConfig = gocui.RecordingConfig{
|
||||||
Speed: getRecordingSpeed(),
|
Speed: getRecordingSpeed(),
|
||||||
@@ -527,9 +513,9 @@ func (gui *Gui) Run(startArgs types.StartArgs) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
userConfig := gui.UserConfig
|
userConfig := gui.UserConfig
|
||||||
gui.g.SearchEscapeKey = gui.getKey(userConfig.Keybinding.Universal.Return)
|
gui.g.SearchEscapeKey = keybindings.GetKey(userConfig.Keybinding.Universal.Return)
|
||||||
gui.g.NextSearchMatchKey = gui.getKey(userConfig.Keybinding.Universal.NextMatch)
|
gui.g.NextSearchMatchKey = keybindings.GetKey(userConfig.Keybinding.Universal.NextMatch)
|
||||||
gui.g.PrevSearchMatchKey = gui.getKey(userConfig.Keybinding.Universal.PrevMatch)
|
gui.g.PrevSearchMatchKey = keybindings.GetKey(userConfig.Keybinding.Universal.PrevMatch)
|
||||||
|
|
||||||
gui.g.ShowListFooter = userConfig.Gui.ShowListFooter
|
gui.g.ShowListFooter = userConfig.Gui.ShowListFooter
|
||||||
|
|
||||||
@@ -794,7 +780,7 @@ func (gui *Gui) setColorScheme() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) OnUIThread(f func() error) {
|
func (gui *Gui) onUIThread(f func() error) {
|
||||||
gui.g.Update(func(*gocui.Gui) error {
|
gui.g.Update(func(*gocui.Gui) error {
|
||||||
return f()
|
return f()
|
||||||
})
|
})
|
||||||
|
@@ -87,5 +87,5 @@ func (self *guiCommon) OpenSearch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *guiCommon) OnUIThread(f func() error) {
|
func (self *guiCommon) OnUIThread(f func() error) {
|
||||||
self.gui.OnUIThread(f)
|
self.gui.onUIThread(f)
|
||||||
}
|
}
|
||||||
|
@@ -2,37 +2,13 @@ package gui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/constants"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) getKeyDisplay(name string) string {
|
|
||||||
key := gui.getKey(name)
|
|
||||||
return keybindings.GetKeyDisplay(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) getKey(key string) types.Key {
|
|
||||||
runeCount := utf8.RuneCountInString(key)
|
|
||||||
if runeCount > 1 {
|
|
||||||
binding := keybindings.Keymap[strings.ToLower(key)]
|
|
||||||
if binding == nil {
|
|
||||||
log.Fatalf("Unrecognized key %s for keybinding. For permitted values see %s", strings.ToLower(key), constants.Links.Docs.CustomKeybindings)
|
|
||||||
} else {
|
|
||||||
return binding
|
|
||||||
}
|
|
||||||
} else if runeCount == 1 {
|
|
||||||
return []rune(key)[0]
|
|
||||||
}
|
|
||||||
log.Fatal("Key empty for keybinding: " + strings.ToLower(key))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) noPopupPanel(f func() error) func() error {
|
func (gui *Gui) noPopupPanel(f func() error) func() error {
|
||||||
return func() error {
|
return func() error {
|
||||||
if gui.popupPanelFocused() {
|
if gui.popupPanelFocused() {
|
||||||
@@ -68,7 +44,7 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
|||||||
}
|
}
|
||||||
|
|
||||||
opts := types.KeybindingsOpts{
|
opts := types.KeybindingsOpts{
|
||||||
GetKey: self.getKey,
|
GetKey: keybindings.GetKey,
|
||||||
Config: config,
|
Config: config,
|
||||||
Guards: guards,
|
Guards: guards,
|
||||||
}
|
}
|
||||||
@@ -325,110 +301,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
|||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: self.scrollUpSecondary,
|
Handler: self.scrollUpSecondary,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.ScrollLeft),
|
|
||||||
Handler: self.scrollLeftMain,
|
|
||||||
Description: self.c.Tr.LcScrollLeft,
|
|
||||||
Tag: "navigation",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.ScrollRight),
|
|
||||||
Handler: self.scrollRightMain,
|
|
||||||
Description: self.c.Tr.LcScrollRight,
|
|
||||||
Tag: "navigation",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.Return),
|
|
||||||
Handler: self.handleEscapeMerge,
|
|
||||||
Description: self.c.Tr.ReturnToFilesPanel,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Files.OpenMergeTool),
|
|
||||||
Handler: self.helpers.WorkingTree.OpenMergeTool,
|
|
||||||
Description: self.c.Tr.LcOpenMergeTool,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.Select),
|
|
||||||
Handler: self.handlePickHunk,
|
|
||||||
Description: self.c.Tr.PickHunk,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Main.PickBothHunks),
|
|
||||||
Handler: self.handlePickAllHunks,
|
|
||||||
Description: self.c.Tr.PickAllHunks,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.PrevBlock),
|
|
||||||
Handler: self.handleSelectPrevConflict,
|
|
||||||
Description: self.c.Tr.PrevConflict,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.NextBlock),
|
|
||||||
Handler: self.handleSelectNextConflict,
|
|
||||||
Description: self.c.Tr.NextConflict,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.PrevItem),
|
|
||||||
Handler: self.handleSelectPrevConflictHunk,
|
|
||||||
Description: self.c.Tr.SelectPrevHunk,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.NextItem),
|
|
||||||
Handler: self.handleSelectNextConflictHunk,
|
|
||||||
Description: self.c.Tr.SelectNextHunk,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.PrevBlockAlt),
|
|
||||||
Modifier: gocui.ModNone,
|
|
||||||
Handler: self.handleSelectPrevConflict,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.NextBlockAlt),
|
|
||||||
Modifier: gocui.ModNone,
|
|
||||||
Handler: self.handleSelectNextConflict,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.PrevItemAlt),
|
|
||||||
Modifier: gocui.ModNone,
|
|
||||||
Handler: self.handleSelectPrevConflictHunk,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.NextItemAlt),
|
|
||||||
Modifier: gocui.ModNone,
|
|
||||||
Handler: self.handleSelectNextConflictHunk,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.Edit),
|
|
||||||
Handler: self.handleMergeConflictEditFileAtLine,
|
|
||||||
Description: self.c.Tr.LcEditFile,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.OpenFile),
|
|
||||||
Handler: self.handleMergeConflictOpenFileAtLine,
|
|
||||||
Description: self.c.Tr.LcOpenFile,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "merging",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.Undo),
|
|
||||||
Handler: self.handleMergeConflictUndo,
|
|
||||||
Description: self.c.Tr.LcUndo,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
ViewName: "status",
|
ViewName: "status",
|
||||||
Key: gocui.MouseLeft,
|
Key: gocui.MouseLeft,
|
||||||
|
@@ -2,12 +2,16 @@ package keybindings
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/constants"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var KeyMapReversed = map[gocui.Key]string{
|
var keyMapReversed = map[gocui.Key]string{
|
||||||
gocui.KeyF1: "f1",
|
gocui.KeyF1: "f1",
|
||||||
gocui.KeyF2: "f2",
|
gocui.KeyF2: "f2",
|
||||||
gocui.KeyF3: "f3",
|
gocui.KeyF3: "f3",
|
||||||
@@ -66,11 +70,11 @@ var KeyMapReversed = map[gocui.Key]string{
|
|||||||
gocui.KeyCtrl5: "ctrl+5", // ctrl+]
|
gocui.KeyCtrl5: "ctrl+5", // ctrl+]
|
||||||
gocui.KeyCtrl6: "ctrl+6",
|
gocui.KeyCtrl6: "ctrl+6",
|
||||||
gocui.KeyCtrl8: "ctrl+8",
|
gocui.KeyCtrl8: "ctrl+8",
|
||||||
gocui.MouseWheelUp: "mouse wheel up",
|
gocui.MouseWheelUp: "mouse wheel ▲",
|
||||||
gocui.MouseWheelDown: "mouse wheel down",
|
gocui.MouseWheelDown: "mouse wheel ▼",
|
||||||
}
|
}
|
||||||
|
|
||||||
var Keymap = map[string]types.Key{
|
var keyMap = map[string]types.Key{
|
||||||
"<c-a>": gocui.KeyCtrlA,
|
"<c-a>": gocui.KeyCtrlA,
|
||||||
"<c-b>": gocui.KeyCtrlB,
|
"<c-b>": gocui.KeyCtrlB,
|
||||||
"<c-c>": gocui.KeyCtrlC,
|
"<c-c>": gocui.KeyCtrlC,
|
||||||
@@ -142,14 +146,18 @@ var Keymap = map[string]types.Key{
|
|||||||
"<right>": gocui.KeyArrowRight,
|
"<right>": gocui.KeyArrowRight,
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetKeyDisplay(key types.Key) string {
|
func Label(name string) string {
|
||||||
|
return LabelFromKey(GetKey(name))
|
||||||
|
}
|
||||||
|
|
||||||
|
func LabelFromKey(key types.Key) string {
|
||||||
keyInt := 0
|
keyInt := 0
|
||||||
|
|
||||||
switch key := key.(type) {
|
switch key := key.(type) {
|
||||||
case rune:
|
case rune:
|
||||||
keyInt = int(key)
|
keyInt = int(key)
|
||||||
case gocui.Key:
|
case gocui.Key:
|
||||||
value, ok := KeyMapReversed[key]
|
value, ok := keyMapReversed[key]
|
||||||
if ok {
|
if ok {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
@@ -158,3 +166,19 @@ func GetKeyDisplay(key types.Key) string {
|
|||||||
|
|
||||||
return fmt.Sprintf("%c", keyInt)
|
return fmt.Sprintf("%c", keyInt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetKey(key string) types.Key {
|
||||||
|
runeCount := utf8.RuneCountInString(key)
|
||||||
|
if runeCount > 1 {
|
||||||
|
binding := keyMap[strings.ToLower(key)]
|
||||||
|
if binding == nil {
|
||||||
|
log.Fatalf("Unrecognized key %s for keybinding. For permitted values see %s", strings.ToLower(key), constants.Links.Docs.CustomKeybindings)
|
||||||
|
} else {
|
||||||
|
return binding
|
||||||
|
}
|
||||||
|
} else if runeCount == 1 {
|
||||||
|
return []rune(key)[0]
|
||||||
|
}
|
||||||
|
log.Fatal("Key empty for keybinding: " + strings.ToLower(key))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@@ -33,7 +33,7 @@ func (gui *Gui) filesListContext() *context.WorkingTreeContext {
|
|||||||
return []string{line}
|
return []string{line}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
OnFocusWrapper(gui.onFocusFile),
|
nil,
|
||||||
gui.withDiffModeCheck(gui.filesRenderToMain),
|
gui.withDiffModeCheck(gui.filesRenderToMain),
|
||||||
nil,
|
nil,
|
||||||
gui.c,
|
gui.c,
|
||||||
|
@@ -43,6 +43,18 @@ func NewRenderStringWithoutScrollTask(str string) *renderStringWithoutScrollTask
|
|||||||
return &renderStringWithoutScrollTask{str: str}
|
return &renderStringWithoutScrollTask{str: str}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type renderStringWithScrollTask struct {
|
||||||
|
str string
|
||||||
|
originX int
|
||||||
|
originY int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *renderStringWithScrollTask) IsUpdateTask() {}
|
||||||
|
|
||||||
|
func NewRenderStringWithScrollTask(str string, originX int, originY int) *renderStringWithScrollTask {
|
||||||
|
return &renderStringWithScrollTask{str: str, originX: originX, originY: originY}
|
||||||
|
}
|
||||||
|
|
||||||
type runCommandTask struct {
|
type runCommandTask struct {
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
prefix string
|
prefix string
|
||||||
@@ -69,11 +81,6 @@ func NewRunPtyTask(cmd *exec.Cmd) *runPtyTask {
|
|||||||
return &runPtyTask{cmd: cmd}
|
return &runPtyTask{cmd: cmd}
|
||||||
}
|
}
|
||||||
|
|
||||||
// currently unused
|
|
||||||
// func (gui *Gui) createRunPtyTaskWithPrefix(cmd *exec.Cmd, prefix string) *runPtyTask {
|
|
||||||
// return &runPtyTask{cmd: cmd, prefix: prefix}
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (gui *Gui) runTaskForView(view *gocui.View, task updateTask) error {
|
func (gui *Gui) runTaskForView(view *gocui.View, task updateTask) error {
|
||||||
switch v := task.(type) {
|
switch v := task.(type) {
|
||||||
case *renderStringTask:
|
case *renderStringTask:
|
||||||
@@ -82,6 +89,9 @@ func (gui *Gui) runTaskForView(view *gocui.View, task updateTask) error {
|
|||||||
case *renderStringWithoutScrollTask:
|
case *renderStringWithoutScrollTask:
|
||||||
return gui.newStringTaskWithoutScroll(view, v.str)
|
return gui.newStringTaskWithoutScroll(view, v.str)
|
||||||
|
|
||||||
|
case *renderStringWithScrollTask:
|
||||||
|
return gui.newStringTaskWithScroll(view, v.str, v.originX, v.originY)
|
||||||
|
|
||||||
case *runCommandTask:
|
case *runCommandTask:
|
||||||
return gui.newCmdTask(view, v.cmd, v.prefix)
|
return gui.newCmdTask(view, v.cmd, v.prefix)
|
||||||
|
|
||||||
@@ -144,7 +154,7 @@ func (gui *Gui) patchBuildingMainContextPair() MainContextPair {
|
|||||||
|
|
||||||
func (gui *Gui) mergingMainContextPair() MainContextPair {
|
func (gui *Gui) mergingMainContextPair() MainContextPair {
|
||||||
return MainContextPair{
|
return MainContextPair{
|
||||||
main: gui.State.Contexts.Merging,
|
main: gui.State.Contexts.MergeConflicts,
|
||||||
secondary: nil,
|
secondary: nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package gui
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
@@ -13,9 +14,9 @@ func (gui *Gui) getMenuOptions() map[string]string {
|
|||||||
keybindingConfig := gui.c.UserConfig.Keybinding
|
keybindingConfig := gui.c.UserConfig.Keybinding
|
||||||
|
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
gui.getKeyDisplay(keybindingConfig.Universal.Return): gui.c.Tr.LcClose,
|
keybindings.Label(keybindingConfig.Universal.Return): gui.c.Tr.LcClose,
|
||||||
fmt.Sprintf("%s %s", gui.getKeyDisplay(keybindingConfig.Universal.PrevItem), gui.getKeyDisplay(keybindingConfig.Universal.NextItem)): gui.c.Tr.LcNavigate,
|
fmt.Sprintf("%s %s", keybindings.Label(keybindingConfig.Universal.PrevItem), keybindings.Label(keybindingConfig.Universal.NextItem)): gui.c.Tr.LcNavigate,
|
||||||
gui.getKeyDisplay(keybindingConfig.Universal.Select): gui.c.Tr.LcExecute,
|
keybindings.Label(keybindingConfig.Universal.Select): gui.c.Tr.LcExecute,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,319 +0,0 @@
|
|||||||
// though this panel is called the merge panel, it's really going to use the main panel. This may change in the future
|
|
||||||
|
|
||||||
package gui
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (gui *Gui) handleSelectPrevConflictHunk() error {
|
|
||||||
return gui.withMergeConflictLock(func() error {
|
|
||||||
gui.takeOverMergeConflictScrolling()
|
|
||||||
gui.State.Panels.Merging.SelectPrevConflictHunk()
|
|
||||||
return gui.renderConflictsWithFocus()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleSelectNextConflictHunk() error {
|
|
||||||
return gui.withMergeConflictLock(func() error {
|
|
||||||
gui.takeOverMergeConflictScrolling()
|
|
||||||
gui.State.Panels.Merging.SelectNextConflictHunk()
|
|
||||||
return gui.renderConflictsWithFocus()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleSelectNextConflict() error {
|
|
||||||
return gui.withMergeConflictLock(func() error {
|
|
||||||
gui.takeOverMergeConflictScrolling()
|
|
||||||
gui.State.Panels.Merging.SelectNextConflict()
|
|
||||||
return gui.renderConflictsWithFocus()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleSelectPrevConflict() error {
|
|
||||||
return gui.withMergeConflictLock(func() error {
|
|
||||||
gui.takeOverMergeConflictScrolling()
|
|
||||||
gui.State.Panels.Merging.SelectPrevConflict()
|
|
||||||
return gui.renderConflictsWithFocus()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleMergeConflictUndo() error {
|
|
||||||
state := gui.State.Panels.Merging
|
|
||||||
|
|
||||||
ok := state.Undo()
|
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.c.LogAction("Restoring file to previous state")
|
|
||||||
gui.LogCommand("Undoing last conflict resolution", false)
|
|
||||||
if err := ioutil.WriteFile(state.GetPath(), []byte(state.GetContent()), 0o644); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.renderConflictsWithFocus()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handlePickHunk() error {
|
|
||||||
return gui.withMergeConflictLock(func() error {
|
|
||||||
ok, err := gui.resolveConflict(gui.State.Panels.Merging.Selection())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if gui.State.Panels.Merging.AllConflictsResolved() {
|
|
||||||
return gui.onLastConflictResolved()
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.renderConflictsWithFocus()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handlePickAllHunks() error {
|
|
||||||
return gui.withMergeConflictLock(func() error {
|
|
||||||
ok, err := gui.resolveConflict(mergeconflicts.ALL)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if gui.State.Panels.Merging.AllConflictsResolved() {
|
|
||||||
return gui.onLastConflictResolved()
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.renderConflictsWithFocus()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) resolveConflict(selection mergeconflicts.Selection) (bool, error) {
|
|
||||||
gui.takeOverMergeConflictScrolling()
|
|
||||||
|
|
||||||
state := gui.State.Panels.Merging
|
|
||||||
|
|
||||||
ok, content, err := state.ContentAfterConflictResolve(selection)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var logStr string
|
|
||||||
switch selection {
|
|
||||||
case mergeconflicts.TOP:
|
|
||||||
logStr = "Picking top hunk"
|
|
||||||
case mergeconflicts.MIDDLE:
|
|
||||||
logStr = "Picking middle hunk"
|
|
||||||
case mergeconflicts.BOTTOM:
|
|
||||||
logStr = "Picking bottom hunk"
|
|
||||||
case mergeconflicts.ALL:
|
|
||||||
logStr = "Picking all hunks"
|
|
||||||
}
|
|
||||||
gui.c.LogAction("Resolve merge conflict")
|
|
||||||
gui.LogCommand(logStr, false)
|
|
||||||
state.PushContent(content)
|
|
||||||
return true, ioutil.WriteFile(state.GetPath(), []byte(content), 0o644)
|
|
||||||
}
|
|
||||||
|
|
||||||
// precondition: we actually have conflicts to render
|
|
||||||
func (gui *Gui) renderConflicts(hasFocus bool) error {
|
|
||||||
state := gui.State.Panels.Merging.State
|
|
||||||
content := mergeconflicts.ColoredConflictFile(state, hasFocus)
|
|
||||||
|
|
||||||
if !gui.State.Panels.Merging.UserVerticalScrolling {
|
|
||||||
// TODO: find a way to not have to do this OnUIThread thing. Why doesn't it work
|
|
||||||
// without it given that we're calling the 'no scroll' variant below?
|
|
||||||
gui.OnUIThread(func() error {
|
|
||||||
gui.State.Panels.Merging.Lock()
|
|
||||||
defer gui.State.Panels.Merging.Unlock()
|
|
||||||
|
|
||||||
if !state.Active() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.centerYPos(gui.Views.Merging, state.GetConflictMiddle())
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.refreshMainViews(refreshMainOpts{
|
|
||||||
pair: gui.mergingMainContextPair(),
|
|
||||||
main: &viewUpdateOpts{
|
|
||||||
task: NewRenderStringWithoutScrollTask(content),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) renderConflictsWithFocus() error {
|
|
||||||
return gui.renderConflicts(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) renderConflictsWithLock(hasFocus bool) error {
|
|
||||||
return gui.withMergeConflictLock(func() error {
|
|
||||||
return gui.renderConflicts(hasFocus)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) centerYPos(view *gocui.View, y int) {
|
|
||||||
ox, _ := view.Origin()
|
|
||||||
_, height := view.Size()
|
|
||||||
newOriginY := int(math.Max(0, float64(y-(height/2))))
|
|
||||||
_ = view.SetOrigin(ox, newOriginY)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) getMergingOptions() map[string]string {
|
|
||||||
keybindingConfig := gui.c.UserConfig.Keybinding
|
|
||||||
|
|
||||||
return map[string]string{
|
|
||||||
fmt.Sprintf("%s %s", gui.getKeyDisplay(keybindingConfig.Universal.PrevItem), gui.getKeyDisplay(keybindingConfig.Universal.NextItem)): gui.c.Tr.LcSelectHunk,
|
|
||||||
fmt.Sprintf("%s %s", gui.getKeyDisplay(keybindingConfig.Universal.PrevBlock), gui.getKeyDisplay(keybindingConfig.Universal.NextBlock)): gui.c.Tr.LcNavigateConflicts,
|
|
||||||
gui.getKeyDisplay(keybindingConfig.Universal.Select): gui.c.Tr.LcPickHunk,
|
|
||||||
gui.getKeyDisplay(keybindingConfig.Main.PickBothHunks): gui.c.Tr.LcPickAllHunks,
|
|
||||||
gui.getKeyDisplay(keybindingConfig.Universal.Undo): gui.c.Tr.LcUndo,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleEscapeMerge() error {
|
|
||||||
if err := gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.escapeMerge()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) onLastConflictResolved() error {
|
|
||||||
// as part of refreshing files, we handle the situation where a file has had
|
|
||||||
// its merge conflicts resolved.
|
|
||||||
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) resetMergeState() {
|
|
||||||
gui.takeOverMergeConflictScrolling()
|
|
||||||
gui.State.Panels.Merging.Reset()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) setMergeState(path string) (bool, error) {
|
|
||||||
content, err := gui.git.File.Cat(path)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.State.Panels.Merging.SetContent(content, path)
|
|
||||||
|
|
||||||
return !gui.State.Panels.Merging.NoConflicts(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) setMergeStateWithLock(path string) (bool, error) {
|
|
||||||
gui.State.Panels.Merging.Lock()
|
|
||||||
defer gui.State.Panels.Merging.Unlock()
|
|
||||||
|
|
||||||
return gui.setMergeState(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) resetMergeStateWithLock() {
|
|
||||||
gui.State.Panels.Merging.Lock()
|
|
||||||
defer gui.State.Panels.Merging.Unlock()
|
|
||||||
|
|
||||||
gui.resetMergeState()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) escapeMerge() error {
|
|
||||||
gui.resetMergeState()
|
|
||||||
|
|
||||||
// doing this in separate UI thread so that we're not still holding the lock by the time refresh the file
|
|
||||||
gui.OnUIThread(func() error {
|
|
||||||
return gui.c.PushContext(gui.State.Contexts.Files)
|
|
||||||
})
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) renderingConflicts() bool {
|
|
||||||
currentView := gui.g.CurrentView()
|
|
||||||
if currentView != gui.Views.Merging && currentView != gui.Views.Files {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.State.Panels.Merging.Active()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) withMergeConflictLock(f func() error) error {
|
|
||||||
gui.State.Panels.Merging.Lock()
|
|
||||||
defer gui.State.Panels.Merging.Unlock()
|
|
||||||
|
|
||||||
return f()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) takeOverMergeConflictScrolling() {
|
|
||||||
gui.State.Panels.Merging.UserVerticalScrolling = false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) setConflictsAndRender(path string, hasFocus bool) (bool, error) {
|
|
||||||
hasConflicts, err := gui.setMergeState(path)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if hasConflicts {
|
|
||||||
return true, gui.renderConflicts(hasFocus)
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) setConflictsAndRenderWithLock(path string, hasFocus bool) (bool, error) {
|
|
||||||
gui.State.Panels.Merging.Lock()
|
|
||||||
defer gui.State.Panels.Merging.Unlock()
|
|
||||||
|
|
||||||
return gui.setConflictsAndRender(path, hasFocus)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) switchToMerge(path string) error {
|
|
||||||
gui.takeOverMergeConflictScrolling()
|
|
||||||
|
|
||||||
if gui.State.Panels.Merging.GetPath() != path {
|
|
||||||
hasConflicts, err := gui.setMergeStateWithLock(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !hasConflicts {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.c.PushContext(gui.State.Contexts.Merging)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleMergeConflictEditFileAtLine() error {
|
|
||||||
file := gui.getSelectedFile()
|
|
||||||
if file == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
lineNumber := gui.State.Panels.Merging.GetSelectedLine()
|
|
||||||
return gui.helpers.Files.EditFileAtLine(file.GetPath(), lineNumber)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleMergeConflictOpenFileAtLine() error {
|
|
||||||
file := gui.getSelectedFile()
|
|
||||||
if file == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
lineNumber := gui.State.Panels.Merging.GetSelectedLine()
|
|
||||||
return gui.helpers.Files.OpenFileAtLine(file.GetPath(), lineNumber)
|
|
||||||
}
|
|
@@ -1,15 +1,11 @@
|
|||||||
package mergeconflicts
|
package mergeconflicts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// State represents the selection state of the merge conflict context.
|
// State represents the selection state of the merge conflict context.
|
||||||
type State struct {
|
type State struct {
|
||||||
sync.Mutex
|
|
||||||
|
|
||||||
// path of the file with the conflicts
|
// path of the file with the conflicts
|
||||||
path string
|
path string
|
||||||
|
|
||||||
@@ -28,7 +24,6 @@ type State struct {
|
|||||||
|
|
||||||
func NewState() *State {
|
func NewState() *State {
|
||||||
return &State{
|
return &State{
|
||||||
Mutex: sync.Mutex{},
|
|
||||||
conflictIndex: 0,
|
conflictIndex: 0,
|
||||||
selectionIndex: 0,
|
selectionIndex: 0,
|
||||||
conflicts: []*mergeConflict{},
|
conflicts: []*mergeConflict{},
|
||||||
@@ -151,6 +146,12 @@ func (s *State) Reset() {
|
|||||||
s.path = ""
|
s.path = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we're not resetting selectedIndex here because the user typically would want
|
||||||
|
// to pick either all top hunks or all bottom hunks so we retain that selection
|
||||||
|
func (s *State) ResetConflictSelection() {
|
||||||
|
s.conflictIndex = 0
|
||||||
|
}
|
||||||
|
|
||||||
func (s *State) Active() bool {
|
func (s *State) Active() bool {
|
||||||
return s.path != ""
|
return s.path != ""
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@ func (gui *Gui) getBindings(context types.Context) []*types.Binding {
|
|||||||
bindings = append(customBindings, bindings...)
|
bindings = append(customBindings, bindings...)
|
||||||
|
|
||||||
for _, binding := range bindings {
|
for _, binding := range bindings {
|
||||||
if keybindings.GetKeyDisplay(binding.Key) != "" && binding.Description != "" {
|
if keybindings.LabelFromKey(binding.Key) != "" && binding.Description != "" {
|
||||||
if binding.ViewName == "" {
|
if binding.ViewName == "" {
|
||||||
bindingsGlobal = append(bindingsGlobal, binding)
|
bindingsGlobal = append(bindingsGlobal, binding)
|
||||||
} else if binding.Tag == "navigation" {
|
} else if binding.Tag == "navigation" {
|
||||||
|
@@ -2,7 +2,6 @@ package popup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/common"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
@@ -10,12 +9,13 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PopupHandler struct {
|
type PopupHandler struct {
|
||||||
*common.Common
|
*common.Common
|
||||||
index int
|
index int
|
||||||
sync.Mutex
|
deadlock.Mutex
|
||||||
createPopupPanelFn func(types.CreatePopupPanelOpts) error
|
createPopupPanelFn func(types.CreatePopupPanelOpts) error
|
||||||
onErrorFn func() error
|
onErrorFn func() error
|
||||||
popContextFn func() error
|
popContextFn func() error
|
||||||
|
@@ -2,7 +2,6 @@ package presentation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/generics/set"
|
"github.com/jesseduffield/generics/set"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
@@ -14,6 +13,7 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/kyokomi/emoji/v2"
|
"github.com/kyokomi/emoji/v2"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pipeSetCacheKey struct {
|
type pipeSetCacheKey struct {
|
||||||
@@ -23,7 +23,7 @@ type pipeSetCacheKey struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
pipeSetCache = make(map[pipeSetCacheKey][][]*graph.Pipe)
|
pipeSetCache = make(map[pipeSetCacheKey][][]*graph.Pipe)
|
||||||
mutex sync.Mutex
|
mutex deadlock.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
type bisectBounds struct {
|
type bisectBounds struct {
|
||||||
|
@@ -22,17 +22,18 @@ import (
|
|||||||
|
|
||||||
func getScopeNames(scopes []types.RefreshableView) []string {
|
func getScopeNames(scopes []types.RefreshableView) []string {
|
||||||
scopeNameMap := map[types.RefreshableView]string{
|
scopeNameMap := map[types.RefreshableView]string{
|
||||||
types.COMMITS: "commits",
|
types.COMMITS: "commits",
|
||||||
types.BRANCHES: "branches",
|
types.BRANCHES: "branches",
|
||||||
types.FILES: "files",
|
types.FILES: "files",
|
||||||
types.SUBMODULES: "submodules",
|
types.SUBMODULES: "submodules",
|
||||||
types.STASH: "stash",
|
types.STASH: "stash",
|
||||||
types.REFLOG: "reflog",
|
types.REFLOG: "reflog",
|
||||||
types.TAGS: "tags",
|
types.TAGS: "tags",
|
||||||
types.REMOTES: "remotes",
|
types.REMOTES: "remotes",
|
||||||
types.STATUS: "status",
|
types.STATUS: "status",
|
||||||
types.BISECT_INFO: "bisect",
|
types.BISECT_INFO: "bisect",
|
||||||
types.STAGING: "staging",
|
types.STAGING: "staging",
|
||||||
|
types.MERGE_CONFLICTS: "mergeConflicts",
|
||||||
}
|
}
|
||||||
|
|
||||||
return slices.Map(scopes, func(scope types.RefreshableView) string {
|
return slices.Map(scopes, func(scope types.RefreshableView) string {
|
||||||
@@ -138,6 +139,10 @@ func (gui *Gui) Refresh(options types.RefreshOptions) error {
|
|||||||
refresh(func() { _ = gui.refreshPatchBuildingPanel(types.OnFocusOpts{}) })
|
refresh(func() { _ = gui.refreshPatchBuildingPanel(types.OnFocusOpts{}) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if scopeSet.Includes(types.MERGE_CONFLICTS) || scopeSet.Includes(types.FILES) {
|
||||||
|
refresh(func() { _ = gui.refreshMergeState() })
|
||||||
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
gui.refreshStatus()
|
gui.refreshStatus()
|
||||||
@@ -148,7 +153,7 @@ func (gui *Gui) Refresh(options types.RefreshOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if options.Mode == types.BLOCK_UI {
|
if options.Mode == types.BLOCK_UI {
|
||||||
gui.OnUIThread(func() error {
|
gui.c.OnUIThread(func() error {
|
||||||
f()
|
f()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -323,21 +328,15 @@ func (gui *Gui) refreshFilesAndSubmodules() error {
|
|||||||
gui.Mutexes.RefreshingFilesMutex.Unlock()
|
gui.Mutexes.RefreshingFilesMutex.Unlock()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
prevSelectedPath := gui.getSelectedPath()
|
|
||||||
|
|
||||||
if err := gui.refreshStateSubmoduleConfigs(); err != nil {
|
if err := gui.refreshStateSubmoduleConfigs(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gui.refreshMergeState(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := gui.refreshStateFiles(); err != nil {
|
if err := gui.refreshStateFiles(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.OnUIThread(func() error {
|
gui.c.OnUIThread(func() error {
|
||||||
if err := gui.c.PostRefreshUpdate(gui.State.Contexts.Submodules); err != nil {
|
if err := gui.c.PostRefreshUpdate(gui.State.Contexts.Submodules); err != nil {
|
||||||
gui.c.Log.Error(err)
|
gui.c.Log.Error(err)
|
||||||
}
|
}
|
||||||
@@ -346,14 +345,6 @@ func (gui *Gui) refreshFilesAndSubmodules() error {
|
|||||||
gui.c.Log.Error(err)
|
gui.c.Log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if gui.currentContext().GetKey() == context.FILES_CONTEXT_KEY {
|
|
||||||
currentSelectedPath := gui.getSelectedPath()
|
|
||||||
alreadySelected := prevSelectedPath != "" && currentSelectedPath == prevSelectedPath
|
|
||||||
if !alreadySelected {
|
|
||||||
gui.takeOverMergeConflictScrolling()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -361,20 +352,20 @@ func (gui *Gui) refreshFilesAndSubmodules() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshMergeState() error {
|
func (gui *Gui) refreshMergeState() error {
|
||||||
gui.State.Panels.Merging.Lock()
|
gui.State.Contexts.MergeConflicts.GetMutex().Lock()
|
||||||
defer gui.State.Panels.Merging.Unlock()
|
defer gui.State.Contexts.MergeConflicts.GetMutex().Unlock()
|
||||||
|
|
||||||
if gui.currentContext().GetKey() != context.MERGING_MAIN_CONTEXT_KEY {
|
if gui.currentContext().GetKey() != context.MERGE_CONFLICTS_CONTEXT_KEY {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
hasConflicts, err := gui.setConflictsAndRender(gui.State.Panels.Merging.GetPath(), true)
|
hasConflicts, err := gui.helpers.MergeConflicts.SetConflictsAndRender(gui.State.Contexts.MergeConflicts.GetState().GetPath(), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gui.c.Error(err)
|
return gui.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hasConflicts {
|
if !hasConflicts {
|
||||||
return gui.escapeMerge()
|
return gui.helpers.MergeConflicts.EscapeMerge()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -426,7 +417,7 @@ func (gui *Gui) refreshStateFiles() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if gui.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE && conflictFileCount == 0 && prevConflictFileCount > 0 {
|
if gui.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE && conflictFileCount == 0 && prevConflictFileCount > 0 {
|
||||||
gui.OnUIThread(func() error { return gui.helpers.MergeAndRebase.PromptToContinueRebase() })
|
gui.c.OnUIThread(func() error { return gui.helpers.MergeAndRebase.PromptToContinueRebase() })
|
||||||
}
|
}
|
||||||
|
|
||||||
fileTreeViewModel.RWMutex.Lock()
|
fileTreeViewModel.RWMutex.Lock()
|
||||||
@@ -701,3 +692,22 @@ func (gui *Gui) refreshPatchBuildingPanel(opts types.OnFocusOpts) error {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) refreshMergePanel(isFocused bool) error {
|
||||||
|
content := gui.State.Contexts.MergeConflicts.GetContentToRender(isFocused)
|
||||||
|
|
||||||
|
var task updateTask
|
||||||
|
if gui.State.Contexts.MergeConflicts.IsUserScrolling() {
|
||||||
|
task = NewRenderStringWithoutScrollTask(content)
|
||||||
|
} else {
|
||||||
|
originY := gui.State.Contexts.MergeConflicts.GetOriginY()
|
||||||
|
task = NewRenderStringWithScrollTask(content, 0, originY)
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.refreshMainViews(refreshMainOpts{
|
||||||
|
pair: gui.mergingMainContextPair(),
|
||||||
|
main: &viewUpdateOpts{
|
||||||
|
task: task,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package gui
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ func (gui *Gui) onSelectItemWrapper(innerFunc func(int) error) func(int, int, in
|
|||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"no matches for '%s' %s",
|
"no matches for '%s' %s",
|
||||||
gui.State.Searching.searchString,
|
gui.State.Searching.searchString,
|
||||||
theme.OptionsFgColor.Sprintf("%s: exit search mode", gui.getKeyDisplay(keybindingConfig.Universal.Return)),
|
theme.OptionsFgColor.Sprintf("%s: exit search mode", keybindings.Label(keybindingConfig.Universal.Return)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -65,9 +66,9 @@ func (gui *Gui) onSelectItemWrapper(innerFunc func(int) error) func(int, int, in
|
|||||||
total,
|
total,
|
||||||
theme.OptionsFgColor.Sprintf(
|
theme.OptionsFgColor.Sprintf(
|
||||||
"%s: next match, %s: previous match, %s: exit search mode",
|
"%s: next match, %s: previous match, %s: exit search mode",
|
||||||
gui.getKeyDisplay(keybindingConfig.Universal.NextMatch),
|
keybindings.Label(keybindingConfig.Universal.NextMatch),
|
||||||
gui.getKeyDisplay(keybindingConfig.Universal.PrevMatch),
|
keybindings.Label(keybindingConfig.Universal.PrevMatch),
|
||||||
gui.getKeyDisplay(keybindingConfig.Universal.Return),
|
keybindings.Label(keybindingConfig.Universal.Return),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@@ -23,11 +23,10 @@ func NewClient(
|
|||||||
git *commands.GitCommand,
|
git *commands.GitCommand,
|
||||||
contexts *context.ContextTree,
|
contexts *context.ContextTree,
|
||||||
helpers *helpers.Helpers,
|
helpers *helpers.Helpers,
|
||||||
getKey func(string) types.Key,
|
|
||||||
) *Client {
|
) *Client {
|
||||||
sessionStateLoader := NewSessionStateLoader(contexts, helpers)
|
sessionStateLoader := NewSessionStateLoader(contexts, helpers)
|
||||||
handlerCreator := NewHandlerCreator(c, os, git, sessionStateLoader)
|
handlerCreator := NewHandlerCreator(c, os, git, sessionStateLoader)
|
||||||
keybindingCreator := NewKeybindingCreator(contexts, getKey)
|
keybindingCreator := NewKeybindingCreator(contexts)
|
||||||
customCommands := c.UserConfig.CustomCommands
|
customCommands := c.UserConfig.CustomCommands
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
|
@@ -8,19 +8,18 @@ import (
|
|||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KeybindingCreator takes a custom command along with its handler and returns a corresponding keybinding
|
// KeybindingCreator takes a custom command along with its handler and returns a corresponding keybinding
|
||||||
type KeybindingCreator struct {
|
type KeybindingCreator struct {
|
||||||
contexts *context.ContextTree
|
contexts *context.ContextTree
|
||||||
getKey func(string) types.Key
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKeybindingCreator(contexts *context.ContextTree, getKey func(string) types.Key) *KeybindingCreator {
|
func NewKeybindingCreator(contexts *context.ContextTree) *KeybindingCreator {
|
||||||
return &KeybindingCreator{
|
return &KeybindingCreator{
|
||||||
contexts: contexts,
|
contexts: contexts,
|
||||||
getKey: getKey,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ func (self *KeybindingCreator) call(customCommand config.CustomCommand, handler
|
|||||||
|
|
||||||
return &types.Binding{
|
return &types.Binding{
|
||||||
ViewName: viewName,
|
ViewName: viewName,
|
||||||
Key: self.getKey(customCommand.Key),
|
Key: keybindings.GetKey(customCommand.Key),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: handler,
|
Handler: handler,
|
||||||
Description: description,
|
Description: description,
|
||||||
|
@@ -64,6 +64,22 @@ func (gui *Gui) newStringTaskWithoutScroll(view *gocui.View, str string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) newStringTaskWithScroll(view *gocui.View, str string, originX int, originY int) error {
|
||||||
|
manager := gui.getManager(view)
|
||||||
|
|
||||||
|
f := func(stop chan struct{}) error {
|
||||||
|
gui.setViewContent(view, str)
|
||||||
|
_ = view.SetOrigin(originX, originY)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := manager.NewTask(f, ""); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) newStringTaskWithKey(view *gocui.View, str string, key string) error {
|
func (gui *Gui) newStringTaskWithKey(view *gocui.View, str string, key string) error {
|
||||||
manager := gui.getManager(view)
|
manager := gui.getManager(view)
|
||||||
|
|
||||||
|
@@ -1,13 +1,12 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/common"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
|
"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -160,11 +159,11 @@ type Model struct {
|
|||||||
// if you add a new mutex here be sure to instantiate it. We're using pointers to
|
// if you add a new mutex here be sure to instantiate it. We're using pointers to
|
||||||
// mutexes so that we can pass the mutexes to controllers.
|
// mutexes so that we can pass the mutexes to controllers.
|
||||||
type Mutexes struct {
|
type Mutexes struct {
|
||||||
RefreshingFilesMutex *sync.Mutex
|
RefreshingFilesMutex *deadlock.Mutex
|
||||||
RefreshingStatusMutex *sync.Mutex
|
RefreshingStatusMutex *deadlock.Mutex
|
||||||
SyncMutex *sync.Mutex
|
SyncMutex *deadlock.Mutex
|
||||||
LocalCommitsMutex *sync.Mutex
|
LocalCommitsMutex *deadlock.Mutex
|
||||||
SubprocessMutex *sync.Mutex
|
SubprocessMutex *deadlock.Mutex
|
||||||
PopupMutex *sync.Mutex
|
PopupMutex *deadlock.Mutex
|
||||||
PtyMutex *sync.Mutex
|
PtyMutex *deadlock.Mutex
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,10 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContextKind int
|
type ContextKind int
|
||||||
@@ -106,7 +105,7 @@ type IPatchExplorerContext interface {
|
|||||||
Focus() error
|
Focus() error
|
||||||
GetContentToRender(isFocused bool) string
|
GetContentToRender(isFocused bool) string
|
||||||
NavigateTo(isFocused bool, selectedLineIdx int) error
|
NavigateTo(isFocused bool, selectedLineIdx int) error
|
||||||
GetMutex() *sync.Mutex
|
GetMutex() *deadlock.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type IViewTrait interface {
|
type IViewTrait interface {
|
||||||
|
@@ -16,6 +16,7 @@ const (
|
|||||||
SUBMODULES
|
SUBMODULES
|
||||||
STAGING
|
STAGING
|
||||||
PATCH_BUILDING
|
PATCH_BUILDING
|
||||||
|
MERGE_CONFLICTS
|
||||||
COMMIT_FILES
|
COMMIT_FILES
|
||||||
// not actually a view. Will refactor this later
|
// not actually a view. Will refactor this later
|
||||||
BISECT_INFO
|
BISECT_INFO
|
||||||
|
@@ -58,7 +58,7 @@ func (gui *Gui) startUpdating(newVersion string) {
|
|||||||
func (gui *Gui) onUpdateFinish(statusId int, err error) error {
|
func (gui *Gui) onUpdateFinish(statusId int, err error) error {
|
||||||
gui.State.Updating = false
|
gui.State.Updating = false
|
||||||
gui.statusManager.removeStatus(statusId)
|
gui.statusManager.removeStatus(statusId)
|
||||||
gui.OnUIThread(func() error {
|
gui.c.OnUIThread(func() error {
|
||||||
_ = gui.renderString(gui.Views.AppStatus, "")
|
_ = gui.renderString(gui.Views.AppStatus, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMessage := utils.ResolvePlaceholderString(
|
errMessage := utils.ResolvePlaceholderString(
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/spkg/bom"
|
"github.com/spkg/bom"
|
||||||
@@ -99,13 +100,13 @@ func (gui *Gui) globalOptionsMap() map[string]string {
|
|||||||
keybindingConfig := gui.c.UserConfig.Keybinding
|
keybindingConfig := gui.c.UserConfig.Keybinding
|
||||||
|
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
fmt.Sprintf("%s/%s", gui.getKeyDisplay(keybindingConfig.Universal.ScrollUpMain), gui.getKeyDisplay(keybindingConfig.Universal.ScrollDownMain)): gui.c.Tr.LcScroll,
|
fmt.Sprintf("%s/%s", keybindings.Label(keybindingConfig.Universal.ScrollUpMain), keybindings.Label(keybindingConfig.Universal.ScrollDownMain)): gui.c.Tr.LcScroll,
|
||||||
fmt.Sprintf("%s %s %s %s", gui.getKeyDisplay(keybindingConfig.Universal.PrevBlock), gui.getKeyDisplay(keybindingConfig.Universal.NextBlock), gui.getKeyDisplay(keybindingConfig.Universal.PrevItem), gui.getKeyDisplay(keybindingConfig.Universal.NextItem)): gui.c.Tr.LcNavigate,
|
fmt.Sprintf("%s %s %s %s", keybindings.Label(keybindingConfig.Universal.PrevBlock), keybindings.Label(keybindingConfig.Universal.NextBlock), keybindings.Label(keybindingConfig.Universal.PrevItem), keybindings.Label(keybindingConfig.Universal.NextItem)): gui.c.Tr.LcNavigate,
|
||||||
gui.getKeyDisplay(keybindingConfig.Universal.Return): gui.c.Tr.LcCancel,
|
keybindings.Label(keybindingConfig.Universal.Return): gui.c.Tr.LcCancel,
|
||||||
gui.getKeyDisplay(keybindingConfig.Universal.Quit): gui.c.Tr.LcQuit,
|
keybindings.Label(keybindingConfig.Universal.Quit): gui.c.Tr.LcQuit,
|
||||||
gui.getKeyDisplay(keybindingConfig.Universal.OptionMenu): gui.c.Tr.LcMenu,
|
keybindings.Label(keybindingConfig.Universal.OptionMenu): gui.c.Tr.LcMenu,
|
||||||
fmt.Sprintf("%s-%s", gui.getKeyDisplay(keybindingConfig.Universal.JumpToBlock[0]), gui.getKeyDisplay(keybindingConfig.Universal.JumpToBlock[len(keybindingConfig.Universal.JumpToBlock)-1])): gui.c.Tr.LcJump,
|
fmt.Sprintf("%s-%s", keybindings.Label(keybindingConfig.Universal.JumpToBlock[0]), keybindings.Label(keybindingConfig.Universal.JumpToBlock[len(keybindingConfig.Universal.JumpToBlock)-1])): gui.c.Tr.LcJump,
|
||||||
fmt.Sprintf("%s/%s", gui.getKeyDisplay(keybindingConfig.Universal.ScrollLeft), gui.getKeyDisplay(keybindingConfig.Universal.ScrollRight)): gui.c.Tr.LcScrollLeftRight,
|
fmt.Sprintf("%s/%s", keybindings.Label(keybindingConfig.Universal.ScrollLeft), keybindings.Label(keybindingConfig.Universal.ScrollRight)): gui.c.Tr.LcScrollLeftRight,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,5 +193,5 @@ func getTabbedView(gui *Gui) *gocui.View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) render() {
|
func (gui *Gui) render() {
|
||||||
gui.OnUIThread(func() error { return nil })
|
gui.c.OnUIThread(func() error { return nil })
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ type Views struct {
|
|||||||
StagingSecondary *gocui.View
|
StagingSecondary *gocui.View
|
||||||
PatchBuilding *gocui.View
|
PatchBuilding *gocui.View
|
||||||
PatchBuildingSecondary *gocui.View
|
PatchBuildingSecondary *gocui.View
|
||||||
Merging *gocui.View
|
MergeConflicts *gocui.View
|
||||||
|
|
||||||
Options *gocui.View
|
Options *gocui.View
|
||||||
Confirmation *gocui.View
|
Confirmation *gocui.View
|
||||||
@@ -74,7 +74,7 @@ func (gui *Gui) orderedViewNameMappings() []viewNameMapping {
|
|||||||
{viewPtr: &gui.Views.StagingSecondary, name: "stagingSecondary"},
|
{viewPtr: &gui.Views.StagingSecondary, name: "stagingSecondary"},
|
||||||
{viewPtr: &gui.Views.PatchBuilding, name: "patchBuilding"},
|
{viewPtr: &gui.Views.PatchBuilding, name: "patchBuilding"},
|
||||||
{viewPtr: &gui.Views.PatchBuildingSecondary, name: "patchBuildingSecondary"},
|
{viewPtr: &gui.Views.PatchBuildingSecondary, name: "patchBuildingSecondary"},
|
||||||
{viewPtr: &gui.Views.Merging, name: "merging"},
|
{viewPtr: &gui.Views.MergeConflicts, name: "mergeConflicts"},
|
||||||
{viewPtr: &gui.Views.Secondary, name: "secondary"},
|
{viewPtr: &gui.Views.Secondary, name: "secondary"},
|
||||||
{viewPtr: &gui.Views.Main, name: "main"},
|
{viewPtr: &gui.Views.Main, name: "main"},
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ func (gui *Gui) createAllViews() error {
|
|||||||
gui.Views.Files.Title = gui.c.Tr.FilesTitle
|
gui.Views.Files.Title = gui.c.Tr.FilesTitle
|
||||||
gui.Views.Files.FgColor = theme.GocuiDefaultTextColor
|
gui.Views.Files.FgColor = theme.GocuiDefaultTextColor
|
||||||
|
|
||||||
for _, view := range []*gocui.View{gui.Views.Main, gui.Views.Secondary, gui.Views.Staging, gui.Views.StagingSecondary, gui.Views.PatchBuilding, gui.Views.PatchBuildingSecondary, gui.Views.Merging} {
|
for _, view := range []*gocui.View{gui.Views.Main, gui.Views.Secondary, gui.Views.Staging, gui.Views.StagingSecondary, gui.Views.PatchBuilding, gui.Views.PatchBuildingSecondary, gui.Views.MergeConflicts} {
|
||||||
view.Title = gui.c.Tr.DiffTitle
|
view.Title = gui.c.Tr.DiffTitle
|
||||||
view.Wrap = true
|
view.Wrap = true
|
||||||
view.FgColor = theme.GocuiDefaultTextColor
|
view.FgColor = theme.GocuiDefaultTextColor
|
||||||
@@ -175,9 +175,9 @@ func (gui *Gui) createAllViews() error {
|
|||||||
gui.Views.PatchBuildingSecondary.Highlight = true
|
gui.Views.PatchBuildingSecondary.Highlight = true
|
||||||
gui.Views.PatchBuildingSecondary.Wrap = true
|
gui.Views.PatchBuildingSecondary.Wrap = true
|
||||||
|
|
||||||
gui.Views.Merging.Title = gui.c.Tr.MergeConflictsTitle
|
gui.Views.MergeConflicts.Title = gui.c.Tr.MergeConflictsTitle
|
||||||
gui.Views.Merging.Highlight = true
|
gui.Views.MergeConflicts.Highlight = true
|
||||||
gui.Views.Merging.Wrap = true
|
gui.Views.MergeConflicts.Wrap = false
|
||||||
|
|
||||||
gui.Views.Limit.Title = gui.c.Tr.NotEnoughSpace
|
gui.Views.Limit.Title = gui.c.Tr.NotEnoughSpace
|
||||||
gui.Views.Limit.Wrap = true
|
gui.Views.Limit.Wrap = true
|
||||||
|
@@ -202,7 +202,7 @@ func RunTests(
|
|||||||
|
|
||||||
// validates that the actual and expected dirs have the same repo names (doesn't actually check the contents of the repos)
|
// validates that the actual and expected dirs have the same repo names (doesn't actually check the contents of the repos)
|
||||||
func validateSameRepos(expectedDir string, actualDir string) error {
|
func validateSameRepos(expectedDir string, actualDir string) error {
|
||||||
// iterate through each repo in the expected dir and comparet to the corresponding repo in the actual dir
|
// iterate through each repo in the expected dir and compare to the corresponding repo in the actual dir
|
||||||
expectedFiles, err := ioutil.ReadDir(expectedDir)
|
expectedFiles, err := ioutil.ReadDir(expectedDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -441,6 +441,13 @@ func generateSnapshots(actualDir string, expectedDir string) (string, string, er
|
|||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
err := os.RemoveAll(expectedDirCopyDir)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err := restoreSpecialPaths(expectedDirCopyDir); err != nil {
|
if err := restoreSpecialPaths(expectedDirCopyDir); err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
@@ -450,11 +457,6 @@ func generateSnapshots(actualDir string, expectedDir string) (string, string, er
|
|||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.RemoveAll(expectedDirCopyDir)
|
|
||||||
if err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return actual, expected, nil
|
return actual, expected, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,9 +1,8 @@
|
|||||||
package tasks
|
package tasks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// the purpose of an AsyncHandler is to ensure that if we have multiple long-running
|
// the purpose of an AsyncHandler is to ensure that if we have multiple long-running
|
||||||
@@ -17,13 +16,13 @@ import (
|
|||||||
type AsyncHandler struct {
|
type AsyncHandler struct {
|
||||||
currentId int
|
currentId int
|
||||||
lastId int
|
lastId int
|
||||||
mutex sync.Mutex
|
mutex deadlock.Mutex
|
||||||
onReject func()
|
onReject func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAsyncHandler() *AsyncHandler {
|
func NewAsyncHandler() *AsyncHandler {
|
||||||
return &AsyncHandler{
|
return &AsyncHandler{
|
||||||
mutex: sync.Mutex{},
|
mutex: deadlock.Mutex{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
"github.com/sasha-s/go-deadlock"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,8 +35,8 @@ type ViewBufferManager struct {
|
|||||||
// this is what we write the output of the task to. It's typically a view
|
// this is what we write the output of the task to. It's typically a view
|
||||||
writer io.Writer
|
writer io.Writer
|
||||||
|
|
||||||
waitingMutex sync.Mutex
|
waitingMutex deadlock.Mutex
|
||||||
taskIDMutex sync.Mutex
|
taskIDMutex deadlock.Mutex
|
||||||
Log *logrus.Entry
|
Log *logrus.Entry
|
||||||
newTaskID int
|
newTaskID int
|
||||||
readLines chan int
|
readLines chan int
|
||||||
@@ -126,7 +127,7 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
loadingMutex := sync.Mutex{}
|
loadingMutex := deadlock.Mutex{}
|
||||||
|
|
||||||
// not sure if it's the right move to redefine this or not
|
// not sure if it's the right move to redefine this or not
|
||||||
self.readLines = make(chan int, 1024)
|
self.readLines = make(chan int, 1024)
|
||||||
|
31
pkg/utils/once_writer.go
Normal file
31
pkg/utils/once_writer.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This wraps a writer and ensures that before we actually write anything we call a given function first
|
||||||
|
|
||||||
|
type OnceWriter struct {
|
||||||
|
writer io.Writer
|
||||||
|
once sync.Once
|
||||||
|
f func()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ io.Writer = &OnceWriter{}
|
||||||
|
|
||||||
|
func NewOnceWriter(writer io.Writer, f func()) *OnceWriter {
|
||||||
|
return &OnceWriter{
|
||||||
|
writer: writer,
|
||||||
|
f: f,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *OnceWriter) Write(p []byte) (n int, err error) {
|
||||||
|
self.once.Do(func() {
|
||||||
|
self.f()
|
||||||
|
})
|
||||||
|
|
||||||
|
return self.writer.Write(p)
|
||||||
|
}
|
19
pkg/utils/once_writer_test.go
Normal file
19
pkg/utils/once_writer_test.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestOnceWriter(t *testing.T) {
|
||||||
|
innerWriter := bytes.NewBuffer(nil)
|
||||||
|
counter := 0
|
||||||
|
onceWriter := NewOnceWriter(innerWriter, func() {
|
||||||
|
counter += 1
|
||||||
|
})
|
||||||
|
_, _ = onceWriter.Write([]byte("hello"))
|
||||||
|
_, _ = onceWriter.Write([]byte("hello"))
|
||||||
|
if counter != 1 {
|
||||||
|
t.Errorf("expected counter to be 1, got %d", counter)
|
||||||
|
}
|
||||||
|
}
|
4
vendor/github.com/petermattis/goid/.gitignore
generated
vendored
Normal file
4
vendor/github.com/petermattis/goid/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
*~
|
||||||
|
*.test
|
||||||
|
.*.swp
|
||||||
|
.DS_Store
|
202
vendor/github.com/petermattis/goid/LICENSE
generated
vendored
Normal file
202
vendor/github.com/petermattis/goid/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright {yyyy} {name of copyright owner}
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
5
vendor/github.com/petermattis/goid/README.md
generated
vendored
Normal file
5
vendor/github.com/petermattis/goid/README.md
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# goid [](https://travis-ci.org/petermattis/goid)
|
||||||
|
|
||||||
|
Programatically retrieve the current goroutine's ID. See [the CI
|
||||||
|
configuration](.travis.yml) for supported Go versions. In addition,
|
||||||
|
gccgo 7.2.1 (Go 1.8.3) is supported.
|
35
vendor/github.com/petermattis/goid/goid.go
generated
vendored
Normal file
35
vendor/github.com/petermattis/goid/goid.go
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
// Copyright 2016 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExtractGID(s []byte) int64 {
|
||||||
|
s = s[len("goroutine "):]
|
||||||
|
s = s[:bytes.IndexByte(s, ' ')]
|
||||||
|
gid, _ := strconv.ParseInt(string(s), 10, 64)
|
||||||
|
return gid
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the goid from runtime.Stack() output. Slow, but it works.
|
||||||
|
func getSlow() int64 {
|
||||||
|
var buf [64]byte
|
||||||
|
return ExtractGID(buf[:runtime.Stack(buf[:], false)])
|
||||||
|
}
|
25
vendor/github.com/petermattis/goid/goid_gccgo.go
generated
vendored
Normal file
25
vendor/github.com/petermattis/goid/goid_gccgo.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright 2018 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
// +build gccgo
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
//extern runtime.getg
|
||||||
|
func getg() *g
|
||||||
|
|
||||||
|
func Get() int64 {
|
||||||
|
return getg().goid
|
||||||
|
}
|
23
vendor/github.com/petermattis/goid/goid_go1.3.c
generated
vendored
Normal file
23
vendor/github.com/petermattis/goid/goid_go1.3.c
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Copyright 2015 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
// +build !go1.4
|
||||||
|
|
||||||
|
#include <runtime.h>
|
||||||
|
|
||||||
|
void ·Get(int64 ret) {
|
||||||
|
ret = g->goid;
|
||||||
|
USED(&ret);
|
||||||
|
}
|
21
vendor/github.com/petermattis/goid/goid_go1.3.go
generated
vendored
Normal file
21
vendor/github.com/petermattis/goid/goid_go1.3.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2015 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
// +build !go1.4
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
// Get returns the id of the current goroutine.
|
||||||
|
func Get() int64
|
34
vendor/github.com/petermattis/goid/goid_go1.4.go
generated
vendored
Normal file
34
vendor/github.com/petermattis/goid/goid_go1.4.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2015 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
// +build go1.4,!go1.5
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
var pointerSize = unsafe.Sizeof(uintptr(0))
|
||||||
|
|
||||||
|
// Backdoor access to runtime·getg().
|
||||||
|
func getg() uintptr // in goid_go1.4.s
|
||||||
|
|
||||||
|
// Get returns the id of the current goroutine.
|
||||||
|
func Get() int64 {
|
||||||
|
// The goid is the 16th field in the G struct where each field is a
|
||||||
|
// pointer, uintptr or padded to that size. See runtime.h from the
|
||||||
|
// Go sources. I'm not aware of a cleaner way to determine the
|
||||||
|
// offset.
|
||||||
|
return *(*int64)(unsafe.Pointer(getg() + 16*pointerSize))
|
||||||
|
}
|
18
vendor/github.com/petermattis/goid/goid_go1.4.s
generated
vendored
Normal file
18
vendor/github.com/petermattis/goid/goid_go1.4.s
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2014 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Assembly to get into package runtime without using exported symbols.
|
||||||
|
// See https://github.com/golang/go/blob/release-branch.go1.4/misc/cgo/test/backdoor/thunk.s
|
||||||
|
|
||||||
|
// +build amd64 amd64p32 arm 386
|
||||||
|
// +build go1.4,!go1.5
|
||||||
|
|
||||||
|
#include "textflag.h"
|
||||||
|
|
||||||
|
#ifdef GOARCH_arm
|
||||||
|
#define JMP B
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TEXT ·getg(SB),NOSPLIT,$0-0
|
||||||
|
JMP runtime·getg(SB)
|
21
vendor/github.com/petermattis/goid/goid_go1.5_amd64.go
generated
vendored
Normal file
21
vendor/github.com/petermattis/goid/goid_go1.5_amd64.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2016 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
// +build amd64 amd64p32
|
||||||
|
// +build gc,go1.5
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
func Get() int64
|
29
vendor/github.com/petermattis/goid/goid_go1.5_amd64.s
generated
vendored
Normal file
29
vendor/github.com/petermattis/goid/goid_go1.5_amd64.s
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2016 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
// Assembly to mimic runtime.getg.
|
||||||
|
|
||||||
|
// +build amd64 amd64p32
|
||||||
|
// +build gc,go1.5
|
||||||
|
|
||||||
|
#include "go_asm.h"
|
||||||
|
#include "textflag.h"
|
||||||
|
|
||||||
|
// func Get() int64
|
||||||
|
TEXT ·Get(SB),NOSPLIT,$0-8
|
||||||
|
MOVQ (TLS), R14
|
||||||
|
MOVQ g_goid(R14), R13
|
||||||
|
MOVQ R13, ret+0(FP)
|
||||||
|
RET
|
26
vendor/github.com/petermattis/goid/goid_go1.5_arm.go
generated
vendored
Normal file
26
vendor/github.com/petermattis/goid/goid_go1.5_arm.go
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2016 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
// +build arm
|
||||||
|
// +build gc,go1.5
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
// Backdoor access to runtime·getg().
|
||||||
|
func getg() *g // in goid_go1.5plus.s
|
||||||
|
|
||||||
|
func Get() int64 {
|
||||||
|
return getg().goid
|
||||||
|
}
|
27
vendor/github.com/petermattis/goid/goid_go1.5_arm.s
generated
vendored
Normal file
27
vendor/github.com/petermattis/goid/goid_go1.5_arm.s
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2016 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
// Assembly to mimic runtime.getg.
|
||||||
|
// This should work on arm64 as well, but it hasn't been tested.
|
||||||
|
|
||||||
|
// +build arm
|
||||||
|
// +build gc,go1.5
|
||||||
|
|
||||||
|
#include "textflag.h"
|
||||||
|
|
||||||
|
// func getg() *g
|
||||||
|
TEXT ·getg(SB),NOSPLIT,$0-8
|
||||||
|
MOVW g, ret+0(FP)
|
||||||
|
RET
|
23
vendor/github.com/petermattis/goid/goid_slow.go
generated
vendored
Normal file
23
vendor/github.com/petermattis/goid/goid_slow.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Copyright 2016 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
// +build go1.4,!go1.5,!amd64,!amd64p32,!arm,!386 go1.5,!go1.6,!amd64,!amd64p32,!arm go1.6,!amd64,!amd64p32,!arm go1.9,!amd64,!amd64p32,!arm
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
// Get returns the id of the current goroutine.
|
||||||
|
func Get() int64 {
|
||||||
|
return getSlow()
|
||||||
|
}
|
16
vendor/github.com/petermattis/goid/runtime_gccgo_go1.8.go
generated
vendored
Normal file
16
vendor/github.com/petermattis/goid/runtime_gccgo_go1.8.go
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// +build gccgo,go1.8
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
// https://github.com/gcc-mirror/gcc/blob/gcc-7-branch/libgo/go/runtime/runtime2.go#L329-L422
|
||||||
|
|
||||||
|
type g struct {
|
||||||
|
_panic uintptr
|
||||||
|
_defer uintptr
|
||||||
|
m uintptr
|
||||||
|
syscallsp uintptr
|
||||||
|
syscallpc uintptr
|
||||||
|
param uintptr
|
||||||
|
atomicstatus uint32
|
||||||
|
goid int64 // Here it is!
|
||||||
|
}
|
56
vendor/github.com/petermattis/goid/runtime_go1.5.go
generated
vendored
Normal file
56
vendor/github.com/petermattis/goid/runtime_go1.5.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
// Copyright 2016 Peter Mattis.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
// implied. See the License for the specific language governing
|
||||||
|
// permissions and limitations under the License. See the AUTHORS file
|
||||||
|
// for names of contributors.
|
||||||
|
|
||||||
|
// +build go1.5,!go1.6
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
// Just enough of the structs from runtime/runtime2.go to get the offset to goid.
|
||||||
|
// See https://github.com/golang/go/blob/release-branch.go1.5/src/runtime/runtime2.go
|
||||||
|
|
||||||
|
type stack struct {
|
||||||
|
lo uintptr
|
||||||
|
hi uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type gobuf struct {
|
||||||
|
sp uintptr
|
||||||
|
pc uintptr
|
||||||
|
g uintptr
|
||||||
|
ctxt uintptr
|
||||||
|
ret uintptr
|
||||||
|
lr uintptr
|
||||||
|
bp uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type g struct {
|
||||||
|
stack stack
|
||||||
|
stackguard0 uintptr
|
||||||
|
stackguard1 uintptr
|
||||||
|
|
||||||
|
_panic uintptr
|
||||||
|
_defer uintptr
|
||||||
|
m uintptr
|
||||||
|
stackAlloc uintptr
|
||||||
|
sched gobuf
|
||||||
|
syscallsp uintptr
|
||||||
|
syscallpc uintptr
|
||||||
|
stkbar []uintptr
|
||||||
|
stkbarPos uintptr
|
||||||
|
param uintptr
|
||||||
|
atomicstatus uint32
|
||||||
|
stackLock uint32
|
||||||
|
goid int64 // Here it is!
|
||||||
|
}
|
42
vendor/github.com/petermattis/goid/runtime_go1.6.go
generated
vendored
Normal file
42
vendor/github.com/petermattis/goid/runtime_go1.6.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// +build gc,go1.6,!go1.9
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
// Just enough of the structs from runtime/runtime2.go to get the offset to goid.
|
||||||
|
// See https://github.com/golang/go/blob/release-branch.go1.6/src/runtime/runtime2.go
|
||||||
|
|
||||||
|
type stack struct {
|
||||||
|
lo uintptr
|
||||||
|
hi uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type gobuf struct {
|
||||||
|
sp uintptr
|
||||||
|
pc uintptr
|
||||||
|
g uintptr
|
||||||
|
ctxt uintptr
|
||||||
|
ret uintptr
|
||||||
|
lr uintptr
|
||||||
|
bp uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type g struct {
|
||||||
|
stack stack
|
||||||
|
stackguard0 uintptr
|
||||||
|
stackguard1 uintptr
|
||||||
|
|
||||||
|
_panic uintptr
|
||||||
|
_defer uintptr
|
||||||
|
m uintptr
|
||||||
|
stackAlloc uintptr
|
||||||
|
sched gobuf
|
||||||
|
syscallsp uintptr
|
||||||
|
syscallpc uintptr
|
||||||
|
stkbar []uintptr
|
||||||
|
stkbarPos uintptr
|
||||||
|
stktopsp uintptr
|
||||||
|
param uintptr
|
||||||
|
atomicstatus uint32
|
||||||
|
stackLock uint32
|
||||||
|
goid int64 // Here it is!
|
||||||
|
}
|
36
vendor/github.com/petermattis/goid/runtime_go1.9.go
generated
vendored
Normal file
36
vendor/github.com/petermattis/goid/runtime_go1.9.go
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// +build gc,go1.9
|
||||||
|
|
||||||
|
package goid
|
||||||
|
|
||||||
|
type stack struct {
|
||||||
|
lo uintptr
|
||||||
|
hi uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type gobuf struct {
|
||||||
|
sp uintptr
|
||||||
|
pc uintptr
|
||||||
|
g uintptr
|
||||||
|
ctxt uintptr
|
||||||
|
ret uintptr
|
||||||
|
lr uintptr
|
||||||
|
bp uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
type g struct {
|
||||||
|
stack stack
|
||||||
|
stackguard0 uintptr
|
||||||
|
stackguard1 uintptr
|
||||||
|
|
||||||
|
_panic uintptr
|
||||||
|
_defer uintptr
|
||||||
|
m uintptr
|
||||||
|
sched gobuf
|
||||||
|
syscallsp uintptr
|
||||||
|
syscallpc uintptr
|
||||||
|
stktopsp uintptr
|
||||||
|
param uintptr
|
||||||
|
atomicstatus uint32
|
||||||
|
stackLock uint32
|
||||||
|
goid int64 // Here it is!
|
||||||
|
}
|
201
vendor/github.com/sasha-s/go-deadlock/LICENSE
generated
vendored
Normal file
201
vendor/github.com/sasha-s/go-deadlock/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright {yyyy} {name of copyright owner}
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
187
vendor/github.com/sasha-s/go-deadlock/Readme.md
generated
vendored
Normal file
187
vendor/github.com/sasha-s/go-deadlock/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
# Online deadlock detection in go (golang). [](https://wandbox.org/permlink/hJc6QCZowxbNm9WW) [](https://godoc.org/github.com/sasha-s/go-deadlock) [](https://travis-ci.org/sasha-s/go-deadlock) [](https://codecov.io/gh/sasha-s/go-deadlock) [](https://github.com/sasha-s/go-deadlock/releases) [](https://goreportcard.com/report/github.com/sasha-s/go-deadlock) [](https://opensource.org/licenses/Apache-2.0)
|
||||||
|
|
||||||
|
## Why
|
||||||
|
Deadlocks happen and are painful to debug.
|
||||||
|
|
||||||
|
## What
|
||||||
|
go-deadlock provides (RW)Mutex drop-in replacements for sync.(RW)Mutex.
|
||||||
|
It would not work if you create a spaghetti of channels.
|
||||||
|
Mutexes only.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
```sh
|
||||||
|
go get github.com/sasha-s/go-deadlock/...
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
```go
|
||||||
|
import "github.com/sasha-s/go-deadlock"
|
||||||
|
var mu deadlock.Mutex
|
||||||
|
// Use normally, it works exactly like sync.Mutex does.
|
||||||
|
mu.Lock()
|
||||||
|
|
||||||
|
defer mu.Unlock()
|
||||||
|
// Or
|
||||||
|
var rw deadlock.RWMutex
|
||||||
|
rw.RLock()
|
||||||
|
defer rw.RUnlock()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deadlocks
|
||||||
|
One of the most common sources of deadlocks is inconsistent lock ordering:
|
||||||
|
say, you have two mutexes A and B, and in some goroutines you have
|
||||||
|
```go
|
||||||
|
A.Lock() // defer A.Unlock() or similar.
|
||||||
|
...
|
||||||
|
B.Lock() // defer B.Unlock() or similar.
|
||||||
|
```
|
||||||
|
And in another goroutine the order of locks is reversed:
|
||||||
|
```go
|
||||||
|
B.Lock() // defer B.Unlock() or similar.
|
||||||
|
...
|
||||||
|
A.Lock() // defer A.Unlock() or similar.
|
||||||
|
```
|
||||||
|
|
||||||
|
Another common sources of deadlocks is duplicate take a lock in a goroutine:
|
||||||
|
```
|
||||||
|
A.Rlock() or lock()
|
||||||
|
|
||||||
|
A.lock() or A.RLock()
|
||||||
|
```
|
||||||
|
|
||||||
|
This does not guarantee a deadlock (maybe the goroutines above can never be running at the same time), but it usually a design flaw at least.
|
||||||
|
|
||||||
|
go-deadlock can detect such cases (unless you cross goroutine boundary - say lock A, then spawn a goroutine, block until it is singals, and lock B inside of the goroutine), even if the deadlock itself happens very infrequently and is painful to reproduce!
|
||||||
|
|
||||||
|
Each time go-deadlock sees a lock attempt for lock B, it records the order A before B, for each lock that is currently being held in the same goroutine, and it prints (and exits the program by default) when it sees the locking order being violated.
|
||||||
|
|
||||||
|
In addition, if it sees that we are waiting on a lock for a long time (opts.DeadlockTimeout, 30 seconds by default), it reports a potential deadlock, also printing the stacktrace for a goroutine that is currently holding the lock we are desperately trying to grab.
|
||||||
|
|
||||||
|
|
||||||
|
## Sample output
|
||||||
|
#### Inconsistent lock ordering:
|
||||||
|
```
|
||||||
|
POTENTIAL DEADLOCK: Inconsistent locking. saw this ordering in one goroutine:
|
||||||
|
happened before
|
||||||
|
inmem.go:623 bttest.(*server).ReadModifyWriteRow { r.mu.Lock() } <<<<<
|
||||||
|
inmem_test.go:118 bttest.TestConcurrentMutationsReadModifyAndGC.func4 { _, _ = s.ReadModifyWriteRow(ctx, rmw()) }
|
||||||
|
|
||||||
|
happened after
|
||||||
|
inmem.go:629 bttest.(*server).ReadModifyWriteRow { tbl.mu.RLock() } <<<<<
|
||||||
|
inmem_test.go:118 bttest.TestConcurrentMutationsReadModifyAndGC.func4 { _, _ = s.ReadModifyWriteRow(ctx, rmw()) }
|
||||||
|
|
||||||
|
in another goroutine: happened before
|
||||||
|
inmem.go:799 bttest.(*table).gc { t.mu.RLock() } <<<<<
|
||||||
|
inmem_test.go:125 bttest.TestConcurrentMutationsReadModifyAndGC.func5 { tbl.gc() }
|
||||||
|
|
||||||
|
happend after
|
||||||
|
inmem.go:814 bttest.(*table).gc { r.mu.Lock() } <<<<<
|
||||||
|
inmem_test.go:125 bttest.TestConcurrentMutationsReadModifyAndGC.func5 { tbl.gc() }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Waiting for a lock for a long time:
|
||||||
|
|
||||||
|
```
|
||||||
|
POTENTIAL DEADLOCK:
|
||||||
|
Previous place where the lock was grabbed
|
||||||
|
goroutine 240 lock 0xc820160440
|
||||||
|
inmem.go:799 bttest.(*table).gc { t.mu.RLock() } <<<<<
|
||||||
|
inmem_test.go:125 bttest.TestConcurrentMutationsReadModifyAndGC.func5 { tbl.gc() }
|
||||||
|
|
||||||
|
Have been trying to lock it again for more than 40ms
|
||||||
|
goroutine 68 lock 0xc820160440
|
||||||
|
inmem.go:785 bttest.(*table).mutableRow { t.mu.Lock() } <<<<<
|
||||||
|
inmem.go:428 bttest.(*server).MutateRow { r := tbl.mutableRow(string(req.RowKey)) }
|
||||||
|
inmem_test.go:111 bttest.TestConcurrentMutationsReadModifyAndGC.func3 { s.MutateRow(ctx, req) }
|
||||||
|
|
||||||
|
|
||||||
|
Here is what goroutine 240 doing now
|
||||||
|
goroutine 240 [select]:
|
||||||
|
github.com/sasha-s/go-deadlock.lock(0xc82028ca10, 0x5189e0, 0xc82013a9b0)
|
||||||
|
/Users/sasha/go/src/github.com/sasha-s/go-deadlock/deadlock.go:163 +0x1640
|
||||||
|
github.com/sasha-s/go-deadlock.(*Mutex).Lock(0xc82013a9b0)
|
||||||
|
/Users/sasha/go/src/github.com/sasha-s/go-deadlock/deadlock.go:54 +0x86
|
||||||
|
google.golang.org/cloud/bigtable/bttest.(*table).gc(0xc820160440)
|
||||||
|
/Users/sasha/go/src/google.golang.org/cloud/bigtable/bttest/inmem.go:814 +0x28d
|
||||||
|
google.golang.org/cloud/bigtable/bttest.TestConcurrentMutationsReadModifyAndGC.func5(0xc82015c760, 0xc820160440) /Users/sasha/go/src/google.golang.org/cloud/bigtable/bttest/inmem_test.go:125 +0x48
|
||||||
|
created by google.golang.org/cloud/bigtable/bttest.TestConcurrentMutationsReadModifyAndGC
|
||||||
|
/Users/sasha/go/src/google.golang.org/cloud/bigtable/bttest/inmem_test.go:126 +0xb6f
|
||||||
|
```
|
||||||
|
|
||||||
|
## Used in
|
||||||
|
[cockroachdb: Potential deadlock between Gossip.SetStorage and Node.gossipStores](https://github.com/cockroachdb/cockroach/issues/7972)
|
||||||
|
|
||||||
|
[bigtable/bttest: A race between GC and row mutations](https://code-review.googlesource.com#/c/5301/)
|
||||||
|
|
||||||
|
## Need a mutex that works with net.context?
|
||||||
|
I have [one](https://github.com/sasha-s/go-csync).
|
||||||
|
|
||||||
|
## Grabbing an RLock twice from the same goroutine
|
||||||
|
This is, surprisingly, not a good idea!
|
||||||
|
|
||||||
|
From [RWMutex](https://golang.org/pkg/sync/#RWMutex) docs:
|
||||||
|
|
||||||
|
>If a goroutine holds a RWMutex for reading and another goroutine might call Lock, no goroutine should expect to be able to acquire a read lock until the initial read lock is released. In particular, this prohibits recursive read locking. This is to ensure that the lock eventually becomes available; a blocked Lock call excludes new readers from acquiring the lock.
|
||||||
|
|
||||||
|
|
||||||
|
The following code will deadlock — [run the example on playground](https://play.golang.org/p/AkL-W63nq5f) or [try it online with go-deadlock on wandbox](https://wandbox.org/permlink/JwnL0GMySBju4SII):
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var mu sync.RWMutex
|
||||||
|
|
||||||
|
chrlockTwice := make(chan struct{}) // Used to control rlockTwice
|
||||||
|
rlockTwice := func() {
|
||||||
|
mu.RLock()
|
||||||
|
fmt.Println("first Rlock succeeded")
|
||||||
|
<-chrlockTwice
|
||||||
|
<-chrlockTwice
|
||||||
|
fmt.Println("trying to Rlock again")
|
||||||
|
mu.RLock()
|
||||||
|
fmt.Println("second Rlock succeeded")
|
||||||
|
mu.RUnlock()
|
||||||
|
mu.RUnlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
chLock := make(chan struct{}) // Used to contol lock
|
||||||
|
lock := func() {
|
||||||
|
<-chLock
|
||||||
|
fmt.Println("about to Lock")
|
||||||
|
mu.Lock()
|
||||||
|
fmt.Println("Lock succeeded")
|
||||||
|
mu.Unlock()
|
||||||
|
<-chLock
|
||||||
|
}
|
||||||
|
|
||||||
|
control := func() {
|
||||||
|
chrlockTwice <- struct{}{}
|
||||||
|
chLock <- struct{}{}
|
||||||
|
|
||||||
|
close(chrlockTwice)
|
||||||
|
close(chLock)
|
||||||
|
}
|
||||||
|
|
||||||
|
go control()
|
||||||
|
go lock()
|
||||||
|
rlockTwice()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
## Configuring go-deadlock
|
||||||
|
|
||||||
|
Have a look at [Opts](https://pkg.go.dev/github.com/sasha-s/go-deadlock#pkg-variables).
|
||||||
|
|
||||||
|
* `Opts.Disable`: disables deadlock detection altogether
|
||||||
|
* `Opts.DisableLockOrderDetection`: disables lock order based deadlock detection.
|
||||||
|
* `Opts.DeadlockTimeout`: blocking on mutex for longer than DeadlockTimeout is considered a deadlock. ignored if negative
|
||||||
|
* `Opts.OnPotentialDeadlock`: callback for then deadlock is detected
|
||||||
|
* `Opts.MaxMapSize`: size of happens before // happens after table
|
||||||
|
* `Opts.PrintAllCurrentGoroutines`: dump stacktraces of all goroutines when inconsistent locking is detected, verbose
|
||||||
|
* `Opts.LogBuf`: where to write deadlock info/stacktraces
|
||||||
|
|
||||||
|
|
363
vendor/github.com/sasha-s/go-deadlock/deadlock.go
generated
vendored
Normal file
363
vendor/github.com/sasha-s/go-deadlock/deadlock.go
generated
vendored
Normal file
@@ -0,0 +1,363 @@
|
|||||||
|
package deadlock
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/petermattis/goid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Opts control how deadlock detection behaves.
|
||||||
|
// Options are supposed to be set once at a startup (say, when parsing flags).
|
||||||
|
var Opts = struct {
|
||||||
|
// Mutex/RWMutex would work exactly as their sync counterparts
|
||||||
|
// -- almost no runtime penalty, no deadlock detection if Disable == true.
|
||||||
|
Disable bool
|
||||||
|
// Would disable lock order based deadlock detection if DisableLockOrderDetection == true.
|
||||||
|
DisableLockOrderDetection bool
|
||||||
|
// Waiting for a lock for longer than DeadlockTimeout is considered a deadlock.
|
||||||
|
// Ignored is DeadlockTimeout <= 0.
|
||||||
|
DeadlockTimeout time.Duration
|
||||||
|
// OnPotentialDeadlock is called each time a potential deadlock is detected -- either based on
|
||||||
|
// lock order or on lock wait time.
|
||||||
|
OnPotentialDeadlock func()
|
||||||
|
// Will keep MaxMapSize lock pairs (happens before // happens after) in the map.
|
||||||
|
// The map resets once the threshold is reached.
|
||||||
|
MaxMapSize int
|
||||||
|
// Will dump stacktraces of all goroutines when inconsistent locking is detected.
|
||||||
|
PrintAllCurrentGoroutines bool
|
||||||
|
mu *sync.Mutex // Protects the LogBuf.
|
||||||
|
// Will print deadlock info to log buffer.
|
||||||
|
LogBuf io.Writer
|
||||||
|
}{
|
||||||
|
DeadlockTimeout: time.Second * 30,
|
||||||
|
OnPotentialDeadlock: func() {
|
||||||
|
os.Exit(2)
|
||||||
|
},
|
||||||
|
MaxMapSize: 1024 * 64,
|
||||||
|
mu: &sync.Mutex{},
|
||||||
|
LogBuf: os.Stderr,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cond is sync.Cond wrapper
|
||||||
|
type Cond struct {
|
||||||
|
sync.Cond
|
||||||
|
}
|
||||||
|
|
||||||
|
// Locker is sync.Locker wrapper
|
||||||
|
type Locker struct {
|
||||||
|
sync.Locker
|
||||||
|
}
|
||||||
|
|
||||||
|
// Once is sync.Once wrapper
|
||||||
|
type Once struct {
|
||||||
|
sync.Once
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pool is sync.Poll wrapper
|
||||||
|
type Pool struct {
|
||||||
|
sync.Pool
|
||||||
|
}
|
||||||
|
|
||||||
|
// WaitGroup is sync.WaitGroup wrapper
|
||||||
|
type WaitGroup struct {
|
||||||
|
sync.WaitGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
// A Mutex is a drop-in replacement for sync.Mutex.
|
||||||
|
// Performs deadlock detection unless disabled in Opts.
|
||||||
|
type Mutex struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock locks the mutex.
|
||||||
|
// If the lock is already in use, the calling goroutine
|
||||||
|
// blocks until the mutex is available.
|
||||||
|
//
|
||||||
|
// Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf,
|
||||||
|
// calling Opts.OnPotentialDeadlock on each occasion.
|
||||||
|
func (m *Mutex) Lock() {
|
||||||
|
lock(m.mu.Lock, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unlock unlocks the mutex.
|
||||||
|
// It is a run-time error if m is not locked on entry to Unlock.
|
||||||
|
//
|
||||||
|
// A locked Mutex is not associated with a particular goroutine.
|
||||||
|
// It is allowed for one goroutine to lock a Mutex and then
|
||||||
|
// arrange for another goroutine to unlock it.
|
||||||
|
func (m *Mutex) Unlock() {
|
||||||
|
m.mu.Unlock()
|
||||||
|
if !Opts.Disable {
|
||||||
|
postUnlock(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// An RWMutex is a drop-in replacement for sync.RWMutex.
|
||||||
|
// Performs deadlock detection unless disabled in Opts.
|
||||||
|
type RWMutex struct {
|
||||||
|
mu sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock locks rw for writing.
|
||||||
|
// If the lock is already locked for reading or writing,
|
||||||
|
// Lock blocks until the lock is available.
|
||||||
|
// To ensure that the lock eventually becomes available,
|
||||||
|
// a blocked Lock call excludes new readers from acquiring
|
||||||
|
// the lock.
|
||||||
|
//
|
||||||
|
// Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf,
|
||||||
|
// calling Opts.OnPotentialDeadlock on each occasion.
|
||||||
|
func (m *RWMutex) Lock() {
|
||||||
|
lock(m.mu.Lock, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unlock unlocks the mutex for writing. It is a run-time error if rw is
|
||||||
|
// not locked for writing on entry to Unlock.
|
||||||
|
//
|
||||||
|
// As with Mutexes, a locked RWMutex is not associated with a particular
|
||||||
|
// goroutine. One goroutine may RLock (Lock) an RWMutex and then
|
||||||
|
// arrange for another goroutine to RUnlock (Unlock) it.
|
||||||
|
func (m *RWMutex) Unlock() {
|
||||||
|
m.mu.Unlock()
|
||||||
|
if !Opts.Disable {
|
||||||
|
postUnlock(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RLock locks the mutex for reading.
|
||||||
|
//
|
||||||
|
// Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf,
|
||||||
|
// calling Opts.OnPotentialDeadlock on each occasion.
|
||||||
|
func (m *RWMutex) RLock() {
|
||||||
|
lock(m.mu.RLock, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RUnlock undoes a single RLock call;
|
||||||
|
// it does not affect other simultaneous readers.
|
||||||
|
// It is a run-time error if rw is not locked for reading
|
||||||
|
// on entry to RUnlock.
|
||||||
|
func (m *RWMutex) RUnlock() {
|
||||||
|
m.mu.RUnlock()
|
||||||
|
if !Opts.Disable {
|
||||||
|
postUnlock(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RLocker returns a Locker interface that implements
|
||||||
|
// the Lock and Unlock methods by calling RLock and RUnlock.
|
||||||
|
func (m *RWMutex) RLocker() sync.Locker {
|
||||||
|
return (*rlocker)(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func preLock(stack []uintptr, p interface{}) {
|
||||||
|
lo.preLock(stack, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func postLock(stack []uintptr, p interface{}) {
|
||||||
|
lo.postLock(stack, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func postUnlock(p interface{}) {
|
||||||
|
lo.postUnlock(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func lock(lockFn func(), ptr interface{}) {
|
||||||
|
if Opts.Disable {
|
||||||
|
lockFn()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stack := callers(1)
|
||||||
|
preLock(stack, ptr)
|
||||||
|
if Opts.DeadlockTimeout <= 0 {
|
||||||
|
lockFn()
|
||||||
|
} else {
|
||||||
|
ch := make(chan struct{})
|
||||||
|
currentID := goid.Get()
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
t := time.NewTimer(Opts.DeadlockTimeout)
|
||||||
|
defer t.Stop() // This runs after the losure finishes, but it's OK.
|
||||||
|
select {
|
||||||
|
case <-t.C:
|
||||||
|
lo.mu.Lock()
|
||||||
|
prev, ok := lo.cur[ptr]
|
||||||
|
if !ok {
|
||||||
|
lo.mu.Unlock()
|
||||||
|
break // Nobody seems to be holding the lock, try again.
|
||||||
|
}
|
||||||
|
Opts.mu.Lock()
|
||||||
|
fmt.Fprintln(Opts.LogBuf, header)
|
||||||
|
fmt.Fprintln(Opts.LogBuf, "Previous place where the lock was grabbed")
|
||||||
|
fmt.Fprintf(Opts.LogBuf, "goroutine %v lock %p\n", prev.gid, ptr)
|
||||||
|
printStack(Opts.LogBuf, prev.stack)
|
||||||
|
fmt.Fprintln(Opts.LogBuf, "Have been trying to lock it again for more than", Opts.DeadlockTimeout)
|
||||||
|
fmt.Fprintf(Opts.LogBuf, "goroutine %v lock %p\n", currentID, ptr)
|
||||||
|
printStack(Opts.LogBuf, stack)
|
||||||
|
stacks := stacks()
|
||||||
|
grs := bytes.Split(stacks, []byte("\n\n"))
|
||||||
|
for _, g := range grs {
|
||||||
|
if goid.ExtractGID(g) == prev.gid {
|
||||||
|
fmt.Fprintln(Opts.LogBuf, "Here is what goroutine", prev.gid, "doing now")
|
||||||
|
Opts.LogBuf.Write(g)
|
||||||
|
fmt.Fprintln(Opts.LogBuf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lo.other(ptr)
|
||||||
|
if Opts.PrintAllCurrentGoroutines {
|
||||||
|
fmt.Fprintln(Opts.LogBuf, "All current goroutines:")
|
||||||
|
Opts.LogBuf.Write(stacks)
|
||||||
|
}
|
||||||
|
fmt.Fprintln(Opts.LogBuf)
|
||||||
|
if buf, ok := Opts.LogBuf.(*bufio.Writer); ok {
|
||||||
|
buf.Flush()
|
||||||
|
}
|
||||||
|
Opts.mu.Unlock()
|
||||||
|
lo.mu.Unlock()
|
||||||
|
Opts.OnPotentialDeadlock()
|
||||||
|
<-ch
|
||||||
|
return
|
||||||
|
case <-ch:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
lockFn()
|
||||||
|
postLock(stack, ptr)
|
||||||
|
close(ch)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
postLock(stack, ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
type lockOrder struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
cur map[interface{}]stackGID // stacktraces + gids for the locks currently taken.
|
||||||
|
order map[beforeAfter]ss // expected order of locks.
|
||||||
|
}
|
||||||
|
|
||||||
|
type stackGID struct {
|
||||||
|
stack []uintptr
|
||||||
|
gid int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type beforeAfter struct {
|
||||||
|
before interface{}
|
||||||
|
after interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ss struct {
|
||||||
|
before []uintptr
|
||||||
|
after []uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
var lo = newLockOrder()
|
||||||
|
|
||||||
|
func newLockOrder() *lockOrder {
|
||||||
|
return &lockOrder{
|
||||||
|
cur: map[interface{}]stackGID{},
|
||||||
|
order: map[beforeAfter]ss{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *lockOrder) postLock(stack []uintptr, p interface{}) {
|
||||||
|
gid := goid.Get()
|
||||||
|
l.mu.Lock()
|
||||||
|
l.cur[p] = stackGID{stack, gid}
|
||||||
|
l.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *lockOrder) preLock(stack []uintptr, p interface{}) {
|
||||||
|
if Opts.DisableLockOrderDetection {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gid := goid.Get()
|
||||||
|
l.mu.Lock()
|
||||||
|
for b, bs := range l.cur {
|
||||||
|
if b == p {
|
||||||
|
if bs.gid == gid {
|
||||||
|
Opts.mu.Lock()
|
||||||
|
fmt.Fprintln(Opts.LogBuf, header, "Recursive locking:")
|
||||||
|
fmt.Fprintf(Opts.LogBuf, "current goroutine %d lock %p\n", gid, b)
|
||||||
|
printStack(Opts.LogBuf, stack)
|
||||||
|
fmt.Fprintln(Opts.LogBuf, "Previous place where the lock was grabbed (same goroutine)")
|
||||||
|
printStack(Opts.LogBuf, bs.stack)
|
||||||
|
l.other(p)
|
||||||
|
if buf, ok := Opts.LogBuf.(*bufio.Writer); ok {
|
||||||
|
buf.Flush()
|
||||||
|
}
|
||||||
|
Opts.mu.Unlock()
|
||||||
|
Opts.OnPotentialDeadlock()
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if bs.gid != gid { // We want locks taken in the same goroutine only.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if s, ok := l.order[beforeAfter{p, b}]; ok {
|
||||||
|
Opts.mu.Lock()
|
||||||
|
fmt.Fprintln(Opts.LogBuf, header, "Inconsistent locking. saw this ordering in one goroutine:")
|
||||||
|
fmt.Fprintln(Opts.LogBuf, "happened before")
|
||||||
|
printStack(Opts.LogBuf, s.before)
|
||||||
|
fmt.Fprintln(Opts.LogBuf, "happened after")
|
||||||
|
printStack(Opts.LogBuf, s.after)
|
||||||
|
fmt.Fprintln(Opts.LogBuf, "in another goroutine: happened before")
|
||||||
|
printStack(Opts.LogBuf, bs.stack)
|
||||||
|
fmt.Fprintln(Opts.LogBuf, "happened after")
|
||||||
|
printStack(Opts.LogBuf, stack)
|
||||||
|
l.other(p)
|
||||||
|
fmt.Fprintln(Opts.LogBuf)
|
||||||
|
if buf, ok := Opts.LogBuf.(*bufio.Writer); ok {
|
||||||
|
buf.Flush()
|
||||||
|
}
|
||||||
|
Opts.mu.Unlock()
|
||||||
|
Opts.OnPotentialDeadlock()
|
||||||
|
}
|
||||||
|
l.order[beforeAfter{b, p}] = ss{bs.stack, stack}
|
||||||
|
if len(l.order) == Opts.MaxMapSize { // Reset the map to keep memory footprint bounded.
|
||||||
|
l.order = map[beforeAfter]ss{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *lockOrder) postUnlock(p interface{}) {
|
||||||
|
l.mu.Lock()
|
||||||
|
delete(l.cur, p)
|
||||||
|
l.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
type rlocker RWMutex
|
||||||
|
|
||||||
|
func (r *rlocker) Lock() { (*RWMutex)(r).RLock() }
|
||||||
|
func (r *rlocker) Unlock() { (*RWMutex)(r).RUnlock() }
|
||||||
|
|
||||||
|
// Under lo.mu Locked.
|
||||||
|
func (l *lockOrder) other(ptr interface{}) {
|
||||||
|
empty := true
|
||||||
|
for k := range l.cur {
|
||||||
|
if k == ptr {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
empty = false
|
||||||
|
}
|
||||||
|
if empty {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintln(Opts.LogBuf, "Other goroutines holding locks:")
|
||||||
|
for k, pp := range l.cur {
|
||||||
|
if k == ptr {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Fprintf(Opts.LogBuf, "goroutine %v lock %p\n", pp.gid, k)
|
||||||
|
printStack(Opts.LogBuf, pp.stack)
|
||||||
|
}
|
||||||
|
fmt.Fprintln(Opts.LogBuf)
|
||||||
|
}
|
||||||
|
|
||||||
|
const header = "POTENTIAL DEADLOCK:"
|
10
vendor/github.com/sasha-s/go-deadlock/deadlock_map.go
generated
vendored
Normal file
10
vendor/github.com/sasha-s/go-deadlock/deadlock_map.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// +build go1.9
|
||||||
|
|
||||||
|
package deadlock
|
||||||
|
|
||||||
|
import "sync"
|
||||||
|
|
||||||
|
// Map is sync.Map wrapper
|
||||||
|
type Map struct {
|
||||||
|
sync.Map
|
||||||
|
}
|
107
vendor/github.com/sasha-s/go-deadlock/stacktraces.go
generated
vendored
Normal file
107
vendor/github.com/sasha-s/go-deadlock/stacktraces.go
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
package deadlock
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
func callers(skip int) []uintptr {
|
||||||
|
s := make([]uintptr, 50) // Most relevant context seem to appear near the top of the stack.
|
||||||
|
return s[:runtime.Callers(2+skip, s)]
|
||||||
|
}
|
||||||
|
|
||||||
|
func printStack(w io.Writer, stack []uintptr) {
|
||||||
|
home := os.Getenv("HOME")
|
||||||
|
usr, err := user.Current()
|
||||||
|
if err == nil {
|
||||||
|
home = usr.HomeDir
|
||||||
|
}
|
||||||
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
|
for i, pc := range stack {
|
||||||
|
f := runtime.FuncForPC(pc)
|
||||||
|
name := f.Name()
|
||||||
|
pkg := ""
|
||||||
|
if pos := strings.LastIndex(name, "/"); pos >= 0 {
|
||||||
|
name = name[pos+1:]
|
||||||
|
}
|
||||||
|
if pos := strings.Index(name, "."); pos >= 0 {
|
||||||
|
pkg = name[:pos]
|
||||||
|
name = name[pos+1:]
|
||||||
|
}
|
||||||
|
file, line := f.FileLine(pc)
|
||||||
|
if (pkg == "runtime" && name == "goexit") || (pkg == "testing" && name == "tRunner") {
|
||||||
|
fmt.Fprintln(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tail := ""
|
||||||
|
if i == 0 {
|
||||||
|
tail = " <<<<<" // Make the line performing a lock prominent.
|
||||||
|
}
|
||||||
|
// Shorten the file name.
|
||||||
|
clean := file
|
||||||
|
if cwd != "" {
|
||||||
|
cl, err := filepath.Rel(cwd, file)
|
||||||
|
if err == nil {
|
||||||
|
clean = cl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if home != "" {
|
||||||
|
s2 := strings.Replace(file, home, "~", 1)
|
||||||
|
if len(clean) > len(s2) {
|
||||||
|
clean = s2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "%s:%d %s.%s %s%s\n", clean, line-1, pkg, name, code(file, line), tail)
|
||||||
|
}
|
||||||
|
fmt.Fprintln(w)
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileSources struct {
|
||||||
|
sync.Mutex
|
||||||
|
lines map[string][][]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reads souce file lines from disk if not cached already.
|
||||||
|
func getSourceLines(file string) [][]byte {
|
||||||
|
fileSources.Lock()
|
||||||
|
defer fileSources.Unlock()
|
||||||
|
if fileSources.lines == nil {
|
||||||
|
fileSources.lines = map[string][][]byte{}
|
||||||
|
}
|
||||||
|
if lines, ok := fileSources.lines[file]; ok {
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
text, _ := ioutil.ReadFile(file)
|
||||||
|
fileSources.lines[file] = bytes.Split(text, []byte{'\n'})
|
||||||
|
return fileSources.lines[file]
|
||||||
|
}
|
||||||
|
|
||||||
|
func code(file string, line int) string {
|
||||||
|
lines := getSourceLines(file)
|
||||||
|
line -= 2
|
||||||
|
if line >= len(lines) || line < 0 {
|
||||||
|
return "???"
|
||||||
|
}
|
||||||
|
return "{ " + string(bytes.TrimSpace(lines[line])) + " }"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stacktraces for all goroutines.
|
||||||
|
func stacks() []byte {
|
||||||
|
buf := make([]byte, 1024*16)
|
||||||
|
for {
|
||||||
|
n := runtime.Stack(buf, true)
|
||||||
|
if n < len(buf) {
|
||||||
|
return buf[:n]
|
||||||
|
}
|
||||||
|
buf = make([]byte, 2*len(buf))
|
||||||
|
}
|
||||||
|
}
|
12
vendor/github.com/sasha-s/go-deadlock/test.sh
generated
vendored
Normal file
12
vendor/github.com/sasha-s/go-deadlock/test.sh
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
echo "" > coverage.txt
|
||||||
|
|
||||||
|
for d in $(go list ./...); do
|
||||||
|
go test -coverprofile=profile.out -covermode=atomic "$d"
|
||||||
|
if [ -f profile.out ]; then
|
||||||
|
cat profile.out >> coverage.txt
|
||||||
|
rm profile.out
|
||||||
|
fi
|
||||||
|
done
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@@ -225,6 +225,7 @@ github.com/mitchellh/go-homedir
|
|||||||
## explicit
|
## explicit
|
||||||
# github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5
|
# github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5
|
||||||
## explicit
|
## explicit
|
||||||
|
github.com/petermattis/goid
|
||||||
# github.com/pmezard/go-difflib v1.0.0
|
# github.com/pmezard/go-difflib v1.0.0
|
||||||
## explicit
|
## explicit
|
||||||
github.com/pmezard/go-difflib/difflib
|
github.com/pmezard/go-difflib/difflib
|
||||||
@@ -242,6 +243,7 @@ github.com/samber/lo
|
|||||||
github.com/sanity-io/litter
|
github.com/sanity-io/litter
|
||||||
# github.com/sasha-s/go-deadlock v0.3.1
|
# github.com/sasha-s/go-deadlock v0.3.1
|
||||||
## explicit
|
## explicit
|
||||||
|
github.com/sasha-s/go-deadlock
|
||||||
# github.com/sergi/go-diff v1.1.0
|
# github.com/sergi/go-diff v1.1.0
|
||||||
## explicit; go 1.12
|
## explicit; go 1.12
|
||||||
github.com/sergi/go-diff/diffmatchpatch
|
github.com/sergi/go-diff/diffmatchpatch
|
||||||
|
Reference in New Issue
Block a user