git first, git-svn later.

the whole story is that I started a project locally and I used git as my SCM. now I’m going to put it into a svn repository with full history but I still want to use git.

normally you should make this decision at the beginning. that means you

1
git-svn clone http://svn.somewhere.com/myproject

first, then you use git as usual, do git-svn rebase and git-svn dcommit. you have to do this because git-svn must know where to start, namely you should have at least one git-svn-id in your git log to start with.

here is how I add svn support into an existing git repository. basically it’s easy, you just

1
2
git-svn init http://svn.somewhere.com/myproject
git-svn fetch

now git branch -r should tell you there is a branch called git-svn. you git rebase git-svn your current master. if it succeeded then you’re all set.

however, in order to do this, there must be a point back in time that these two branches are the same. if it’s not the case, you’re in trouble. you have to use git-svn set-tree to force a svn commit to be your starting point. in my case, the svn repository started out empty, so I forced the first commit in my git. after that git rebase succeeded like I expected.

fonts disappeared

I’m using debian testing (lenny) and after the latest update my xserver no longer display fonts. This is not totally true because I can still see the fonts on gdm, but after logging in, no fonts whatsoever. It turns out the i810 Xorg driver is messed up and I have to set NoAccel to true to avoid it.

1
2
3
4
5
6
7
8
Section "Device"
Identifier "Intel Corporation 82Q963/Q965 Integrated Graphics Controller"
Driver "i810"
BusID "PCI:0:2:0"
Option "NoAccel" "true"
# Option "AccelMethod" "EXA"
Option "XAANoOffscreenPixmaps"
EndSection

BTW I can use compiz without NoAccel before if I delete the device id from the blacklist in compiz start up script.

我果然不懂 C 啊。

from gcc-4.2.info:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
5.34 An Inline Function is As Fast As a Macro

<..snipped..>

If you specify both `inline' and `extern' in the function definition,
then the definition is used only for inlining. In no case is the
function compiled on its own, not even if you refer to its address
explicitly. Such an address becomes an external reference, as if you
had only declared the function, and had not defined it.

This combination of `inline' and `extern' has almost the effect of a
macro. The way to use it is to put a function definition in a header
file with these keywords, and put another copy of the definition
(lacking `inline' and `extern') in a library file. The definition in
the header file will cause most calls to the function to be inlined.
If any uses of the function remain, they will refer to the single copy
in the library.

Since GCC 4.3 will implement ISO C99 semantics for inline functions,
it is simplest to use `static inline' only to guarantee compatibility.
(The existing semantics will remain available when `-std=gnu89' is
specified, but eventually the default will be `-std=gnu99'; that will
implement the C99 semantics, though it does not do so in versions of
GCC before 4.3\. After the default changes, the existing semantics will
still be available via the `-fgnu89-inline' option or the `gnu_inline'
function attribute.)

