Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supoprt ghq default direcotry(~/.ghq). #5

Merged
merged 2 commits into from
Oct 8, 2014

Conversation

sonatard
Copy link

@sonatard sonatard commented Oct 4, 2014

Emacs lispをinit.el以外で初めて書いてPRさせて頂きました。
部分的に動作させながらコードを理解して、標準出力させた値を元にrootディレクトリをとってきているところは理解できたのですが、純粋に標準出力だけを実現する方法がわからずcall-processでechoしてしまいました。
(princなどでは文字列が評価されて2回出力されてしまう)
Emacs Lisp で prin1とprincとprintの違い - ながとダイアリー
http://d.hatena.ne.jp/mclh46/20100914/1284465897

その他も含めて問題があれば再度修正後にPRさせて貰いたいと思うのでレビューよろしくお願いします。

@syohex
Copy link
Contributor

syohex commented Oct 4, 2014

新しい ghqコマンドだと rootサブコマンドがあるのでそちらを使う方がよいのでは
ないでしょうか ?

@syohex
Copy link
Contributor

syohex commented Oct 4, 2014

こんな具合にすればよいかと思います.

(defun helm-ghq--root ()
  (with-temp-buffer
    (unless (zerop (process-file "ghq" nil t nil "root"))
      (error "Failed: 'ghq root'"))
    (goto-char (point-min))
    (helm-current-line-contents)))

@syohex
Copy link
Contributor

syohex commented Oct 4, 2014

部分的に動作させながらコードを理解して、標準出力させた値を元にrootディレクトリをとってきているところは理解できたのですが、純粋に標準出力だけを実現する方法がわからずcall-processでechoしてしまいました。
(princなどでは文字列が評価されて2回出力されてしまう)

insertでいいと思います. call-processの第三引数は標準出力を現在のバッファ(ここだと tempbuffer)に
出力するという意味になります. なんで標準出力に出すことが重要じゃなく, 現在のバッファにそれを
書き出すことが重要です. しかしまあそれはその先の処理で現在のバッファの文字列を切り出している
からの話であって, 追加されたようなケースでは単に文字列を返すだけで十分です. helm-ghq--root
ghqの rootディレクトリを文字列で返す関数なので, 現在のバッファに書き出すことなどせず, 文字列だけ
返せばよいです.

@sonatard
Copy link
Author

sonatard commented Oct 4, 2014

@syohex いつもありがとうございます!
ghq rootコマンドで動作確認できました。
ghq rootコマンド自体はgitconfigにrootがなければ~/.ghqを返すようなので、実際には~/.ghqディレクトリがない可能性はあるのですが、これはhelm-ghqで対応する必要はないと思うのでディレクトリのチェックはしていません。

部分的に動作させながらコードを理解して、標準出力させた値を元にrootディレクトリをとってきているところは理解できたのですが、純粋に標準出力だけを実現する方法がわからずcall-processでechoしてしまいました。
(princなどでは文字列が評価されて2回出力されてしまう)

insertでいいと思います. call-processの第三引数は標準出力を現在のバッファ(ここだと tempbuffer)に
出力するという意味になります. なんで標準出力に出すことが重要じゃなく, 現在のバッファにそれを
書き出すことが重要です. しかしまあそれはその先の処理で現在のバッファの文字列を切り出している
からの話であって, 追加されたようなケースでは単に文字列を返すだけで十分です. helm-ghq--rootは
ghqの rootディレクトリを文字列で返す関数なので, 現在のバッファに書き出すことなどせず, 文字列だけ
返せばよいです.

insertでバッファにかけるんですね。
PR対応だけではなくemacs lispまで教えていただきありがとうございます!

