OSDN Git Service

Fixed issue #155: Fix SVN Rebase sets upstream as remotes/trunk
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Commands / RepositoryBrowserCommand.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2007-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "StdAfx.h"\r
20 #include "RepositoryBrowserCommand.h"\r
21 \r
22 #include "RepositoryBrowser.h"\r
23 #include "URLDlg.h"\r
24 #include "SVN.h"\r
25 #include "PathUtils.h"\r
26 #include "UnicodeUtils.h"\r
27 \r
28 bool RepositoryBrowserCommand::Execute()\r
29 {\r
30         CString url;\r
31         BOOL bFile = FALSE;\r
32         SVN svn;\r
33         if (!cmdLinePath.IsEmpty())\r
34         {\r
35                 if (cmdLinePath.GetSVNPathString().Left(4).CompareNoCase(_T("svn:"))==0)\r
36                 {\r
37                         // If the path starts with "svn:" and there is another protocol\r
38                         // found in the path (a "://" found after the "svn:") then\r
39                         // remove "svn:" from the beginning of the path.\r
40                         if (cmdLinePath.GetSVNPathString().Find(_T("://"), 4)>=0)\r
41                                 cmdLinePath.SetFromSVN(cmdLinePath.GetSVNPathString().Mid(4));\r
42                 }\r
43 \r
44                 url = svn.GetURLFromPath(cmdLinePath);\r
45 \r
46                 if (url.IsEmpty())\r
47                 {\r
48                         if (SVN::PathIsURL(cmdLinePath))\r
49                                 url = cmdLinePath.GetSVNPathString();\r
50                         else if (svn.IsRepository(cmdLinePath))\r
51                         {\r
52                                 // The path points to a local repository.\r
53                                 // Add 'file:///' so the repository browser recognizes\r
54                                 // it as an URL to the local repository.\r
55                                 if (cmdLinePath.GetWinPathString().GetAt(0) == '\\')    // starts with '\' means an UNC path\r
56                                 {\r
57                                         CString p = cmdLinePath.GetWinPathString();\r
58                                         p.TrimLeft('\\');\r
59                                         if (CPathUtils::PathEscape(CUnicodeUtils::GetUTF8(p)).Find('%') >= 0)\r
60                                         {\r
61                                                 // the path has special chars which will get escaped!\r
62                                                 url = _T("file:///\\")+p;\r
63                                         }\r
64                                         else\r
65                                                 url = _T("file://")+p;\r
66                                 }\r
67                                 else\r
68                                         url = _T("file:///")+cmdLinePath.GetWinPathString();\r
69                                 url.Replace('\\', '/');\r
70                         }\r
71                 }\r
72         }\r
73         if (cmdLinePath.GetUIPathString().Left(7).CompareNoCase(_T("file://"))==0)\r
74         {\r
75                 cmdLinePath.SetFromUnknown(cmdLinePath.GetUIPathString().Mid(7));\r
76         }\r
77         bFile = PathFileExists(cmdLinePath.GetWinPath()) ? !cmdLinePath.IsDirectory() : FALSE;\r
78 \r
79         if (url.IsEmpty())\r
80         {\r
81                 CURLDlg urldlg;\r
82                 if (urldlg.DoModal() != IDOK)\r
83                 {\r
84                         return false;\r
85                 }\r
86                 url = urldlg.m_url;\r
87         }\r
88 \r
89         CString val = parser.GetVal(_T("rev"));\r
90         SVNRev rev(val);\r
91         CRepositoryBrowser dlg(url, rev);\r
92         if (!cmdLinePath.IsUrl())\r
93                 dlg.m_ProjectProperties.ReadProps(cmdLinePath);\r
94         else\r
95         {\r
96                 if (parser.HasVal(_T("projectpropertiespath")))\r
97                 {\r
98                         dlg.m_ProjectProperties.ReadProps(CTSVNPath(parser.GetVal(_T("projectpropertiespath"))));\r
99                 }\r
100         }\r
101         dlg.m_path = cmdLinePath;\r
102         dlg.DoModal();\r
103         return true;\r
104 }