GCC does not inline any functions when not optimizing unless you
specify the `always_inline' attribute for the function, like this:

/* Prototype. */
inline void foo (const char) __attribute__((always_inline));

So, consider the following program:

gcctest.c:

1
2
3
4
5
6
7
#include "inline.h"

int main()
{
puts(externinline());
return 0;
}

inline.h:

1
2
3
4
__inline__ extern char *externinline()
{
return "inline";
}

lib.c:

1
2
3
4
char *externinline()
{
return "extern";
}

The behavior of the executables will be different with or without the -O option of gcc. Compile it without -O, the program will print “extern”. Compile it with -O, the program will print “intern”.

利用 ssh 連到 NAT 內的電腦

在 NAT 內的電腦 (暫名為 A) 上下指令:

1
autossh -R :1234:localhost:22 my.server.com
  1. autossh will automatically reconnect
  2. -R :1234:localhost:22 意思是連到 my.server.com,在 my.server.com 上頭開 port 1234 回連到 A。
  3. my.server.com 上頭 sshd_config 必須要設定 GatewayPorts clientspecified or yes

然後在外頭的 linux 電腦連到:

1
ssh -p 1234 my.server.com

這樣就可以連回 A 了。如此這般就算沒有 VPN 也可以在家工作。

git-svn

像 subversion (svn) 這類集中式的 scm 一定要有網路連線才能 commit ,這是很討厭的一件事情,尤其是很多人都會用 notebook 工作,不見得需要長時間連結網路,或者是並沒興趣修改 svn 上的版本。這時候像老牌的 monotone 或是現在的 git 以及 Mercurial 這種分散式的版本管理系統就很好用。這陣子在改一個 project,他已經有 svn 在 googlecode 上,看來已經很久沒人 maintain. 我當然還不需要 svn write 權限,但是我仍然希望在自己 local 端有版本管理,這樣我如果幹了什麼蠢事才救得回來。

此時 git-svn 這種工具就真的很好用。基本使用方式是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Clone a repo (like git clone):
git-svn clone http://svn.foo.org/project/trunk
# Enter the newly cloned directory:
cd trunk
# You should be on master branch, double-check with git-branch
git branch
# Do some work and commit locally to git:
git commit ...
# Something is committed to SVN, rebase your local changes against the
# latest changes in SVN:
git-svn rebase
# Now commit your changes (that were committed previously using git) to SVN,
# as well as automatically updating your working HEAD:
git-svn dcommit
# Append svn:ignore settings to the default git exclude file:
git-svn show-ignore >> .git/info/exclude

日後如果我想要把修改 commit 到 upstream 去,我在這段時間的修改記錄仍然可以保留。相當有彈性的作法。

DPI果然好用啊。

話說不知道從哪次更新之後,notebook的字型就一直很鳥,調到12號字還是有點小,更加上還很醜,因為其實很多相對應的效果都是針對一般預設10號字左右去調的。剛剛才想到,應該是因為DPI差太多的原因吧,於是拿出尺量了一下螢幕的大小,然後在xorg.conf中加入DisplaySize的設定:

1
2
3
4
5
6
7
Section "Monitor"
Identifier "Generic Monitor"
Option "DPMS"
HorizSync 28-49
VertRefresh 43-72
DisplaySize 245 185
EndSection

嘿,果然搞定。嚴格說起來,在不同的顯示器底下,理想狀態應該是同一個theme只要調整DPI以後都可以得到相同的視覺效果。Microsoft Windows在一開始就忽略掉DPI的設定,還把它誤導成「調整字型大小」用,實在不是很好的觀念。

My .emacs

emacs 當然不是最好上手的 editor,不過功能強大、擴充容易,目前仍然是程式開發最佳選擇之一。我的 .emacs 設定檔設定了 [f4] 為關檔、[f5] 為執行make、[ctrl-enter] 為設定記號,因為原先的 [ctrl-space] 會跟輸入法衝到。另外 (windmove-default-keybindings) 是超好用的視窗切換熱鍵,例如要移到下方的視窗,就是按 shift-down。印象中這功能在 21 版還沒有。剩下的功能都是直接在 emacs 裡頭執行 customize 來設定的,建議就不要手動改了。

幾個比較特別或有用的設定:

'(current-language-environment "Chinese-BIG5") 用來指定預設環境為BIG5中文。這環境在UTF-8以及BIG5底下都工作正常,但這到22版才真正有用。

'(default-major-mode (quote text-mode)) 由於 emacs 是我預設用來寫email的editor,所以設定預設模式為text-mode會比原本的fundamental-mode方便。

'(initial-frame-alist (quote ((width . 80) (height . 60)))) 改變預設視窗大小。

'(server-mode t) server-mode是個很好用的新功能。打開之後,只要在其他視窗打emacsclient xxx就會自動用已經在執行的emacs開檔。我目前環境變數EDITOR的內容為”emacsclient -a emacs”,試試看。

'(winner-mode t nil (winner))) 視窗調大小以後可以用winner-mode還原/重做。熱鍵是 Ctrl-C, left/right.

調字型的方法:22版對gtk支援,應該是不用調。真的要調的話,用shift-滑鼠左鍵叫出字型視窗,選到自己喜歡的以後,進入customize-group, basic-face, default底下,把那邊的值寫入.emacs即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
;; global set key
(global-set-key [f4] `kill-buffer)
(global-set-key [f5] `compile)
(global-set-key [C-return] `set-mark-command)
(windmove-default-keybindings)

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(c-default-style (quote ((c-mode . "stroustrup") (java-mode . "java") (awk-mode . "awk") (other . "gnu"))))
'(current-language-environment "Chinese-BIG5")
'(default-major-mode (quote text-mode))
'(initial-frame-alist (quote ((width . 80) (height . 60))))
'(prolog-system (quote gnu))
'(scroll-bar-mode (quote right))
'(server-mode t)
'(show-paren-mode t)
'(tool-bar-mode nil)
'(user-mail-address "cylee@programmer.net")
'(winner-mode t nil (winner)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:stipple nil :background "black" :foreground "grey" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 105 :width normal :family "adobe-courier")))))

Compiz-fusion, ATI Radeon 9100 and Debian

Repository: Visit http://shame.tuxfamily.org/repo/ I use debian testing (lenny), compiz unstable repo. You need compiz-gnome (or compiz-kde). You might need compiz-manager if you want to make compiz your default window manager.

Related settings in xorg.conf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Section "Device"
Identifier "ATI Technologies Inc Radeon R200 QM [Radeon 9100]"
Driver "ati"
BusID "PCI:1:0:0"
Option "EnablePageFlip" # may disable this.
Option "XAANoOffscreenPixmaps"
EndSection

Section "Extensions"
Option "Composite" "Enable"
EndSection

Section "DRI"
group "video"
mode 0660
EndSection

Ctrl-Alt-Backspace to restart X. Execute fusion-icon, switch to compiz. If it works, you may make it the default window manager:

  1. gconf-editor: /desktop/gnome/applications/window_manager/default , modify value to: /usr/bin/compiz-manager
  2. sudo vim /usr/bin/gnome-wm, near the end of the file, modify:
1
2
3
4
5
6
7
8
9
10
11
openbox)
OPT1=--sm-client-id
OPT2=$SMID
CURRENT=openbox
;;
*)
OPT1=--sm-client-id
OPT2=$SMID
;;
esac
fi
  1. Modify /usr/bin/compiz-manager, change COMPIZ_NAME from “compiz” to “compiz.real”

Toshiba Portege 2000 and Debian

I wrote several posts about the Linux support on Toshiba Protege 2000.[1][2][3][4] Actually I’m still using this elegant laptop to write this article now. It turns out Ubuntu has done quite a impressive work to support laptops. After I installed Debian to replace Ubuntu, the function keys stopped working because no ACPI events will be generated by key pressing. I traced acpid, hal and toshiba-acpi module in kernel space trying to solve this, and finally I found out Ubuntu patched toshiba-acpi in their kernel to support Toshiba specific hotkeys. So, right now I’m putting the patch into my Debian kernel source and re-building it. We will see if it works later.

  • Update: The patch works. Now my debian system could support every hotkey on Protege 2000.