2012-02-16 35 views
2

當我從unix命令行執行svn commit時,它會在打開編輯器之前切換到父目錄。因爲我不在我認爲的地方,所以當我做殼逃脫時,這會引起很大的困惑。爲什麼在執行提交時Subversion切換到父目錄

這種行爲的原因是什麼?

(編輯)下面屏幕截圖顯示這種情況發生在最低的目錄,並在最上面的一個

svn --version svn, version 1.5.5 (r34862) 

test: svn checkout file:///export/home/svn/xxx/a 
A a/b 
A a/b/c 
A a/b/c/new 
Checked out revision 8882. 

test: cd a/b/c 
test: pwd 
/home/geretz/test/a/b/c 
test: echo changed > new 
test: svn commit 

--This line, and those below, will be ignored-- 

M c/new 
~ 
~ 
:!pwd 
/home/geretz/test/a/b 

Hit ENTER or type command to continue 

中止編輯會話沒有發生,嘗試從頂級目錄提交

test: pwd 
/home/geretz/test/a/b/c 
test: cd ../.. 
test: pwd 
/home/geretz/test/a 
test: svn commit 

--This line, and those below, will be ignored-- 

M b/c/new 
~ 
~ 
:!pwd 
/home/geretz/test/a 

Hit ENTER or type command to continue 
+0

您是否使用SVN 1.7.X? – khmarbaise 2012-02-16 20:46:23

+0

svn --version svn,版本1.5.5(r34862) – 2012-02-16 20:57:51

+0

它切換到直接父級還是工作副本的根目錄?如果是後者,我敢打賭,你可以找出原因...... – benzado 2012-02-16 21:01:16

回答

4

如果您瀏覽svn來源,則會發現svn commithttp://svn.apache.org/repos/asf/subversion/branches/1.5.x/subversion/svn/commit-cmd.c中的svn_cl__commit函數處理。實際的功能需要注意將路徑拆分爲'basename'和'dirname'爲svn_wc_get_actual_target。此功能在http://svn.apache.org/repos/asf/subversion/branches/1.5.x/subversion/include/svn_wc.h聲明,並以下評論:

/** Conditionally split @a path into an @a anchor and @a target for the 
* purpose of updating and committing. 
* 
* @a anchor is the directory at which the update or commit editor 
* should be rooted. 
* 
* @a target is the actual subject (relative to the @a anchor) of the 
* update/commit, or "" if the @a anchor itself is the subject. 
* 
* Allocate @a anchor and @a target in @a pool. 
*/ 

最後文件http://svn.apache.org/repos/asf/subversion/branches/1.5.x/subversion/libsvn_wc/update_editor.c我們可以看到如下評論:

Updates are accomplished by driving an editor, and an editor is 
"rooted" on a directory. So, in order to update a file, we need to 
break off the basename of the file, rooting the editor in that 
file's parent directory, and then updating only that file, not the 
other stuff in its parent directory. 

Secondly, we look at the case where we wish to update a directory. 
This is typically trivial. However, one problematic case, exists 
when we wish to update a directory that has been removed from the 
repository and replaced with a file of the same name. If we root 
our edit at the initial directory, there is no editor mechanism for 
deleting that directory and replacing it with a file (this would be 
like having an editor now anchored on a file, which is disallowed). 

All that remains is to have a function with the knowledge required 
to properly decide where to root our editor, and what to act upon 
with that now-rooted editor. Given a path to be updated, this 
function should conditionally split that path into an "anchor" and 
a "target", where the "anchor" is the directory at which the update 
editor is rooted (meaning, editor->open_root() is called with 
this directory in mind), and the "target" is the actual intended 
subject of the update. 

svn_wc_get_actual_target() is that function. 

... 

As it turns out, commits need to have a similar check in place, 
too, specifically for the case where a single directory is being 
committed (we have to anchor at that directory's parent in case the 
directory itself needs to be modified) 
+0

如果在編寫消息時需要有一個可預測的工作目錄,看起來最好的辦法是創建提交消息並在*之前將其保存到文件*做提交,然後通過'svn commit --file commit_log.txt'來使用它。這基本上是幕後發生的事情,只有文件是臨時的,並在提交完成後自動刪除。 – bta 2012-02-23 18:41:56

相關問題