(unless (zerop (call-process "git" nil t nil "config" "ghq.root"))
(error "Failed: Can't find ghq.root"))
(unless (zerop (process-file "ghq" nil t nil "root"))
(error "Failed: 'ghq root'"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

古いバージョンを使っている人はここに来るので、
ghq rootはverXXから追加された」ことを書けばよいかと思いましたが、
https://github.com/motemen/ghq/releases 見るとリリース版には入ってないのですね。
(ghq root自体は x-motemen/ghq#34 でマージされた)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ああ、"No help topic for 'root'"という文字列が返るのかな。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rootサブコマンドが実装されたバージョンのバイナリがリリースされていない
ことは見落としていました. リリースされるまでは fallbackさせる等する必要が
ありそうです(さすがに go getでインストールさせるのはやりすぎだと思うので)

@masutaka
Copy link
Owner

masutaka commented Oct 5, 2014

PRありがとうございます!ちょっと考えます。

※ force pushされたようですが、経緯が分からなくなるのであまりオススメしません。

@sonatard
Copy link
Author

sonatard commented Oct 5, 2014

@masutaka ご対応ありがとうございます。

PRありがとうございます!ちょっと考えます。
※ force pushされたようですが、経緯が分からなくなるのであまりオススメしません。

元々は~/.ghqのディレクトリの有無を判断して存在した場合にはecho "~/.ghq"しておりました。
ご迷惑をおかけしていますが検討よろしくお願いします

@syohex
Copy link
Contributor

syohex commented Oct 6, 2014

あと詳しく見ていなかったのですが, ghqに存在しないサブコマンドを与えても
error statusが 0になりますので, コマンドの戻り値が 0かどうかでチェックする
というのはできなそうです.(これは ghqの問題でなく, cliというライブラリの
問題のように思えますが).

@syohex
Copy link
Contributor

syohex commented Oct 6, 2014

すべてを考慮するとこんな感じでしょうか.

diff --git a/helm-ghq.el b/helm-ghq.el
index d08af0e..c06e23c 100644
--- a/helm-ghq.el
+++ b/helm-ghq.el
@@ -52,12 +52,21 @@
   `(buffer-substring-no-properties
     (line-beginning-position) (line-end-position)))

+(defun helm-ghq--root-fallback ()
+  (erase-buffer)
+  (unless (zerop (process-file "git" nil t nil "config" "ghq.root"))
+    (error "Failed: Can't find ghq.root"))
+  (goto-char (point-min))
+  (expand-file-name (helm-ghq--line-string)))
+
 (defun helm-ghq--root ()
   (with-temp-buffer
-    (unless (zerop (call-process "git" nil t nil "config" "ghq.root"))
-      (error "Failed: Can't find ghq.root"))
+    (process-file "ghq" nil t nil "root")
     (goto-char (point-min))
-    (expand-file-name (helm-ghq--line-string))))
+    (let ((output (helm-ghq--line-string)))
+      (if (string-match-p "\\`No help topic" output)
+          (helm-ghq--root-fallback)
+        (expand-file-name output)))))

 (defun helm-ghq--list-candidates ()
   (with-temp-buffer

@sonatard
Copy link
Author

sonatard commented Oct 6, 2014

@syohex ありがとうございます。
以下であっていますか?

  1. ghq rootでrootを取得(configのghq.rootの値もしくはデフォルトの~/.ghq)
  2. もしgit rootコマンド対応でなければgit config ghq.rootでrootを取得(configのghq.root)

masutakaさんが宜しければsyohexさんものを追加でコミットしたいと思いますのでそのときは言ってください。

@syohex
Copy link
Contributor

syohex commented Oct 6, 2014

以下であっていますか?

  1. ghq rootでrootを取得(configのghq.rootの値もしくはデフォルトの~/.ghq)
  2. もしgit rootコマンド対応でなければgit config ghq.rootでrootを取得(configのghq.root)

はい.

@masutaka
Copy link
Owner

masutaka commented Oct 7, 2014

masutakaさんが宜しければsyohexさんものを追加でコミットしたいと思いますのでそのときは言ってください。

👍

@masutaka
Copy link
Owner

masutaka commented Oct 8, 2014

ありがとうございます。

LGTM

masutaka added a commit that referenced this pull request Oct 8, 2014
Supoprt ghq default direcotry(~/.ghq).
@masutaka masutaka merged commit 2a99849 into masutaka:master Oct 8, 2014
@masutaka
Copy link
Owner

masutaka commented Oct 8, 2014

@sona-tar
commit logのAuthorのEmailアドレスのドメインが@gmail.co.jpとおかしいので、
~/.gitconfig等確認したほうが良さそうです。
(commit logでアイコンが出ないのも多分それが原因かと。)

@sonatard
Copy link
Author

sonatard commented Oct 8, 2014

@masutaka マージとメールの件ありがとうございます。
@gmai.comに直したところアイコンが正しく表示されるようになりました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants