Show More
@@ -0,0 +1,244 | |||||
|
1 | .. _installation_win: | |||
|
2 | ||||
|
3 | ||||
|
4 | Step by step Installation for Windows | |||
|
5 | ===================================== | |||
|
6 | ||||
|
7 | ||||
|
8 | RhodeCode step-by-step install Guide for Windows | |||
|
9 | ||||
|
10 | Target OS: Windows XP SP3 English (Clean installation) | |||
|
11 | + All Windows Updates until 24-may-2012 | |||
|
12 | ||||
|
13 | Step1 - Install Visual Studio 2008 Express | |||
|
14 | ------------------------------------------ | |||
|
15 | ||||
|
16 | ||||
|
17 | Optional: You can also install MingW, but VS2008 installation is easier | |||
|
18 | ||||
|
19 | Download "Visual C++ 2008 Express Edition with SP1" from: | |||
|
20 | http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express | |||
|
21 | (if not found or relocated, google for "visual studio 2008 express" for | |||
|
22 | updated link) | |||
|
23 | ||||
|
24 | You can also download full ISO file for offline installation, just | |||
|
25 | choose "All - Offline Install ISO image file" in the previous page and | |||
|
26 | choose "Visual C++ 2008 Express" when installing. | |||
|
27 | ||||
|
28 | ||||
|
29 | .. note:: | |||
|
30 | ||||
|
31 | Silverlight Runtime and SQL Server 2008 Express Edition are not | |||
|
32 | required, you can uncheck them | |||
|
33 | ||||
|
34 | ||||
|
35 | Step2 - Install Python | |||
|
36 | ---------------------- | |||
|
37 | ||||
|
38 | Install Python 2.x.y (x >= 5) x86 version (32bit). DO NOT USE A 3.x version. | |||
|
39 | Download Python 2.x.y from: | |||
|
40 | http://www.python.org/download/ | |||
|
41 | ||||
|
42 | Choose "Windows Installer" (32bit version) not "Windows X86-64 | |||
|
43 | Installer". While writing this guide, the latest version was v2.7.3. | |||
|
44 | Remember the specific major and minor version installed, because it will | |||
|
45 | be needed in the next step. In this case, it is "2.7". | |||
|
46 | ||||
|
47 | ||||
|
48 | Step3 - Install Win32py extensions | |||
|
49 | ---------------------------------- | |||
|
50 | ||||
|
51 | Download pywin32 from: | |||
|
52 | http://sourceforge.net/projects/pywin32/files/ | |||
|
53 | ||||
|
54 | - Click on "pywin32" folder | |||
|
55 | - Click on the first folder (in this case, Build 217, maybe newer when you try) | |||
|
56 | - Choose the file ending with ".win32-py2.x.exe" -> x being the minor | |||
|
57 | version of Python you installed (in this case, 7) | |||
|
58 | When writing this guide, the file was: | |||
|
59 | http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/pywin32-217.win32-py2.7.exe/download | |||
|
60 | ||||
|
61 | ||||
|
62 | Step4 - Python BIN | |||
|
63 | ------------------ | |||
|
64 | ||||
|
65 | Add Python BIN folder to the path | |||
|
66 | ||||
|
67 | You have to add the Python folder to the path, you can do it manually | |||
|
68 | (editing "PATH" environment variable) or using Windows Support Tools | |||
|
69 | that came preinstalled in Vista/7 and can be installed in Windows XP. | |||
|
70 | ||||
|
71 | - Using support tools on WINDOWS XP: | |||
|
72 | If you use Windows XP you can install them using Windows XP CD and | |||
|
73 | navigating to \SUPPORT\TOOLS. There, execute Setup.EXE (not MSI). | |||
|
74 | Afterwards, open a CMD and type:: | |||
|
75 | ||||
|
76 | SETX PATH "%PATH%;[your-python-path]" -M | |||
|
77 | ||||
|
78 | Close CMD (the path variable will be updated then) | |||
|
79 | ||||
|
80 | - Using support tools on WINDOWS Vista/7: | |||
|
81 | ||||
|
82 | Open a CMD and type:: | |||
|
83 | ||||
|
84 | SETX PATH "%PATH%;[your-python-path]" /M | |||
|
85 | ||||
|
86 | Please substitute [your-python-path] with your Python installation path. | |||
|
87 | Typically: C:\\Python27 | |||
|
88 | ||||
|
89 | ||||
|
90 | Step5 - RhodeCode folder structure | |||
|
91 | ---------------------------------- | |||
|
92 | ||||
|
93 | Create a RhodeCode folder structure | |||
|
94 | ||||
|
95 | This is only a example to install RhodeCode, you can of course change | |||
|
96 | it. However, this guide will follow the proposed structure, so please | |||
|
97 | later adapt the paths if you change them. My recommendation is to use | |||
|
98 | folders with NO SPACES. But you can try if you are brave... | |||
|
99 | ||||
|
100 | Create the following folder structure:: | |||
|
101 | ||||
|
102 | C:\RhodeCode | |||
|
103 | C:\RhodeCode\Bin | |||
|
104 | C:\RhodeCode\Env | |||
|
105 | C:\RhodeCode\Repos | |||
|
106 | ||||
|
107 | ||||
|
108 | Step6 - Install virtualenv | |||
|
109 | --------------------------- | |||
|
110 | ||||
|
111 | Install Virtual Env for Python | |||
|
112 | ||||
|
113 | Navigate to: http://www.virtualenv.org/en/latest/index.html#installation | |||
|
114 | Right click on "virtualenv.py" file and choose "Save link as...". | |||
|
115 | Download to C:\\RhodeCode (or whatever you want) | |||
|
116 | (the file is located at | |||
|
117 | https://raw.github.com/pypa/virtualenv/master/virtualenv.py) | |||
|
118 | ||||
|
119 | Create a virtual Python environment in C:\\RhodeCode\\Env (or similar). To | |||
|
120 | do so, open a CMD (Python Path should be included in Step3), navigate | |||
|
121 | where you downloaded "virtualenv.py", and write:: | |||
|
122 | ||||
|
123 | python virtualenv.py C:\RhodeCode\Env | |||
|
124 | ||||
|
125 | (--no-site-packages is now the default behaviour of virtualenv, no need | |||
|
126 | to include it) | |||
|
127 | ||||
|
128 | ||||
|
129 | Step7 - Install RhodeCode | |||
|
130 | ------------------------- | |||
|
131 | ||||
|
132 | Finally, install RhodeCode | |||
|
133 | ||||
|
134 | Close previously opened command prompt/s, and open a Visual Studio 2008 | |||
|
135 | Command Prompt (**IMPORTANT!!**). To do so, go to Start Menu, and then open | |||
|
136 | "Microsoft Visual C++ 2008 Express Edition" -> "Visual Studio Tools" -> | |||
|
137 | "Visual Studio 2008 Command Prompt" | |||
|
138 | ||||
|
139 | In that CMD (loaded with VS2008 PATHs) type:: | |||
|
140 | ||||
|
141 | cd C:\RhodeCode\Env\Scripts (or similar) | |||
|
142 | activate | |||
|
143 | ||||
|
144 | The prompt will change into "(Env) C:\\RhodeCode\\Env\\Scripts" or similar | |||
|
145 | (depending of your folder structure). Then type:: | |||
|
146 | ||||
|
147 | pip install rhodecode | |||
|
148 | ||||
|
149 | (long step, please wait until fully complete) | |||
|
150 | ||||
|
151 | Some warnings will appear, don't worry as they are normal. | |||
|
152 | ||||
|
153 | ||||
|
154 | Step8 - Configuring RhodeCode | |||
|
155 | ----------------------------- | |||
|
156 | ||||
|
157 | ||||
|
158 | steps taken from http://packages.python.org/RhodeCode/setup.html | |||
|
159 | ||||
|
160 | You have to use the same Visual Studio 2008 command prompt as Step7, so | |||
|
161 | if you closed it reopen it following the same commands (including the | |||
|
162 | "activate" one). When ready, just type:: | |||
|
163 | ||||
|
164 | cd C:\RhodeCode\Bin | |||
|
165 | paster make-config RhodeCode production.ini | |||
|
166 | ||||
|
167 | Then, you must edit production.ini to fit your needs (ip address, ip | |||
|
168 | port, mail settings, database, whatever). I recommend using NotePad++ | |||
|
169 | (free) or similar text editor, as it handles well the EndOfLine | |||
|
170 | character differences between Unix and Windows | |||
|
171 | (http://notepad-plus-plus.org/) | |||
|
172 | ||||
|
173 | For the sake of simplicity lets run it with the default settings. After | |||
|
174 | your edits (if any), in the previous Command Prompt, type:: | |||
|
175 | ||||
|
176 | paster setup-rhodecode production.ini | |||
|
177 | ||||
|
178 | (this time a NEW database will be installed, you must follow a different | |||
|
179 | step to later UPGRADE to a newer RhodeCode version) | |||
|
180 | ||||
|
181 | The script will ask you for confirmation about creating a NEW database, | |||
|
182 | answer yes (y) | |||
|
183 | The script will ask you for repository path, answer C:\\RhodeCode\\Repos | |||
|
184 | (or similar) | |||
|
185 | The script will ask you for admin username and password, answer "admin" | |||
|
186 | + "123456" (or whatever you want) | |||
|
187 | The script will ask you for admin mail, answer "admin@xxxx.com" (or | |||
|
188 | whatever you want) | |||
|
189 | ||||
|
190 | If you make some mistake and the script does not end, don't worry, start | |||
|
191 | it again. | |||
|
192 | ||||
|
193 | ||||
|
194 | Step9 - Running RhodeCode | |||
|
195 | ------------------------- | |||
|
196 | ||||
|
197 | ||||
|
198 | In the previous command prompt, being in the C:\\RhodeCode\\Bin folder, | |||
|
199 | just type:: | |||
|
200 | ||||
|
201 | paster serve production.ini | |||
|
202 | ||||
|
203 | Open yout web server, and go to http://127.0.0.1:5000 | |||
|
204 | ||||
|
205 | It works!! :-) | |||
|
206 | ||||
|
207 | Remark: | |||
|
208 | If it does not work first time, just Ctrl-C the CMD process and start it | |||
|
209 | again. Don't forget the "http://" in Internet Explorer | |||
|
210 | ||||
|
211 | ||||
|
212 | ||||
|
213 | What this Guide does not cover: | |||
|
214 | ||||
|
215 | - Installing Celery | |||
|
216 | - Running RhodeCode as Windows Service. You can investigate here: | |||
|
217 | ||||
|
218 | - http://pypi.python.org/pypi/wsgisvc | |||
|
219 | - http://ryrobes.com/python/running-python-scripts-as-a-windows-service/ | |||
|
220 | - http://wiki.pylonshq.com/display/pylonscookbook/How+to+run+Pylons+as+a+Windows+service | |||
|
221 | ||||
|
222 | - Using Apache. You can investigate here: | |||
|
223 | ||||
|
224 | - https://groups.google.com/group/rhodecode/msg/c433074e813ffdc4 | |||
|
225 | ||||
|
226 | ||||
|
227 | Upgrading | |||
|
228 | ========= | |||
|
229 | ||||
|
230 | Stop running RhodeCode | |||
|
231 | Open a CommandPrompt like in Step7 (VS2008 path + activate) and type:: | |||
|
232 | ||||
|
233 | easy_install -U rhodecode | |||
|
234 | cd \RhodeCode\Bin | |||
|
235 | ||||
|
236 | { backup your production.ini file now} :: | |||
|
237 | ||||
|
238 | paster make-config RhodeCode production.ini | |||
|
239 | ||||
|
240 | (check changes and update your production.ini accordingly) :: | |||
|
241 | ||||
|
242 | paster upgrade-db production.ini (update database) | |||
|
243 | ||||
|
244 | Full steps in http://packages.python.org/RhodeCode/upgrade.html No newline at end of file |
@@ -1,124 +1,129 | |||||
1 | .. _installation: |
|
1 | .. _installation: | |
2 |
|
2 | |||
3 | ============ |
|
3 | ============ | |
4 | Installation |
|
4 | Installation | |
5 | ============ |
|
5 | ============ | |
6 |
|
6 | |||
7 | ``RhodeCode`` is written entirely in Python. Before posting any issues make |
|
7 | ``RhodeCode`` is written entirely in Python. Before posting any issues make | |
8 | sure, your not missing any system libraries and using right version of |
|
8 | sure, your not missing any system libraries and using right version of | |
9 | libraries required by RhodeCode. There's also restriction in terms of mercurial |
|
9 | libraries required by RhodeCode. There's also restriction in terms of mercurial | |
10 | clients. Minimal version of hg client known working fine with RhodeCode is |
|
10 | clients. Minimal version of hg client known working fine with RhodeCode is | |
11 | **1.6**. If you're using older client, please upgrade. |
|
11 | **1.6**. If you're using older client, please upgrade. | |
12 |
|
12 | |||
13 |
|
13 | |||
14 | Installing RhodeCode from Cheese Shop |
|
14 | Installing RhodeCode from Cheese Shop | |
15 | ------------------------------------- |
|
15 | ------------------------------------- | |
16 |
|
16 | |||
17 | Rhodecode requires python version 2.5 or higher. |
|
17 | Rhodecode requires python version 2.5 or higher. | |
18 |
|
18 | |||
19 | The easiest way to install ``rhodecode`` is to run:: |
|
19 | The easiest way to install ``rhodecode`` is to run:: | |
20 |
|
20 | |||
21 | easy_install rhodecode |
|
21 | easy_install rhodecode | |
22 |
|
22 | |||
23 | Or:: |
|
23 | Or:: | |
24 |
|
24 | |||
25 | pip install rhodecode |
|
25 | pip install rhodecode | |
26 |
|
26 | |||
27 | If you prefer to install RhodeCode manually simply grab latest release from |
|
27 | If you prefer to install RhodeCode manually simply grab latest release from | |
28 | http://pypi.python.org/pypi/RhodeCode, decompress the archive and run:: |
|
28 | http://pypi.python.org/pypi/RhodeCode, decompress the archive and run:: | |
29 |
|
29 | |||
30 | python setup.py install |
|
30 | python setup.py install | |
31 |
|
31 | |||
|
32 | Step by step installation example for Windows | |||
|
33 | --------------------------------------------- | |||
32 |
|
34 | |||
33 | Step by step installation example |
|
35 | :ref:`installation_win` | |
34 | --------------------------------- |
|
36 | ||
|
37 | ||||
|
38 | Step by step installation example for Linux | |||
|
39 | ------------------------------------------- | |||
35 |
|
40 | |||
36 |
|
41 | |||
37 | For installing RhodeCode i highly recommend using separate virtualenv_. This |
|
42 | For installing RhodeCode i highly recommend using separate virtualenv_. This | |
38 | way many required by RhodeCode libraries will remain sandboxed from your main |
|
43 | way many required by RhodeCode libraries will remain sandboxed from your main | |
39 | python and making things less problematic when doing system python updates. |
|
44 | python and making things less problematic when doing system python updates. | |
40 |
|
45 | |||
41 | - Assuming you have installed virtualenv_ create a new virtual environment |
|
46 | - Assuming you have installed virtualenv_ create a new virtual environment | |
42 | using virtualenv command:: |
|
47 | using virtualenv command:: | |
43 |
|
48 | |||
44 | virtualenv --no-site-packages /var/www/rhodecode-venv |
|
49 | virtualenv --no-site-packages /var/www/rhodecode-venv | |
45 |
|
50 | |||
46 |
|
51 | |||
47 | .. note:: Using ``--no-site-packages`` when generating your |
|
52 | .. note:: Using ``--no-site-packages`` when generating your | |
48 | virtualenv is **very important**. This flag provides the necessary |
|
53 | virtualenv is **very important**. This flag provides the necessary | |
49 | isolation for running the set of packages required by |
|
54 | isolation for running the set of packages required by | |
50 | RhodeCode. If you do not specify ``--no-site-packages``, |
|
55 | RhodeCode. If you do not specify ``--no-site-packages``, | |
51 | it's possible that RhodeCode will not install properly into |
|
56 | it's possible that RhodeCode will not install properly into | |
52 | the virtualenv, or, even if it does, may not run properly, |
|
57 | the virtualenv, or, even if it does, may not run properly, | |
53 | depending on the packages you've already got installed into your |
|
58 | depending on the packages you've already got installed into your | |
54 | Python's "main" site-packages dir. |
|
59 | Python's "main" site-packages dir. | |
55 |
|
60 | |||
56 |
|
61 | |||
57 | - this will install new virtualenv_ into `/var/www/rhodecode-venv`. |
|
62 | - this will install new virtualenv_ into `/var/www/rhodecode-venv`. | |
58 | - Activate the virtualenv_ by running:: |
|
63 | - Activate the virtualenv_ by running:: | |
59 |
|
64 | |||
60 | source /var/www/rhodecode-venv/bin/activate |
|
65 | source /var/www/rhodecode-venv/bin/activate | |
61 |
|
66 | |||
62 | .. note:: If you're using UNIX, *do not* use ``sudo`` to run the |
|
67 | .. note:: If you're using UNIX, *do not* use ``sudo`` to run the | |
63 | ``virtualenv`` script. It's perfectly acceptable (and desirable) |
|
68 | ``virtualenv`` script. It's perfectly acceptable (and desirable) | |
64 | to create a virtualenv as a normal user. |
|
69 | to create a virtualenv as a normal user. | |
65 |
|
70 | |||
66 | - Make a folder for rhodecode data files, and configuration somewhere on the |
|
71 | - Make a folder for rhodecode data files, and configuration somewhere on the | |
67 | filesystem. For example:: |
|
72 | filesystem. For example:: | |
68 |
|
73 | |||
69 | mkdir /var/www/rhodecode |
|
74 | mkdir /var/www/rhodecode | |
70 |
|
75 | |||
71 |
|
76 | |||
72 | - Go into the created directory run this command to install rhodecode:: |
|
77 | - Go into the created directory run this command to install rhodecode:: | |
73 |
|
78 | |||
74 | easy_install rhodecode |
|
79 | easy_install rhodecode | |
75 |
|
80 | |||
76 | or:: |
|
81 | or:: | |
77 |
|
82 | |||
78 | pip install rhodecode |
|
83 | pip install rhodecode | |
79 |
|
84 | |||
80 | - This will install rhodecode together with pylons and all other required |
|
85 | - This will install rhodecode together with pylons and all other required | |
81 | python libraries into activated virtualenv |
|
86 | python libraries into activated virtualenv | |
82 |
|
87 | |||
83 | Requirements for Celery (optional) |
|
88 | Requirements for Celery (optional) | |
84 | ---------------------------------- |
|
89 | ---------------------------------- | |
85 |
|
90 | |||
86 | In order to gain maximum performance |
|
91 | In order to gain maximum performance | |
87 | there are some third-party you must install. When RhodeCode is used |
|
92 | there are some third-party you must install. When RhodeCode is used | |
88 | together with celery you have to install some kind of message broker, |
|
93 | together with celery you have to install some kind of message broker, | |
89 | recommended one is rabbitmq_ to make the async tasks work. |
|
94 | recommended one is rabbitmq_ to make the async tasks work. | |
90 |
|
95 | |||
91 | Of course RhodeCode works in sync mode also and then you do not have to install |
|
96 | Of course RhodeCode works in sync mode also and then you do not have to install | |
92 | any third party applications. However, using Celery_ will give you a large |
|
97 | any third party applications. However, using Celery_ will give you a large | |
93 | speed improvement when using many big repositories. If you plan to use |
|
98 | speed improvement when using many big repositories. If you plan to use | |
94 | RhodeCode for say 7 to 10 repositories, RhodeCode will perform perfectly well |
|
99 | RhodeCode for say 7 to 10 repositories, RhodeCode will perform perfectly well | |
95 | without celery running. |
|
100 | without celery running. | |
96 |
|
101 | |||
97 | If you make the decision to run RhodeCode with celery make sure you run |
|
102 | If you make the decision to run RhodeCode with celery make sure you run | |
98 | celeryd using paster and message broker together with the application. |
|
103 | celeryd using paster and message broker together with the application. | |
99 |
|
104 | |||
100 | .. note:: |
|
105 | .. note:: | |
101 | Installing message broker and using celery is optional, RhodeCode will |
|
106 | Installing message broker and using celery is optional, RhodeCode will | |
102 | work perfectly fine without them. |
|
107 | work perfectly fine without them. | |
103 |
|
108 | |||
104 |
|
109 | |||
105 | **Message Broker** |
|
110 | **Message Broker** | |
106 |
|
111 | |||
107 | - preferred is `RabbitMq <http://www.rabbitmq.com/>`_ |
|
112 | - preferred is `RabbitMq <http://www.rabbitmq.com/>`_ | |
108 | - A possible alternative is `Redis <http://code.google.com/p/redis/>`_ |
|
113 | - A possible alternative is `Redis <http://code.google.com/p/redis/>`_ | |
109 |
|
114 | |||
110 | For installation instructions you can visit: |
|
115 | For installation instructions you can visit: | |
111 | http://ask.github.com/celery/getting-started/index.html. |
|
116 | http://ask.github.com/celery/getting-started/index.html. | |
112 | This is a very nice tutorial on how to start using celery_ with rabbitmq_ |
|
117 | This is a very nice tutorial on how to start using celery_ with rabbitmq_ | |
113 |
|
118 | |||
114 |
|
119 | |||
115 | You can now proceed to :ref:`setup` |
|
120 | You can now proceed to :ref:`setup` | |
116 | ----------------------------------- |
|
121 | ----------------------------------- | |
117 |
|
122 | |||
118 |
|
123 | |||
119 |
|
124 | |||
120 | .. _virtualenv: http://pypi.python.org/pypi/virtualenv |
|
125 | .. _virtualenv: http://pypi.python.org/pypi/virtualenv | |
121 | .. _python: http://www.python.org/ |
|
126 | .. _python: http://www.python.org/ | |
122 | .. _mercurial: http://mercurial.selenic.com/ |
|
127 | .. _mercurial: http://mercurial.selenic.com/ | |
123 | .. _celery: http://celeryproject.org/ |
|
128 | .. _celery: http://celeryproject.org/ | |
124 | .. _rabbitmq: http://www.rabbitmq.com/ No newline at end of file |
|
129 | .. _rabbitmq: http://www.rabbitmq.com/ |
@@ -1,732 +1,737 | |||||
1 | .. _setup: |
|
1 | .. _setup: | |
2 |
|
2 | |||
3 | ===== |
|
3 | ===== | |
4 | Setup |
|
4 | Setup | |
5 | ===== |
|
5 | ===== | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | Setting up RhodeCode |
|
8 | Setting up RhodeCode | |
9 | -------------------- |
|
9 | -------------------- | |
10 |
|
10 | |||
11 | First, you will need to create a RhodeCode configuration file. Run the |
|
11 | First, you will need to create a RhodeCode configuration file. Run the | |
12 | following command to do this:: |
|
12 | following command to do this:: | |
13 |
|
13 | |||
14 | paster make-config RhodeCode production.ini |
|
14 | paster make-config RhodeCode production.ini | |
15 |
|
15 | |||
16 | - This will create the file `production.ini` in the current directory. This |
|
16 | - This will create the file `production.ini` in the current directory. This | |
17 | configuration file contains the various settings for RhodeCode, e.g proxy |
|
17 | configuration file contains the various settings for RhodeCode, e.g proxy | |
18 | port, email settings, usage of static files, cache, celery settings and |
|
18 | port, email settings, usage of static files, cache, celery settings and | |
19 | logging. |
|
19 | logging. | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | Next, you need to create the databases used by RhodeCode. I recommend that you |
|
22 | Next, you need to create the databases used by RhodeCode. I recommend that you | |
23 | use postgresql or sqlite (default). If you choose a database other than the |
|
23 | use postgresql or sqlite (default). If you choose a database other than the | |
24 | default ensure you properly adjust the db url in your production.ini |
|
24 | default ensure you properly adjust the db url in your production.ini | |
25 | configuration file to use this other database. RhodeCode currently supports |
|
25 | configuration file to use this other database. RhodeCode currently supports | |
26 | postgresql, sqlite and mysql databases. Create the database by running |
|
26 | postgresql, sqlite and mysql databases. Create the database by running | |
27 | the following command:: |
|
27 | the following command:: | |
28 |
|
28 | |||
29 | paster setup-rhodecode production.ini |
|
29 | paster setup-rhodecode production.ini | |
30 |
|
30 | |||
31 | This will prompt you for a "root" path. This "root" path is the location where |
|
31 | This will prompt you for a "root" path. This "root" path is the location where | |
32 | RhodeCode will store all of its repositories on the current machine. After |
|
32 | RhodeCode will store all of its repositories on the current machine. After | |
33 | entering this "root" path ``setup-rhodecode`` will also prompt you for a username |
|
33 | entering this "root" path ``setup-rhodecode`` will also prompt you for a username | |
34 | and password for the initial admin account which ``setup-rhodecode`` sets |
|
34 | and password for the initial admin account which ``setup-rhodecode`` sets | |
35 | up for you. |
|
35 | up for you. | |
36 |
|
36 | |||
|
37 | setup process can be fully automated, example for lazy:: | |||
|
38 | ||||
|
39 | paster setup-rhodecode production.ini --user=marcink --password=secret --email=marcin@rhodecode.org --repos=/home/marcink/my_repos | |||
|
40 | ||||
|
41 | ||||
37 | - The ``setup-rhodecode`` command will create all of the needed tables and an |
|
42 | - The ``setup-rhodecode`` command will create all of the needed tables and an | |
38 | admin account. When choosing a root path you can either use a new empty |
|
43 | admin account. When choosing a root path you can either use a new empty | |
39 | location, or a location which already contains existing repositories. If you |
|
44 | location, or a location which already contains existing repositories. If you | |
40 | choose a location which contains existing repositories RhodeCode will simply |
|
45 | choose a location which contains existing repositories RhodeCode will simply | |
41 | add all of the repositories at the chosen location to it's database. |
|
46 | add all of the repositories at the chosen location to it's database. | |
42 | (Note: make sure you specify the correct path to the root). |
|
47 | (Note: make sure you specify the correct path to the root). | |
43 | - Note: the given path for mercurial_ repositories **must** be write accessible |
|
48 | - Note: the given path for mercurial_ repositories **must** be write accessible | |
44 | for the application. It's very important since the RhodeCode web interface |
|
49 | for the application. It's very important since the RhodeCode web interface | |
45 | will work without write access, but when trying to do a push it will |
|
50 | will work without write access, but when trying to do a push it will | |
46 | eventually fail with permission denied errors unless it has write access. |
|
51 | eventually fail with permission denied errors unless it has write access. | |
47 |
|
52 | |||
48 | You are now ready to use RhodeCode, to run it simply execute:: |
|
53 | You are now ready to use RhodeCode, to run it simply execute:: | |
49 |
|
54 | |||
50 | paster serve production.ini |
|
55 | paster serve production.ini | |
51 |
|
56 | |||
52 | - This command runs the RhodeCode server. The web app should be available at the |
|
57 | - This command runs the RhodeCode server. The web app should be available at the | |
53 | 127.0.0.1:5000. This ip and port is configurable via the production.ini |
|
58 | 127.0.0.1:5000. This ip and port is configurable via the production.ini | |
54 | file created in previous step |
|
59 | file created in previous step | |
55 | - Use the admin account you created above when running ``setup-rhodecode`` |
|
60 | - Use the admin account you created above when running ``setup-rhodecode`` | |
56 | to login to the web app. |
|
61 | to login to the web app. | |
57 | - The default permissions on each repository is read, and the owner is admin. |
|
62 | - The default permissions on each repository is read, and the owner is admin. | |
58 | Remember to update these if needed. |
|
63 | Remember to update these if needed. | |
59 | - In the admin panel you can toggle ldap, anonymous, permissions settings. As |
|
64 | - In the admin panel you can toggle ldap, anonymous, permissions settings. As | |
60 | well as edit more advanced options on users and repositories |
|
65 | well as edit more advanced options on users and repositories | |
61 |
|
66 | |||
62 | Optionally users can create `rcextensions` package that extends RhodeCode |
|
67 | Optionally users can create `rcextensions` package that extends RhodeCode | |
63 | functionality. To do this simply execute:: |
|
68 | functionality. To do this simply execute:: | |
64 |
|
69 | |||
65 | paster make-rcext production.ini |
|
70 | paster make-rcext production.ini | |
66 |
|
71 | |||
67 | This will create `rcextensions` package in the same place that your `ini` file |
|
72 | This will create `rcextensions` package in the same place that your `ini` file | |
68 | lives. With `rcextensions` it's possible to add additional mapping for whoosh, |
|
73 | lives. With `rcextensions` it's possible to add additional mapping for whoosh, | |
69 | stats and add additional code into the push/pull/create repo hooks. For example |
|
74 | stats and add additional code into the push/pull/create repo hooks. For example | |
70 | for sending signals to build-bots such as jenkins. |
|
75 | for sending signals to build-bots such as jenkins. | |
71 | Please see the `__init__.py` file inside `rcextensions` package |
|
76 | Please see the `__init__.py` file inside `rcextensions` package | |
72 | for more details. |
|
77 | for more details. | |
73 |
|
78 | |||
74 |
|
79 | |||
75 | Using RhodeCode with SSH |
|
80 | Using RhodeCode with SSH | |
76 | ------------------------ |
|
81 | ------------------------ | |
77 |
|
82 | |||
78 | RhodeCode currently only hosts repositories using http and https. (The addition |
|
83 | RhodeCode currently only hosts repositories using http and https. (The addition | |
79 | of ssh hosting is a planned future feature.) However you can easily use ssh in |
|
84 | of ssh hosting is a planned future feature.) However you can easily use ssh in | |
80 | parallel with RhodeCode. (Repository access via ssh is a standard "out of |
|
85 | parallel with RhodeCode. (Repository access via ssh is a standard "out of | |
81 | the box" feature of mercurial_ and you can use this to access any of the |
|
86 | the box" feature of mercurial_ and you can use this to access any of the | |
82 | repositories that RhodeCode is hosting. See PublishingRepositories_) |
|
87 | repositories that RhodeCode is hosting. See PublishingRepositories_) | |
83 |
|
88 | |||
84 | RhodeCode repository structures are kept in directories with the same name |
|
89 | RhodeCode repository structures are kept in directories with the same name | |
85 | as the project. When using repository groups, each group is a subdirectory. |
|
90 | as the project. When using repository groups, each group is a subdirectory. | |
86 | This allows you to easily use ssh for accessing repositories. |
|
91 | This allows you to easily use ssh for accessing repositories. | |
87 |
|
92 | |||
88 | In order to use ssh you need to make sure that your web-server and the users |
|
93 | In order to use ssh you need to make sure that your web-server and the users | |
89 | login accounts have the correct permissions set on the appropriate directories. |
|
94 | login accounts have the correct permissions set on the appropriate directories. | |
90 | (Note that these permissions are independent of any permissions you have set up |
|
95 | (Note that these permissions are independent of any permissions you have set up | |
91 | using the RhodeCode web interface.) |
|
96 | using the RhodeCode web interface.) | |
92 |
|
97 | |||
93 | If your main directory (the same as set in RhodeCode settings) is for example |
|
98 | If your main directory (the same as set in RhodeCode settings) is for example | |
94 | set to **/home/hg** and the repository you are using is named `rhodecode`, then |
|
99 | set to **/home/hg** and the repository you are using is named `rhodecode`, then | |
95 | to clone via ssh you should run:: |
|
100 | to clone via ssh you should run:: | |
96 |
|
101 | |||
97 | hg clone ssh://user@server.com/home/hg/rhodecode |
|
102 | hg clone ssh://user@server.com/home/hg/rhodecode | |
98 |
|
103 | |||
99 | Using other external tools such as mercurial-server_ or using ssh key based |
|
104 | Using other external tools such as mercurial-server_ or using ssh key based | |
100 | authentication is fully supported. |
|
105 | authentication is fully supported. | |
101 |
|
106 | |||
102 | Note: In an advanced setup, in order for your ssh access to use the same |
|
107 | Note: In an advanced setup, in order for your ssh access to use the same | |
103 | permissions as set up via the RhodeCode web interface, you can create an |
|
108 | permissions as set up via the RhodeCode web interface, you can create an | |
104 | authentication hook to connect to the rhodecode db and runs check functions for |
|
109 | authentication hook to connect to the rhodecode db and runs check functions for | |
105 | permissions against that. |
|
110 | permissions against that. | |
106 |
|
111 | |||
107 | Setting up Whoosh full text search |
|
112 | Setting up Whoosh full text search | |
108 | ---------------------------------- |
|
113 | ---------------------------------- | |
109 |
|
114 | |||
110 | Starting from version 1.1 the whoosh index can be build by using the paster |
|
115 | Starting from version 1.1 the whoosh index can be build by using the paster | |
111 | command ``make-index``. To use ``make-index`` you must specify the configuration |
|
116 | command ``make-index``. To use ``make-index`` you must specify the configuration | |
112 | file that stores the location of the index. You may specify the location of the |
|
117 | file that stores the location of the index. You may specify the location of the | |
113 | repositories (`--repo-location`). If not specified, this value is retrieved |
|
118 | repositories (`--repo-location`). If not specified, this value is retrieved | |
114 | from the RhodeCode database. This was required prior to 1.2. Starting from |
|
119 | from the RhodeCode database. This was required prior to 1.2. Starting from | |
115 | version 1.2 it is also possible to specify a comma separated list of |
|
120 | version 1.2 it is also possible to specify a comma separated list of | |
116 | repositories (`--index-only`) to build index only on chooses repositories |
|
121 | repositories (`--index-only`) to build index only on chooses repositories | |
117 | skipping any other found in repos location |
|
122 | skipping any other found in repos location | |
118 |
|
123 | |||
119 | You may optionally pass the option `-f` to enable a full index rebuild. Without |
|
124 | You may optionally pass the option `-f` to enable a full index rebuild. Without | |
120 | the `-f` option, indexing will run always in "incremental" mode. |
|
125 | the `-f` option, indexing will run always in "incremental" mode. | |
121 |
|
126 | |||
122 | For an incremental index build use:: |
|
127 | For an incremental index build use:: | |
123 |
|
128 | |||
124 | paster make-index production.ini |
|
129 | paster make-index production.ini | |
125 |
|
130 | |||
126 | For a full index rebuild use:: |
|
131 | For a full index rebuild use:: | |
127 |
|
132 | |||
128 | paster make-index production.ini -f |
|
133 | paster make-index production.ini -f | |
129 |
|
134 | |||
130 |
|
135 | |||
131 | building index just for chosen repositories is possible with such command:: |
|
136 | building index just for chosen repositories is possible with such command:: | |
132 |
|
137 | |||
133 | paster make-index production.ini --index-only=vcs,rhodecode |
|
138 | paster make-index production.ini --index-only=vcs,rhodecode | |
134 |
|
139 | |||
135 |
|
140 | |||
136 | In order to do periodical index builds and keep your index always up to date. |
|
141 | In order to do periodical index builds and keep your index always up to date. | |
137 | It's recommended to do a crontab entry for incremental indexing. |
|
142 | It's recommended to do a crontab entry for incremental indexing. | |
138 | An example entry might look like this:: |
|
143 | An example entry might look like this:: | |
139 |
|
144 | |||
140 | /path/to/python/bin/paster make-index /path/to/rhodecode/production.ini |
|
145 | /path/to/python/bin/paster make-index /path/to/rhodecode/production.ini | |
141 |
|
146 | |||
142 | When using incremental mode (the default) whoosh will check the last |
|
147 | When using incremental mode (the default) whoosh will check the last | |
143 | modification date of each file and add it to be reindexed if a newer file is |
|
148 | modification date of each file and add it to be reindexed if a newer file is | |
144 | available. The indexing daemon checks for any removed files and removes them |
|
149 | available. The indexing daemon checks for any removed files and removes them | |
145 | from index. |
|
150 | from index. | |
146 |
|
151 | |||
147 | If you want to rebuild index from scratch, you can use the `-f` flag as above, |
|
152 | If you want to rebuild index from scratch, you can use the `-f` flag as above, | |
148 | or in the admin panel you can check `build from scratch` flag. |
|
153 | or in the admin panel you can check `build from scratch` flag. | |
149 |
|
154 | |||
150 |
|
155 | |||
151 | Setting up LDAP support |
|
156 | Setting up LDAP support | |
152 | ----------------------- |
|
157 | ----------------------- | |
153 |
|
158 | |||
154 | RhodeCode starting from version 1.1 supports ldap authentication. In order |
|
159 | RhodeCode starting from version 1.1 supports ldap authentication. In order | |
155 | to use LDAP, you have to install the python-ldap_ package. This package is |
|
160 | to use LDAP, you have to install the python-ldap_ package. This package is | |
156 | available via pypi, so you can install it by running |
|
161 | available via pypi, so you can install it by running | |
157 |
|
162 | |||
158 | using easy_install:: |
|
163 | using easy_install:: | |
159 |
|
164 | |||
160 | easy_install python-ldap |
|
165 | easy_install python-ldap | |
161 |
|
166 | |||
162 | using pip:: |
|
167 | using pip:: | |
163 |
|
168 | |||
164 | pip install python-ldap |
|
169 | pip install python-ldap | |
165 |
|
170 | |||
166 | .. note:: |
|
171 | .. note:: | |
167 | python-ldap requires some certain libs on your system, so before installing |
|
172 | python-ldap requires some certain libs on your system, so before installing | |
168 | it check that you have at least `openldap`, and `sasl` libraries. |
|
173 | it check that you have at least `openldap`, and `sasl` libraries. | |
169 |
|
174 | |||
170 | LDAP settings are located in admin->ldap section, |
|
175 | LDAP settings are located in admin->ldap section, | |
171 |
|
176 | |||
172 | Here's a typical ldap setup:: |
|
177 | Here's a typical ldap setup:: | |
173 |
|
178 | |||
174 | Connection settings |
|
179 | Connection settings | |
175 | Enable LDAP = checked |
|
180 | Enable LDAP = checked | |
176 | Host = host.example.org |
|
181 | Host = host.example.org | |
177 | Port = 389 |
|
182 | Port = 389 | |
178 | Account = <account> |
|
183 | Account = <account> | |
179 | Password = <password> |
|
184 | Password = <password> | |
180 | Connection Security = LDAPS connection |
|
185 | Connection Security = LDAPS connection | |
181 | Certificate Checks = DEMAND |
|
186 | Certificate Checks = DEMAND | |
182 |
|
187 | |||
183 | Search settings |
|
188 | Search settings | |
184 | Base DN = CN=users,DC=host,DC=example,DC=org |
|
189 | Base DN = CN=users,DC=host,DC=example,DC=org | |
185 | LDAP Filter = (&(objectClass=user)(!(objectClass=computer))) |
|
190 | LDAP Filter = (&(objectClass=user)(!(objectClass=computer))) | |
186 | LDAP Search Scope = SUBTREE |
|
191 | LDAP Search Scope = SUBTREE | |
187 |
|
192 | |||
188 | Attribute mappings |
|
193 | Attribute mappings | |
189 | Login Attribute = uid |
|
194 | Login Attribute = uid | |
190 | First Name Attribute = firstName |
|
195 | First Name Attribute = firstName | |
191 | Last Name Attribute = lastName |
|
196 | Last Name Attribute = lastName | |
192 | E-mail Attribute = mail |
|
197 | E-mail Attribute = mail | |
193 |
|
198 | |||
194 | .. _enable_ldap: |
|
199 | .. _enable_ldap: | |
195 |
|
200 | |||
196 | Enable LDAP : required |
|
201 | Enable LDAP : required | |
197 | Whether to use LDAP for authenticating users. |
|
202 | Whether to use LDAP for authenticating users. | |
198 |
|
203 | |||
199 | .. _ldap_host: |
|
204 | .. _ldap_host: | |
200 |
|
205 | |||
201 | Host : required |
|
206 | Host : required | |
202 | LDAP server hostname or IP address. |
|
207 | LDAP server hostname or IP address. | |
203 |
|
208 | |||
204 | .. _Port: |
|
209 | .. _Port: | |
205 |
|
210 | |||
206 | Port : required |
|
211 | Port : required | |
207 | 389 for un-encrypted LDAP, 636 for SSL-encrypted LDAP. |
|
212 | 389 for un-encrypted LDAP, 636 for SSL-encrypted LDAP. | |
208 |
|
213 | |||
209 | .. _ldap_account: |
|
214 | .. _ldap_account: | |
210 |
|
215 | |||
211 | Account : optional |
|
216 | Account : optional | |
212 | Only required if the LDAP server does not allow anonymous browsing of |
|
217 | Only required if the LDAP server does not allow anonymous browsing of | |
213 | records. This should be a special account for record browsing. This |
|
218 | records. This should be a special account for record browsing. This | |
214 | will require `LDAP Password`_ below. |
|
219 | will require `LDAP Password`_ below. | |
215 |
|
220 | |||
216 | .. _LDAP Password: |
|
221 | .. _LDAP Password: | |
217 |
|
222 | |||
218 | Password : optional |
|
223 | Password : optional | |
219 | Only required if the LDAP server does not allow anonymous browsing of |
|
224 | Only required if the LDAP server does not allow anonymous browsing of | |
220 | records. |
|
225 | records. | |
221 |
|
226 | |||
222 | .. _Enable LDAPS: |
|
227 | .. _Enable LDAPS: | |
223 |
|
228 | |||
224 | Connection Security : required |
|
229 | Connection Security : required | |
225 | Defines the connection to LDAP server |
|
230 | Defines the connection to LDAP server | |
226 |
|
231 | |||
227 | No encryption |
|
232 | No encryption | |
228 | Plain non encrypted connection |
|
233 | Plain non encrypted connection | |
229 |
|
234 | |||
230 | LDAPS connection |
|
235 | LDAPS connection | |
231 | Enable ldaps connection. It will likely require `Port`_ to be set to |
|
236 | Enable ldaps connection. It will likely require `Port`_ to be set to | |
232 | a different value (standard LDAPS port is 636). When LDAPS is enabled |
|
237 | a different value (standard LDAPS port is 636). When LDAPS is enabled | |
233 | then `Certificate Checks`_ is required. |
|
238 | then `Certificate Checks`_ is required. | |
234 |
|
239 | |||
235 | START_TLS on LDAP connection |
|
240 | START_TLS on LDAP connection | |
236 | START TLS connection |
|
241 | START TLS connection | |
237 |
|
242 | |||
238 | .. _Certificate Checks: |
|
243 | .. _Certificate Checks: | |
239 |
|
244 | |||
240 | Certificate Checks : optional |
|
245 | Certificate Checks : optional | |
241 | How SSL certificates verification is handled - this is only useful when |
|
246 | How SSL certificates verification is handled - this is only useful when | |
242 | `Enable LDAPS`_ is enabled. Only DEMAND or HARD offer full SSL security |
|
247 | `Enable LDAPS`_ is enabled. Only DEMAND or HARD offer full SSL security | |
243 | while the other options are susceptible to man-in-the-middle attacks. SSL |
|
248 | while the other options are susceptible to man-in-the-middle attacks. SSL | |
244 | certificates can be installed to /etc/openldap/cacerts so that the |
|
249 | certificates can be installed to /etc/openldap/cacerts so that the | |
245 | DEMAND or HARD options can be used with self-signed certificates or |
|
250 | DEMAND or HARD options can be used with self-signed certificates or | |
246 | certificates that do not have traceable certificates of authority. |
|
251 | certificates that do not have traceable certificates of authority. | |
247 |
|
252 | |||
248 | NEVER |
|
253 | NEVER | |
249 | A serve certificate will never be requested or checked. |
|
254 | A serve certificate will never be requested or checked. | |
250 |
|
255 | |||
251 | ALLOW |
|
256 | ALLOW | |
252 | A server certificate is requested. Failure to provide a |
|
257 | A server certificate is requested. Failure to provide a | |
253 | certificate or providing a bad certificate will not terminate the |
|
258 | certificate or providing a bad certificate will not terminate the | |
254 | session. |
|
259 | session. | |
255 |
|
260 | |||
256 | TRY |
|
261 | TRY | |
257 | A server certificate is requested. Failure to provide a |
|
262 | A server certificate is requested. Failure to provide a | |
258 | certificate does not halt the session; providing a bad certificate |
|
263 | certificate does not halt the session; providing a bad certificate | |
259 | halts the session. |
|
264 | halts the session. | |
260 |
|
265 | |||
261 | DEMAND |
|
266 | DEMAND | |
262 | A server certificate is requested and must be provided and |
|
267 | A server certificate is requested and must be provided and | |
263 | authenticated for the session to proceed. |
|
268 | authenticated for the session to proceed. | |
264 |
|
269 | |||
265 | HARD |
|
270 | HARD | |
266 | The same as DEMAND. |
|
271 | The same as DEMAND. | |
267 |
|
272 | |||
268 | .. _Base DN: |
|
273 | .. _Base DN: | |
269 |
|
274 | |||
270 | Base DN : required |
|
275 | Base DN : required | |
271 | The Distinguished Name (DN) where searches for users will be performed. |
|
276 | The Distinguished Name (DN) where searches for users will be performed. | |
272 | Searches can be controlled by `LDAP Filter`_ and `LDAP Search Scope`_. |
|
277 | Searches can be controlled by `LDAP Filter`_ and `LDAP Search Scope`_. | |
273 |
|
278 | |||
274 | .. _LDAP Filter: |
|
279 | .. _LDAP Filter: | |
275 |
|
280 | |||
276 | LDAP Filter : optional |
|
281 | LDAP Filter : optional | |
277 | A LDAP filter defined by RFC 2254. This is more useful when `LDAP |
|
282 | A LDAP filter defined by RFC 2254. This is more useful when `LDAP | |
278 | Search Scope`_ is set to SUBTREE. The filter is useful for limiting |
|
283 | Search Scope`_ is set to SUBTREE. The filter is useful for limiting | |
279 | which LDAP objects are identified as representing Users for |
|
284 | which LDAP objects are identified as representing Users for | |
280 | authentication. The filter is augmented by `Login Attribute`_ below. |
|
285 | authentication. The filter is augmented by `Login Attribute`_ below. | |
281 | This can commonly be left blank. |
|
286 | This can commonly be left blank. | |
282 |
|
287 | |||
283 | .. _LDAP Search Scope: |
|
288 | .. _LDAP Search Scope: | |
284 |
|
289 | |||
285 | LDAP Search Scope : required |
|
290 | LDAP Search Scope : required | |
286 | This limits how far LDAP will search for a matching object. |
|
291 | This limits how far LDAP will search for a matching object. | |
287 |
|
292 | |||
288 | BASE |
|
293 | BASE | |
289 | Only allows searching of `Base DN`_ and is usually not what you |
|
294 | Only allows searching of `Base DN`_ and is usually not what you | |
290 | want. |
|
295 | want. | |
291 |
|
296 | |||
292 | ONELEVEL |
|
297 | ONELEVEL | |
293 | Searches all entries under `Base DN`_, but not Base DN itself. |
|
298 | Searches all entries under `Base DN`_, but not Base DN itself. | |
294 |
|
299 | |||
295 | SUBTREE |
|
300 | SUBTREE | |
296 | Searches all entries below `Base DN`_, but not Base DN itself. |
|
301 | Searches all entries below `Base DN`_, but not Base DN itself. | |
297 | When using SUBTREE `LDAP Filter`_ is useful to limit object |
|
302 | When using SUBTREE `LDAP Filter`_ is useful to limit object | |
298 | location. |
|
303 | location. | |
299 |
|
304 | |||
300 | .. _Login Attribute: |
|
305 | .. _Login Attribute: | |
301 |
|
306 | |||
302 | Login Attribute : required |
|
307 | Login Attribute : required | |
303 | The LDAP record attribute that will be matched as the USERNAME or |
|
308 | The LDAP record attribute that will be matched as the USERNAME or | |
304 | ACCOUNT used to connect to RhodeCode. This will be added to `LDAP |
|
309 | ACCOUNT used to connect to RhodeCode. This will be added to `LDAP | |
305 | Filter`_ for locating the User object. If `LDAP Filter`_ is specified as |
|
310 | Filter`_ for locating the User object. If `LDAP Filter`_ is specified as | |
306 | "LDAPFILTER", `Login Attribute`_ is specified as "uid" and the user has |
|
311 | "LDAPFILTER", `Login Attribute`_ is specified as "uid" and the user has | |
307 | connected as "jsmith" then the `LDAP Filter`_ will be augmented as below |
|
312 | connected as "jsmith" then the `LDAP Filter`_ will be augmented as below | |
308 | :: |
|
313 | :: | |
309 |
|
314 | |||
310 | (&(LDAPFILTER)(uid=jsmith)) |
|
315 | (&(LDAPFILTER)(uid=jsmith)) | |
311 |
|
316 | |||
312 | .. _ldap_attr_firstname: |
|
317 | .. _ldap_attr_firstname: | |
313 |
|
318 | |||
314 | First Name Attribute : required |
|
319 | First Name Attribute : required | |
315 | The LDAP record attribute which represents the user's first name. |
|
320 | The LDAP record attribute which represents the user's first name. | |
316 |
|
321 | |||
317 | .. _ldap_attr_lastname: |
|
322 | .. _ldap_attr_lastname: | |
318 |
|
323 | |||
319 | Last Name Attribute : required |
|
324 | Last Name Attribute : required | |
320 | The LDAP record attribute which represents the user's last name. |
|
325 | The LDAP record attribute which represents the user's last name. | |
321 |
|
326 | |||
322 | .. _ldap_attr_email: |
|
327 | .. _ldap_attr_email: | |
323 |
|
328 | |||
324 | Email Attribute : required |
|
329 | Email Attribute : required | |
325 | The LDAP record attribute which represents the user's email address. |
|
330 | The LDAP record attribute which represents the user's email address. | |
326 |
|
331 | |||
327 | If all data are entered correctly, and python-ldap_ is properly installed |
|
332 | If all data are entered correctly, and python-ldap_ is properly installed | |
328 | users should be granted access to RhodeCode with ldap accounts. At this |
|
333 | users should be granted access to RhodeCode with ldap accounts. At this | |
329 | time user information is copied from LDAP into the RhodeCode user database. |
|
334 | time user information is copied from LDAP into the RhodeCode user database. | |
330 | This means that updates of an LDAP user object may not be reflected as a |
|
335 | This means that updates of an LDAP user object may not be reflected as a | |
331 | user update in RhodeCode. |
|
336 | user update in RhodeCode. | |
332 |
|
337 | |||
333 | If You have problems with LDAP access and believe You entered correct |
|
338 | If You have problems with LDAP access and believe You entered correct | |
334 | information check out the RhodeCode logs, any error messages sent from LDAP |
|
339 | information check out the RhodeCode logs, any error messages sent from LDAP | |
335 | will be saved there. |
|
340 | will be saved there. | |
336 |
|
341 | |||
337 | Active Directory |
|
342 | Active Directory | |
338 | '''''''''''''''' |
|
343 | '''''''''''''''' | |
339 |
|
344 | |||
340 | RhodeCode can use Microsoft Active Directory for user authentication. This |
|
345 | RhodeCode can use Microsoft Active Directory for user authentication. This | |
341 | is done through an LDAP or LDAPS connection to Active Directory. The |
|
346 | is done through an LDAP or LDAPS connection to Active Directory. The | |
342 | following LDAP configuration settings are typical for using Active |
|
347 | following LDAP configuration settings are typical for using Active | |
343 | Directory :: |
|
348 | Directory :: | |
344 |
|
349 | |||
345 | Base DN = OU=SBSUsers,OU=Users,OU=MyBusiness,DC=v3sys,DC=local |
|
350 | Base DN = OU=SBSUsers,OU=Users,OU=MyBusiness,DC=v3sys,DC=local | |
346 | Login Attribute = sAMAccountName |
|
351 | Login Attribute = sAMAccountName | |
347 | First Name Attribute = givenName |
|
352 | First Name Attribute = givenName | |
348 | Last Name Attribute = sn |
|
353 | Last Name Attribute = sn | |
349 | E-mail Attribute = mail |
|
354 | E-mail Attribute = mail | |
350 |
|
355 | |||
351 | All other LDAP settings will likely be site-specific and should be |
|
356 | All other LDAP settings will likely be site-specific and should be | |
352 | appropriately configured. |
|
357 | appropriately configured. | |
353 |
|
358 | |||
354 |
|
359 | |||
355 | Authentication by container or reverse-proxy |
|
360 | Authentication by container or reverse-proxy | |
356 | -------------------------------------------- |
|
361 | -------------------------------------------- | |
357 |
|
362 | |||
358 | Starting with version 1.3, RhodeCode supports delegating the authentication |
|
363 | Starting with version 1.3, RhodeCode supports delegating the authentication | |
359 | of users to its WSGI container, or to a reverse-proxy server through which all |
|
364 | of users to its WSGI container, or to a reverse-proxy server through which all | |
360 | clients access the application. |
|
365 | clients access the application. | |
361 |
|
366 | |||
362 | When these authentication methods are enabled in RhodeCode, it uses the |
|
367 | When these authentication methods are enabled in RhodeCode, it uses the | |
363 | username that the container/proxy (Apache/Nginx/etc) authenticated and doesn't |
|
368 | username that the container/proxy (Apache/Nginx/etc) authenticated and doesn't | |
364 | perform the authentication itself. The authorization, however, is still done by |
|
369 | perform the authentication itself. The authorization, however, is still done by | |
365 | RhodeCode according to its settings. |
|
370 | RhodeCode according to its settings. | |
366 |
|
371 | |||
367 | When a user logs in for the first time using these authentication methods, |
|
372 | When a user logs in for the first time using these authentication methods, | |
368 | a matching user account is created in RhodeCode with default permissions. An |
|
373 | a matching user account is created in RhodeCode with default permissions. An | |
369 | administrator can then modify it using RhodeCode's admin interface. |
|
374 | administrator can then modify it using RhodeCode's admin interface. | |
370 | It's also possible for an administrator to create accounts and configure their |
|
375 | It's also possible for an administrator to create accounts and configure their | |
371 | permissions before the user logs in for the first time. |
|
376 | permissions before the user logs in for the first time. | |
372 |
|
377 | |||
373 | Container-based authentication |
|
378 | Container-based authentication | |
374 | '''''''''''''''''''''''''''''' |
|
379 | '''''''''''''''''''''''''''''' | |
375 |
|
380 | |||
376 | In a container-based authentication setup, RhodeCode reads the user name from |
|
381 | In a container-based authentication setup, RhodeCode reads the user name from | |
377 | the ``REMOTE_USER`` server variable provided by the WSGI container. |
|
382 | the ``REMOTE_USER`` server variable provided by the WSGI container. | |
378 |
|
383 | |||
379 | After setting up your container (see `Apache's WSGI config`_), you'd need |
|
384 | After setting up your container (see `Apache's WSGI config`_), you'd need | |
380 | to configure it to require authentication on the location configured for |
|
385 | to configure it to require authentication on the location configured for | |
381 | RhodeCode. |
|
386 | RhodeCode. | |
382 |
|
387 | |||
383 | In order for RhodeCode to start using the provided username, you should set the |
|
388 | In order for RhodeCode to start using the provided username, you should set the | |
384 | following in the [app:main] section of your .ini file:: |
|
389 | following in the [app:main] section of your .ini file:: | |
385 |
|
390 | |||
386 | container_auth_enabled = true |
|
391 | container_auth_enabled = true | |
387 |
|
392 | |||
388 |
|
393 | |||
389 | Proxy pass-through authentication |
|
394 | Proxy pass-through authentication | |
390 | ''''''''''''''''''''''''''''''''' |
|
395 | ''''''''''''''''''''''''''''''''' | |
391 |
|
396 | |||
392 | In a proxy pass-through authentication setup, RhodeCode reads the user name |
|
397 | In a proxy pass-through authentication setup, RhodeCode reads the user name | |
393 | from the ``X-Forwarded-User`` request header, which should be configured to be |
|
398 | from the ``X-Forwarded-User`` request header, which should be configured to be | |
394 | sent by the reverse-proxy server. |
|
399 | sent by the reverse-proxy server. | |
395 |
|
400 | |||
396 | After setting up your proxy solution (see `Apache virtual host reverse proxy example`_, |
|
401 | After setting up your proxy solution (see `Apache virtual host reverse proxy example`_, | |
397 | `Apache as subdirectory`_ or `Nginx virtual host example`_), you'd need to |
|
402 | `Apache as subdirectory`_ or `Nginx virtual host example`_), you'd need to | |
398 | configure the authentication and add the username in a request header named |
|
403 | configure the authentication and add the username in a request header named | |
399 | ``X-Forwarded-User``. |
|
404 | ``X-Forwarded-User``. | |
400 |
|
405 | |||
401 | For example, the following config section for Apache sets a subdirectory in a |
|
406 | For example, the following config section for Apache sets a subdirectory in a | |
402 | reverse-proxy setup with basic auth:: |
|
407 | reverse-proxy setup with basic auth:: | |
403 |
|
408 | |||
404 | <Location /<someprefix> > |
|
409 | <Location /<someprefix> > | |
405 | ProxyPass http://127.0.0.1:5000/<someprefix> |
|
410 | ProxyPass http://127.0.0.1:5000/<someprefix> | |
406 | ProxyPassReverse http://127.0.0.1:5000/<someprefix> |
|
411 | ProxyPassReverse http://127.0.0.1:5000/<someprefix> | |
407 | SetEnvIf X-Url-Scheme https HTTPS=1 |
|
412 | SetEnvIf X-Url-Scheme https HTTPS=1 | |
408 |
|
413 | |||
409 | AuthType Basic |
|
414 | AuthType Basic | |
410 | AuthName "RhodeCode authentication" |
|
415 | AuthName "RhodeCode authentication" | |
411 | AuthUserFile /home/web/rhodecode/.htpasswd |
|
416 | AuthUserFile /home/web/rhodecode/.htpasswd | |
412 | require valid-user |
|
417 | require valid-user | |
413 |
|
418 | |||
414 | RequestHeader unset X-Forwarded-User |
|
419 | RequestHeader unset X-Forwarded-User | |
415 |
|
420 | |||
416 | RewriteEngine On |
|
421 | RewriteEngine On | |
417 | RewriteCond %{LA-U:REMOTE_USER} (.+) |
|
422 | RewriteCond %{LA-U:REMOTE_USER} (.+) | |
418 | RewriteRule .* - [E=RU:%1] |
|
423 | RewriteRule .* - [E=RU:%1] | |
419 | RequestHeader set X-Forwarded-User %{RU}e |
|
424 | RequestHeader set X-Forwarded-User %{RU}e | |
420 | </Location> |
|
425 | </Location> | |
421 |
|
426 | |||
422 | In order for RhodeCode to start using the forwarded username, you should set |
|
427 | In order for RhodeCode to start using the forwarded username, you should set | |
423 | the following in the [app:main] section of your .ini file:: |
|
428 | the following in the [app:main] section of your .ini file:: | |
424 |
|
429 | |||
425 | proxypass_auth_enabled = true |
|
430 | proxypass_auth_enabled = true | |
426 |
|
431 | |||
427 | .. note:: |
|
432 | .. note:: | |
428 | If you enable proxy pass-through authentication, make sure your server is |
|
433 | If you enable proxy pass-through authentication, make sure your server is | |
429 | only accessible through the proxy. Otherwise, any client would be able to |
|
434 | only accessible through the proxy. Otherwise, any client would be able to | |
430 | forge the authentication header and could effectively become authenticated |
|
435 | forge the authentication header and could effectively become authenticated | |
431 | using any account of their liking. |
|
436 | using any account of their liking. | |
432 |
|
437 | |||
433 | Integration with Issue trackers |
|
438 | Integration with Issue trackers | |
434 | ------------------------------- |
|
439 | ------------------------------- | |
435 |
|
440 | |||
436 | RhodeCode provides a simple integration with issue trackers. It's possible |
|
441 | RhodeCode provides a simple integration with issue trackers. It's possible | |
437 | to define a regular expression that will fetch issue id stored in commit |
|
442 | to define a regular expression that will fetch issue id stored in commit | |
438 | messages and replace that with an url to this issue. To enable this simply |
|
443 | messages and replace that with an url to this issue. To enable this simply | |
439 | uncomment following variables in the ini file:: |
|
444 | uncomment following variables in the ini file:: | |
440 |
|
445 | |||
441 | url_pat = (?:^#|\s#)(\w+) |
|
446 | url_pat = (?:^#|\s#)(\w+) | |
442 | issue_server_link = https://myissueserver.com/{repo}/issue/{id} |
|
447 | issue_server_link = https://myissueserver.com/{repo}/issue/{id} | |
443 | issue_prefix = # |
|
448 | issue_prefix = # | |
444 |
|
449 | |||
445 | `url_pat` is the regular expression that will fetch issues from commit messages. |
|
450 | `url_pat` is the regular expression that will fetch issues from commit messages. | |
446 | Default regex will match issues in format of #<number> eg. #300. |
|
451 | Default regex will match issues in format of #<number> eg. #300. | |
447 |
|
452 | |||
448 | Matched issues will be replace with the link specified as `issue_server_link` |
|
453 | Matched issues will be replace with the link specified as `issue_server_link` | |
449 | {id} will be replaced with issue id, and {repo} with repository name. |
|
454 | {id} will be replaced with issue id, and {repo} with repository name. | |
450 | Since the # is striped `issue_prefix` is added as a prefix to url. |
|
455 | Since the # is striped `issue_prefix` is added as a prefix to url. | |
451 | `issue_prefix` can be something different than # if you pass |
|
456 | `issue_prefix` can be something different than # if you pass | |
452 | ISSUE- as issue prefix this will generate an url in format:: |
|
457 | ISSUE- as issue prefix this will generate an url in format:: | |
453 |
|
458 | |||
454 | <a href="https://myissueserver.com/example_repo/issue/300">ISSUE-300</a> |
|
459 | <a href="https://myissueserver.com/example_repo/issue/300">ISSUE-300</a> | |
455 |
|
460 | |||
456 | Hook management |
|
461 | Hook management | |
457 | --------------- |
|
462 | --------------- | |
458 |
|
463 | |||
459 | Hooks can be managed in similar way to this used in .hgrc files. |
|
464 | Hooks can be managed in similar way to this used in .hgrc files. | |
460 | To access hooks setting click `advanced setup` on Hooks section of Mercurial |
|
465 | To access hooks setting click `advanced setup` on Hooks section of Mercurial | |
461 | Settings in Admin. |
|
466 | Settings in Admin. | |
462 |
|
467 | |||
463 | There are 4 built in hooks that cannot be changed (only enable/disable by |
|
468 | There are 4 built in hooks that cannot be changed (only enable/disable by | |
464 | checkboxes on previos section). |
|
469 | checkboxes on previos section). | |
465 | To add another custom hook simply fill in first section with |
|
470 | To add another custom hook simply fill in first section with | |
466 | <name>.<hook_type> and the second one with hook path. Example hooks |
|
471 | <name>.<hook_type> and the second one with hook path. Example hooks | |
467 | can be found at *rhodecode.lib.hooks*. |
|
472 | can be found at *rhodecode.lib.hooks*. | |
468 |
|
473 | |||
469 |
|
474 | |||
470 | Changing default encoding |
|
475 | Changing default encoding | |
471 | ------------------------- |
|
476 | ------------------------- | |
472 |
|
477 | |||
473 | By default RhodeCode uses utf8 encoding, starting from 1.3 series this |
|
478 | By default RhodeCode uses utf8 encoding, starting from 1.3 series this | |
474 | can be changed, simply edit default_encoding in .ini file to desired one. |
|
479 | can be changed, simply edit default_encoding in .ini file to desired one. | |
475 | This affects many parts in rhodecode including commiters names, filenames, |
|
480 | This affects many parts in rhodecode including commiters names, filenames, | |
476 | encoding of commit messages. In addition RhodeCode can detect if `chardet` |
|
481 | encoding of commit messages. In addition RhodeCode can detect if `chardet` | |
477 | library is installed. If `chardet` is detected RhodeCode will fallback to it |
|
482 | library is installed. If `chardet` is detected RhodeCode will fallback to it | |
478 | when there are encode/decode errors. |
|
483 | when there are encode/decode errors. | |
479 |
|
484 | |||
480 |
|
485 | |||
481 | Setting Up Celery |
|
486 | Setting Up Celery | |
482 | ----------------- |
|
487 | ----------------- | |
483 |
|
488 | |||
484 | Since version 1.1 celery is configured by the rhodecode ini configuration files. |
|
489 | Since version 1.1 celery is configured by the rhodecode ini configuration files. | |
485 | Simply set use_celery=true in the ini file then add / change the configuration |
|
490 | Simply set use_celery=true in the ini file then add / change the configuration | |
486 | variables inside the ini file. |
|
491 | variables inside the ini file. | |
487 |
|
492 | |||
488 | Remember that the ini files use the format with '.' not with '_' like celery. |
|
493 | Remember that the ini files use the format with '.' not with '_' like celery. | |
489 | So for example setting `BROKER_HOST` in celery means setting `broker.host` in |
|
494 | So for example setting `BROKER_HOST` in celery means setting `broker.host` in | |
490 | the config file. |
|
495 | the config file. | |
491 |
|
496 | |||
492 | In order to start using celery run:: |
|
497 | In order to start using celery run:: | |
493 |
|
498 | |||
494 | paster celeryd <configfile.ini> |
|
499 | paster celeryd <configfile.ini> | |
495 |
|
500 | |||
496 |
|
501 | |||
497 | .. note:: |
|
502 | .. note:: | |
498 | Make sure you run this command from the same virtualenv, and with the same |
|
503 | Make sure you run this command from the same virtualenv, and with the same | |
499 | user that rhodecode runs. |
|
504 | user that rhodecode runs. | |
500 |
|
505 | |||
501 | HTTPS support |
|
506 | HTTPS support | |
502 | ------------- |
|
507 | ------------- | |
503 |
|
508 | |||
504 | There are two ways to enable https: |
|
509 | There are two ways to enable https: | |
505 |
|
510 | |||
506 | - Set HTTP_X_URL_SCHEME in your http server headers, than rhodecode will |
|
511 | - Set HTTP_X_URL_SCHEME in your http server headers, than rhodecode will | |
507 | recognize this headers and make proper https redirections |
|
512 | recognize this headers and make proper https redirections | |
508 | - Alternatively, change the `force_https = true` flag in the ini configuration |
|
513 | - Alternatively, change the `force_https = true` flag in the ini configuration | |
509 | to force using https, no headers are needed than to enable https |
|
514 | to force using https, no headers are needed than to enable https | |
510 |
|
515 | |||
511 |
|
516 | |||
512 | Nginx virtual host example |
|
517 | Nginx virtual host example | |
513 | -------------------------- |
|
518 | -------------------------- | |
514 |
|
519 | |||
515 | Sample config for nginx using proxy:: |
|
520 | Sample config for nginx using proxy:: | |
516 |
|
521 | |||
517 | upstream rc { |
|
522 | upstream rc { | |
518 | server 127.0.0.1:5000; |
|
523 | server 127.0.0.1:5000; | |
519 | # add more instances for load balancing |
|
524 | # add more instances for load balancing | |
520 | #server 127.0.0.1:5001; |
|
525 | #server 127.0.0.1:5001; | |
521 | #server 127.0.0.1:5002; |
|
526 | #server 127.0.0.1:5002; | |
522 | } |
|
527 | } | |
523 |
|
528 | |||
524 | server { |
|
529 | server { | |
525 | listen 80; |
|
530 | listen 80; | |
526 | server_name hg.myserver.com; |
|
531 | server_name hg.myserver.com; | |
527 | access_log /var/log/nginx/rhodecode.access.log; |
|
532 | access_log /var/log/nginx/rhodecode.access.log; | |
528 | error_log /var/log/nginx/rhodecode.error.log; |
|
533 | error_log /var/log/nginx/rhodecode.error.log; | |
529 |
|
534 | |||
530 | location / { |
|
535 | location / { | |
531 | try_files $uri @rhode; |
|
536 | try_files $uri @rhode; | |
532 | } |
|
537 | } | |
533 |
|
538 | |||
534 | location @rhode { |
|
539 | location @rhode { | |
535 | proxy_pass http://rc; |
|
540 | proxy_pass http://rc; | |
536 | include /etc/nginx/proxy.conf; |
|
541 | include /etc/nginx/proxy.conf; | |
537 | } |
|
542 | } | |
538 |
|
543 | |||
539 | } |
|
544 | } | |
540 |
|
545 | |||
541 | Here's the proxy.conf. It's tuned so it will not timeout on long |
|
546 | Here's the proxy.conf. It's tuned so it will not timeout on long | |
542 | pushes or large pushes:: |
|
547 | pushes or large pushes:: | |
543 |
|
548 | |||
544 | proxy_redirect off; |
|
549 | proxy_redirect off; | |
545 | proxy_set_header Host $host; |
|
550 | proxy_set_header Host $host; | |
546 | proxy_set_header X-Url-Scheme $scheme; |
|
551 | proxy_set_header X-Url-Scheme $scheme; | |
547 | proxy_set_header X-Host $http_host; |
|
552 | proxy_set_header X-Host $http_host; | |
548 | proxy_set_header X-Real-IP $remote_addr; |
|
553 | proxy_set_header X-Real-IP $remote_addr; | |
549 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
554 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
550 | proxy_set_header Proxy-host $proxy_host; |
|
555 | proxy_set_header Proxy-host $proxy_host; | |
551 | client_max_body_size 400m; |
|
556 | client_max_body_size 400m; | |
552 | client_body_buffer_size 128k; |
|
557 | client_body_buffer_size 128k; | |
553 | proxy_buffering off; |
|
558 | proxy_buffering off; | |
554 | proxy_connect_timeout 7200; |
|
559 | proxy_connect_timeout 7200; | |
555 | proxy_send_timeout 7200; |
|
560 | proxy_send_timeout 7200; | |
556 | proxy_read_timeout 7200; |
|
561 | proxy_read_timeout 7200; | |
557 | proxy_buffers 8 32k; |
|
562 | proxy_buffers 8 32k; | |
558 |
|
563 | |||
559 | Also, when using root path with nginx you might set the static files to false |
|
564 | Also, when using root path with nginx you might set the static files to false | |
560 | in the production.ini file:: |
|
565 | in the production.ini file:: | |
561 |
|
566 | |||
562 | [app:main] |
|
567 | [app:main] | |
563 | use = egg:rhodecode |
|
568 | use = egg:rhodecode | |
564 | full_stack = true |
|
569 | full_stack = true | |
565 | static_files = false |
|
570 | static_files = false | |
566 | lang=en |
|
571 | lang=en | |
567 | cache_dir = %(here)s/data |
|
572 | cache_dir = %(here)s/data | |
568 |
|
573 | |||
569 | In order to not have the statics served by the application. This improves speed. |
|
574 | In order to not have the statics served by the application. This improves speed. | |
570 |
|
575 | |||
571 |
|
576 | |||
572 | Apache virtual host reverse proxy example |
|
577 | Apache virtual host reverse proxy example | |
573 | ----------------------------------------- |
|
578 | ----------------------------------------- | |
574 |
|
579 | |||
575 | Here is a sample configuration file for apache using proxy:: |
|
580 | Here is a sample configuration file for apache using proxy:: | |
576 |
|
581 | |||
577 | <VirtualHost *:80> |
|
582 | <VirtualHost *:80> | |
578 | ServerName hg.myserver.com |
|
583 | ServerName hg.myserver.com | |
579 | ServerAlias hg.myserver.com |
|
584 | ServerAlias hg.myserver.com | |
580 |
|
585 | |||
581 | <Proxy *> |
|
586 | <Proxy *> | |
582 | Order allow,deny |
|
587 | Order allow,deny | |
583 | Allow from all |
|
588 | Allow from all | |
584 | </Proxy> |
|
589 | </Proxy> | |
585 |
|
590 | |||
586 | #important ! |
|
591 | #important ! | |
587 | #Directive to properly generate url (clone url) for pylons |
|
592 | #Directive to properly generate url (clone url) for pylons | |
588 | ProxyPreserveHost On |
|
593 | ProxyPreserveHost On | |
589 |
|
594 | |||
590 | #rhodecode instance |
|
595 | #rhodecode instance | |
591 | ProxyPass / http://127.0.0.1:5000/ |
|
596 | ProxyPass / http://127.0.0.1:5000/ | |
592 | ProxyPassReverse / http://127.0.0.1:5000/ |
|
597 | ProxyPassReverse / http://127.0.0.1:5000/ | |
593 |
|
598 | |||
594 | #to enable https use line below |
|
599 | #to enable https use line below | |
595 | #SetEnvIf X-Url-Scheme https HTTPS=1 |
|
600 | #SetEnvIf X-Url-Scheme https HTTPS=1 | |
596 |
|
601 | |||
597 | </VirtualHost> |
|
602 | </VirtualHost> | |
598 |
|
603 | |||
599 |
|
604 | |||
600 | Additional tutorial |
|
605 | Additional tutorial | |
601 | http://wiki.pylonshq.com/display/pylonscookbook/Apache+as+a+reverse+proxy+for+Pylons |
|
606 | http://wiki.pylonshq.com/display/pylonscookbook/Apache+as+a+reverse+proxy+for+Pylons | |
602 |
|
607 | |||
603 |
|
608 | |||
604 | Apache as subdirectory |
|
609 | Apache as subdirectory | |
605 | ---------------------- |
|
610 | ---------------------- | |
606 |
|
611 | |||
607 | Apache subdirectory part:: |
|
612 | Apache subdirectory part:: | |
608 |
|
613 | |||
609 | <Location /<someprefix> > |
|
614 | <Location /<someprefix> > | |
610 | ProxyPass http://127.0.0.1:5000/<someprefix> |
|
615 | ProxyPass http://127.0.0.1:5000/<someprefix> | |
611 | ProxyPassReverse http://127.0.0.1:5000/<someprefix> |
|
616 | ProxyPassReverse http://127.0.0.1:5000/<someprefix> | |
612 | SetEnvIf X-Url-Scheme https HTTPS=1 |
|
617 | SetEnvIf X-Url-Scheme https HTTPS=1 | |
613 | </Location> |
|
618 | </Location> | |
614 |
|
619 | |||
615 | Besides the regular apache setup you will need to add the following line |
|
620 | Besides the regular apache setup you will need to add the following line | |
616 | into [app:main] section of your .ini file:: |
|
621 | into [app:main] section of your .ini file:: | |
617 |
|
622 | |||
618 | filter-with = proxy-prefix |
|
623 | filter-with = proxy-prefix | |
619 |
|
624 | |||
620 | Add the following at the end of the .ini file:: |
|
625 | Add the following at the end of the .ini file:: | |
621 |
|
626 | |||
622 | [filter:proxy-prefix] |
|
627 | [filter:proxy-prefix] | |
623 | use = egg:PasteDeploy#prefix |
|
628 | use = egg:PasteDeploy#prefix | |
624 | prefix = /<someprefix> |
|
629 | prefix = /<someprefix> | |
625 |
|
630 | |||
626 |
|
631 | |||
627 | then change <someprefix> into your choosen prefix |
|
632 | then change <someprefix> into your choosen prefix | |
628 |
|
633 | |||
629 | Apache's WSGI config |
|
634 | Apache's WSGI config | |
630 | -------------------- |
|
635 | -------------------- | |
631 |
|
636 | |||
632 | Alternatively, RhodeCode can be set up with Apache under mod_wsgi. For |
|
637 | Alternatively, RhodeCode can be set up with Apache under mod_wsgi. For | |
633 | that, you'll need to: |
|
638 | that, you'll need to: | |
634 |
|
639 | |||
635 | - Install mod_wsgi. If using a Debian-based distro, you can install |
|
640 | - Install mod_wsgi. If using a Debian-based distro, you can install | |
636 | the package libapache2-mod-wsgi:: |
|
641 | the package libapache2-mod-wsgi:: | |
637 |
|
642 | |||
638 | aptitude install libapache2-mod-wsgi |
|
643 | aptitude install libapache2-mod-wsgi | |
639 |
|
644 | |||
640 | - Enable mod_wsgi:: |
|
645 | - Enable mod_wsgi:: | |
641 |
|
646 | |||
642 | a2enmod wsgi |
|
647 | a2enmod wsgi | |
643 |
|
648 | |||
644 | - Create a wsgi dispatch script, like the one below. Make sure you |
|
649 | - Create a wsgi dispatch script, like the one below. Make sure you | |
645 | check the paths correctly point to where you installed RhodeCode |
|
650 | check the paths correctly point to where you installed RhodeCode | |
646 | and its Python Virtual Environment. |
|
651 | and its Python Virtual Environment. | |
647 | - Enable the WSGIScriptAlias directive for the wsgi dispatch script, |
|
652 | - Enable the WSGIScriptAlias directive for the wsgi dispatch script, | |
648 | as in the following example. Once again, check the paths are |
|
653 | as in the following example. Once again, check the paths are | |
649 | correctly specified. |
|
654 | correctly specified. | |
650 |
|
655 | |||
651 | Here is a sample excerpt from an Apache Virtual Host configuration file:: |
|
656 | Here is a sample excerpt from an Apache Virtual Host configuration file:: | |
652 |
|
657 | |||
653 | WSGIDaemonProcess pylons user=www-data group=www-data processes=1 \ |
|
658 | WSGIDaemonProcess pylons user=www-data group=www-data processes=1 \ | |
654 | threads=4 \ |
|
659 | threads=4 \ | |
655 | python-path=/home/web/rhodecode/pyenv/lib/python2.6/site-packages |
|
660 | python-path=/home/web/rhodecode/pyenv/lib/python2.6/site-packages | |
656 | WSGIScriptAlias / /home/web/rhodecode/dispatch.wsgi |
|
661 | WSGIScriptAlias / /home/web/rhodecode/dispatch.wsgi | |
657 | WSGIPassAuthorization On |
|
662 | WSGIPassAuthorization On | |
658 |
|
663 | |||
659 | Example wsgi dispatch script:: |
|
664 | Example wsgi dispatch script:: | |
660 |
|
665 | |||
661 | import os |
|
666 | import os | |
662 | os.environ["HGENCODING"] = "UTF-8" |
|
667 | os.environ["HGENCODING"] = "UTF-8" | |
663 | os.environ['PYTHON_EGG_CACHE'] = '/home/web/rhodecode/.egg-cache' |
|
668 | os.environ['PYTHON_EGG_CACHE'] = '/home/web/rhodecode/.egg-cache' | |
664 |
|
669 | |||
665 | # sometimes it's needed to set the curent dir |
|
670 | # sometimes it's needed to set the curent dir | |
666 | os.chdir('/home/web/rhodecode/') |
|
671 | os.chdir('/home/web/rhodecode/') | |
667 |
|
672 | |||
668 | import site |
|
673 | import site | |
669 | site.addsitedir("/home/web/rhodecode/pyenv/lib/python2.6/site-packages") |
|
674 | site.addsitedir("/home/web/rhodecode/pyenv/lib/python2.6/site-packages") | |
670 |
|
675 | |||
671 | from paste.deploy import loadapp |
|
676 | from paste.deploy import loadapp | |
672 | from paste.script.util.logging_config import fileConfig |
|
677 | from paste.script.util.logging_config import fileConfig | |
673 |
|
678 | |||
674 | fileConfig('/home/web/rhodecode/production.ini') |
|
679 | fileConfig('/home/web/rhodecode/production.ini') | |
675 | application = loadapp('config:/home/web/rhodecode/production.ini') |
|
680 | application = loadapp('config:/home/web/rhodecode/production.ini') | |
676 |
|
681 | |||
677 | Note: when using mod_wsgi you'll need to install the same version of |
|
682 | Note: when using mod_wsgi you'll need to install the same version of | |
678 | Mercurial that's inside RhodeCode's virtualenv also on the system's Python |
|
683 | Mercurial that's inside RhodeCode's virtualenv also on the system's Python | |
679 | environment. |
|
684 | environment. | |
680 |
|
685 | |||
681 |
|
686 | |||
682 | Other configuration files |
|
687 | Other configuration files | |
683 | ------------------------- |
|
688 | ------------------------- | |
684 |
|
689 | |||
685 | Some example init.d scripts can be found here, for debian and gentoo: |
|
690 | Some example init.d scripts can be found here, for debian and gentoo: | |
686 |
|
691 | |||
687 | https://rhodecode.org/rhodecode/files/tip/init.d |
|
692 | https://rhodecode.org/rhodecode/files/tip/init.d | |
688 |
|
693 | |||
689 |
|
694 | |||
690 | Troubleshooting |
|
695 | Troubleshooting | |
691 | --------------- |
|
696 | --------------- | |
692 |
|
697 | |||
693 | :Q: **Missing static files?** |
|
698 | :Q: **Missing static files?** | |
694 | :A: Make sure either to set the `static_files = true` in the .ini file or |
|
699 | :A: Make sure either to set the `static_files = true` in the .ini file or | |
695 | double check the root path for your http setup. It should point to |
|
700 | double check the root path for your http setup. It should point to | |
696 | for example: |
|
701 | for example: | |
697 | /home/my-virtual-python/lib/python2.6/site-packages/rhodecode/public |
|
702 | /home/my-virtual-python/lib/python2.6/site-packages/rhodecode/public | |
698 |
|
703 | |||
699 | | |
|
704 | | | |
700 |
|
705 | |||
701 | :Q: **Can't install celery/rabbitmq** |
|
706 | :Q: **Can't install celery/rabbitmq** | |
702 | :A: Don't worry RhodeCode works without them too. No extra setup is required. |
|
707 | :A: Don't worry RhodeCode works without them too. No extra setup is required. | |
703 |
|
708 | |||
704 | | |
|
709 | | | |
705 |
|
710 | |||
706 | :Q: **Long lasting push timeouts?** |
|
711 | :Q: **Long lasting push timeouts?** | |
707 | :A: Make sure you set a longer timeouts in your proxy/fcgi settings, timeouts |
|
712 | :A: Make sure you set a longer timeouts in your proxy/fcgi settings, timeouts | |
708 | are caused by https server and not RhodeCode. |
|
713 | are caused by https server and not RhodeCode. | |
709 |
|
714 | |||
710 | | |
|
715 | | | |
711 |
|
716 | |||
712 | :Q: **Large pushes timeouts?** |
|
717 | :Q: **Large pushes timeouts?** | |
713 | :A: Make sure you set a proper max_body_size for the http server. |
|
718 | :A: Make sure you set a proper max_body_size for the http server. | |
714 |
|
719 | |||
715 | | |
|
720 | | | |
716 |
|
721 | |||
717 | :Q: **Apache doesn't pass basicAuth on pull/push?** |
|
722 | :Q: **Apache doesn't pass basicAuth on pull/push?** | |
718 | :A: Make sure you added `WSGIPassAuthorization true`. |
|
723 | :A: Make sure you added `WSGIPassAuthorization true`. | |
719 |
|
724 | |||
720 | For further questions search the `Issues tracker`_, or post a message in the |
|
725 | For further questions search the `Issues tracker`_, or post a message in the | |
721 | `google group rhodecode`_ |
|
726 | `google group rhodecode`_ | |
722 |
|
727 | |||
723 | .. _virtualenv: http://pypi.python.org/pypi/virtualenv |
|
728 | .. _virtualenv: http://pypi.python.org/pypi/virtualenv | |
724 | .. _python: http://www.python.org/ |
|
729 | .. _python: http://www.python.org/ | |
725 | .. _mercurial: http://mercurial.selenic.com/ |
|
730 | .. _mercurial: http://mercurial.selenic.com/ | |
726 | .. _celery: http://celeryproject.org/ |
|
731 | .. _celery: http://celeryproject.org/ | |
727 | .. _rabbitmq: http://www.rabbitmq.com/ |
|
732 | .. _rabbitmq: http://www.rabbitmq.com/ | |
728 | .. _python-ldap: http://www.python-ldap.org/ |
|
733 | .. _python-ldap: http://www.python-ldap.org/ | |
729 | .. _mercurial-server: http://www.lshift.net/mercurial-server.html |
|
734 | .. _mercurial-server: http://www.lshift.net/mercurial-server.html | |
730 | .. _PublishingRepositories: http://mercurial.selenic.com/wiki/PublishingRepositories |
|
735 | .. _PublishingRepositories: http://mercurial.selenic.com/wiki/PublishingRepositories | |
731 | .. _Issues tracker: https://bitbucket.org/marcinkuzminski/rhodecode/issues |
|
736 | .. _Issues tracker: https://bitbucket.org/marcinkuzminski/rhodecode/issues | |
732 | .. _google group rhodecode: http://groups.google.com/group/rhodecode |
|
737 | .. _google group rhodecode: http://groups.google.com/group/rhodecode |
@@ -1,609 +1,614 | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | rhodecode.lib.diffs |
|
3 | rhodecode.lib.diffs | |
4 | ~~~~~~~~~~~~~~~~~~~ |
|
4 | ~~~~~~~~~~~~~~~~~~~ | |
5 |
|
5 | |||
6 | Set of diffing helpers, previously part of vcs |
|
6 | Set of diffing helpers, previously part of vcs | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | :created_on: Dec 4, 2011 |
|
9 | :created_on: Dec 4, 2011 | |
10 | :author: marcink |
|
10 | :author: marcink | |
11 | :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
|
11 | :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> | |
12 | :original copyright: 2007-2008 by Armin Ronacher |
|
12 | :original copyright: 2007-2008 by Armin Ronacher | |
13 | :license: GPLv3, see COPYING for more details. |
|
13 | :license: GPLv3, see COPYING for more details. | |
14 | """ |
|
14 | """ | |
15 | # This program is free software: you can redistribute it and/or modify |
|
15 | # This program is free software: you can redistribute it and/or modify | |
16 | # it under the terms of the GNU General Public License as published by |
|
16 | # it under the terms of the GNU General Public License as published by | |
17 | # the Free Software Foundation, either version 3 of the License, or |
|
17 | # the Free Software Foundation, either version 3 of the License, or | |
18 | # (at your option) any later version. |
|
18 | # (at your option) any later version. | |
19 | # |
|
19 | # | |
20 | # This program is distributed in the hope that it will be useful, |
|
20 | # This program is distributed in the hope that it will be useful, | |
21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | # GNU General Public License for more details. |
|
23 | # GNU General Public License for more details. | |
24 | # |
|
24 | # | |
25 | # You should have received a copy of the GNU General Public License |
|
25 | # You should have received a copy of the GNU General Public License | |
26 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
26 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 |
|
27 | |||
28 | import re |
|
28 | import re | |
29 | import io |
|
29 | import io | |
30 | import difflib |
|
30 | import difflib | |
31 | import markupsafe |
|
31 | import markupsafe | |
32 |
|
32 | |||
33 | from itertools import tee, imap |
|
33 | from itertools import tee, imap | |
34 |
|
34 | |||
35 | from mercurial import patch |
|
35 | from mercurial import patch | |
36 | from mercurial.mdiff import diffopts |
|
36 | from mercurial.mdiff import diffopts | |
37 | from mercurial.bundlerepo import bundlerepository |
|
37 | from mercurial.bundlerepo import bundlerepository | |
38 | from mercurial import localrepo |
|
38 | from mercurial import localrepo | |
39 |
|
39 | |||
40 | from pylons.i18n.translation import _ |
|
40 | from pylons.i18n.translation import _ | |
41 |
|
41 | |||
42 | from rhodecode.lib.vcs.exceptions import VCSError |
|
42 | from rhodecode.lib.vcs.exceptions import VCSError | |
43 | from rhodecode.lib.vcs.nodes import FileNode, SubModuleNode |
|
43 | from rhodecode.lib.vcs.nodes import FileNode, SubModuleNode | |
44 | from rhodecode.lib.helpers import escape |
|
44 | from rhodecode.lib.helpers import escape | |
45 | from rhodecode.lib.utils import EmptyChangeset, make_ui |
|
45 | from rhodecode.lib.utils import EmptyChangeset, make_ui | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | def wrap_to_table(str_): |
|
48 | def wrap_to_table(str_): | |
49 | return '''<table class="code-difftable"> |
|
49 | return '''<table class="code-difftable"> | |
50 | <tr class="line no-comment"> |
|
50 | <tr class="line no-comment"> | |
51 | <td class="lineno new"></td> |
|
51 | <td class="lineno new"></td> | |
52 | <td class="code no-comment"><pre>%s</pre></td> |
|
52 | <td class="code no-comment"><pre>%s</pre></td> | |
53 | </tr> |
|
53 | </tr> | |
54 | </table>''' % str_ |
|
54 | </table>''' % str_ | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | def wrapped_diff(filenode_old, filenode_new, cut_off_limit=None, |
|
57 | def wrapped_diff(filenode_old, filenode_new, cut_off_limit=None, | |
58 | ignore_whitespace=True, line_context=3, |
|
58 | ignore_whitespace=True, line_context=3, | |
59 | enable_comments=False): |
|
59 | enable_comments=False): | |
60 | """ |
|
60 | """ | |
61 | returns a wrapped diff into a table, checks for cut_off_limit and presents |
|
61 | returns a wrapped diff into a table, checks for cut_off_limit and presents | |
62 | proper message |
|
62 | proper message | |
63 | """ |
|
63 | """ | |
64 |
|
64 | |||
65 | if filenode_old is None: |
|
65 | if filenode_old is None: | |
66 | filenode_old = FileNode(filenode_new.path, '', EmptyChangeset()) |
|
66 | filenode_old = FileNode(filenode_new.path, '', EmptyChangeset()) | |
67 |
|
67 | |||
68 | if filenode_old.is_binary or filenode_new.is_binary: |
|
68 | if filenode_old.is_binary or filenode_new.is_binary: | |
69 | diff = wrap_to_table(_('binary file')) |
|
69 | diff = wrap_to_table(_('binary file')) | |
70 | stats = (0, 0) |
|
70 | stats = (0, 0) | |
71 | size = 0 |
|
71 | size = 0 | |
72 |
|
72 | |||
73 | elif cut_off_limit != -1 and (cut_off_limit is None or |
|
73 | elif cut_off_limit != -1 and (cut_off_limit is None or | |
74 | (filenode_old.size < cut_off_limit and filenode_new.size < cut_off_limit)): |
|
74 | (filenode_old.size < cut_off_limit and filenode_new.size < cut_off_limit)): | |
75 |
|
75 | |||
76 | f_gitdiff = get_gitdiff(filenode_old, filenode_new, |
|
76 | f_gitdiff = get_gitdiff(filenode_old, filenode_new, | |
77 | ignore_whitespace=ignore_whitespace, |
|
77 | ignore_whitespace=ignore_whitespace, | |
78 | context=line_context) |
|
78 | context=line_context) | |
79 | diff_processor = DiffProcessor(f_gitdiff, format='gitdiff') |
|
79 | diff_processor = DiffProcessor(f_gitdiff, format='gitdiff') | |
80 |
|
80 | |||
81 | diff = diff_processor.as_html(enable_comments=enable_comments) |
|
81 | diff = diff_processor.as_html(enable_comments=enable_comments) | |
82 | stats = diff_processor.stat() |
|
82 | stats = diff_processor.stat() | |
83 | size = len(diff or '') |
|
83 | size = len(diff or '') | |
84 | else: |
|
84 | else: | |
85 | diff = wrap_to_table(_('Changeset was too big and was cut off, use ' |
|
85 | diff = wrap_to_table(_('Changeset was too big and was cut off, use ' | |
86 | 'diff menu to display this diff')) |
|
86 | 'diff menu to display this diff')) | |
87 | stats = (0, 0) |
|
87 | stats = (0, 0) | |
88 | size = 0 |
|
88 | size = 0 | |
89 | if not diff: |
|
89 | if not diff: | |
90 | submodules = filter(lambda o: isinstance(o, SubModuleNode), |
|
90 | submodules = filter(lambda o: isinstance(o, SubModuleNode), | |
91 | [filenode_new, filenode_old]) |
|
91 | [filenode_new, filenode_old]) | |
92 | if submodules: |
|
92 | if submodules: | |
93 | diff = wrap_to_table(escape('Submodule %r' % submodules[0])) |
|
93 | diff = wrap_to_table(escape('Submodule %r' % submodules[0])) | |
94 | else: |
|
94 | else: | |
95 | diff = wrap_to_table(_('No changes detected')) |
|
95 | diff = wrap_to_table(_('No changes detected')) | |
96 |
|
96 | |||
97 | cs1 = filenode_old.changeset.raw_id |
|
97 | cs1 = filenode_old.changeset.raw_id | |
98 | cs2 = filenode_new.changeset.raw_id |
|
98 | cs2 = filenode_new.changeset.raw_id | |
99 |
|
99 | |||
100 | return size, cs1, cs2, diff, stats |
|
100 | return size, cs1, cs2, diff, stats | |
101 |
|
101 | |||
102 |
|
102 | |||
103 | def get_gitdiff(filenode_old, filenode_new, ignore_whitespace=True, context=3): |
|
103 | def get_gitdiff(filenode_old, filenode_new, ignore_whitespace=True, context=3): | |
104 | """ |
|
104 | """ | |
105 | Returns git style diff between given ``filenode_old`` and ``filenode_new``. |
|
105 | Returns git style diff between given ``filenode_old`` and ``filenode_new``. | |
106 |
|
106 | |||
107 | :param ignore_whitespace: ignore whitespaces in diff |
|
107 | :param ignore_whitespace: ignore whitespaces in diff | |
108 | """ |
|
108 | """ | |
109 | # make sure we pass in default context |
|
109 | # make sure we pass in default context | |
110 | context = context or 3 |
|
110 | context = context or 3 | |
111 | submodules = filter(lambda o: isinstance(o, SubModuleNode), |
|
111 | submodules = filter(lambda o: isinstance(o, SubModuleNode), | |
112 | [filenode_new, filenode_old]) |
|
112 | [filenode_new, filenode_old]) | |
113 | if submodules: |
|
113 | if submodules: | |
114 | return '' |
|
114 | return '' | |
115 |
|
115 | |||
116 | for filenode in (filenode_old, filenode_new): |
|
116 | for filenode in (filenode_old, filenode_new): | |
117 | if not isinstance(filenode, FileNode): |
|
117 | if not isinstance(filenode, FileNode): | |
118 | raise VCSError("Given object should be FileNode object, not %s" |
|
118 | raise VCSError("Given object should be FileNode object, not %s" | |
119 | % filenode.__class__) |
|
119 | % filenode.__class__) | |
120 |
|
120 | |||
121 | repo = filenode_new.changeset.repository |
|
121 | repo = filenode_new.changeset.repository | |
122 | old_raw_id = getattr(filenode_old.changeset, 'raw_id', repo.EMPTY_CHANGESET) |
|
122 | old_raw_id = getattr(filenode_old.changeset, 'raw_id', repo.EMPTY_CHANGESET) | |
123 | new_raw_id = getattr(filenode_new.changeset, 'raw_id', repo.EMPTY_CHANGESET) |
|
123 | new_raw_id = getattr(filenode_new.changeset, 'raw_id', repo.EMPTY_CHANGESET) | |
124 |
|
124 | |||
125 | vcs_gitdiff = repo.get_diff(old_raw_id, new_raw_id, filenode_new.path, |
|
125 | vcs_gitdiff = repo.get_diff(old_raw_id, new_raw_id, filenode_new.path, | |
126 | ignore_whitespace, context) |
|
126 | ignore_whitespace, context) | |
127 | return vcs_gitdiff |
|
127 | return vcs_gitdiff | |
128 |
|
128 | |||
129 |
|
129 | |||
130 | class DiffProcessor(object): |
|
130 | class DiffProcessor(object): | |
131 | """ |
|
131 | """ | |
132 | Give it a unified diff and it returns a list of the files that were |
|
132 | Give it a unified diff and it returns a list of the files that were | |
133 | mentioned in the diff together with a dict of meta information that |
|
133 | mentioned in the diff together with a dict of meta information that | |
134 | can be used to render it in a HTML template. |
|
134 | can be used to render it in a HTML template. | |
135 | """ |
|
135 | """ | |
136 | _chunk_re = re.compile(r'@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)') |
|
136 | _chunk_re = re.compile(r'@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)') | |
137 |
|
137 | |||
138 | def __init__(self, diff, differ='diff', format='udiff'): |
|
138 | def __init__(self, diff, differ='diff', format='udiff'): | |
139 | """ |
|
139 | """ | |
140 | :param diff: a text in diff format or generator |
|
140 | :param diff: a text in diff format or generator | |
141 | :param format: format of diff passed, `udiff` or `gitdiff` |
|
141 | :param format: format of diff passed, `udiff` or `gitdiff` | |
142 | """ |
|
142 | """ | |
143 | if isinstance(diff, basestring): |
|
143 | if isinstance(diff, basestring): | |
144 | diff = [diff] |
|
144 | diff = [diff] | |
145 |
|
145 | |||
146 | self.__udiff = diff |
|
146 | self.__udiff = diff | |
147 | self.__format = format |
|
147 | self.__format = format | |
148 | self.adds = 0 |
|
148 | self.adds = 0 | |
149 | self.removes = 0 |
|
149 | self.removes = 0 | |
150 |
|
150 | |||
151 | if isinstance(self.__udiff, basestring): |
|
151 | if isinstance(self.__udiff, basestring): | |
152 | self.lines = iter(self.__udiff.splitlines(1)) |
|
152 | self.lines = iter(self.__udiff.splitlines(1)) | |
153 |
|
153 | |||
154 | elif self.__format == 'gitdiff': |
|
154 | elif self.__format == 'gitdiff': | |
155 | udiff_copy = self.copy_iterator() |
|
155 | udiff_copy = self.copy_iterator() | |
156 | self.lines = imap(self.escaper, self._parse_gitdiff(udiff_copy)) |
|
156 | self.lines = imap(self.escaper, self._parse_gitdiff(udiff_copy)) | |
157 | else: |
|
157 | else: | |
158 | udiff_copy = self.copy_iterator() |
|
158 | udiff_copy = self.copy_iterator() | |
159 | self.lines = imap(self.escaper, udiff_copy) |
|
159 | self.lines = imap(self.escaper, udiff_copy) | |
160 |
|
160 | |||
161 | # Select a differ. |
|
161 | # Select a differ. | |
162 | if differ == 'difflib': |
|
162 | if differ == 'difflib': | |
163 | self.differ = self._highlight_line_difflib |
|
163 | self.differ = self._highlight_line_difflib | |
164 | else: |
|
164 | else: | |
165 | self.differ = self._highlight_line_udiff |
|
165 | self.differ = self._highlight_line_udiff | |
166 |
|
166 | |||
167 | def escaper(self, string): |
|
167 | def escaper(self, string): | |
168 | return markupsafe.escape(string) |
|
168 | return markupsafe.escape(string) | |
169 |
|
169 | |||
170 | def copy_iterator(self): |
|
170 | def copy_iterator(self): | |
171 | """ |
|
171 | """ | |
172 | make a fresh copy of generator, we should not iterate thru |
|
172 | make a fresh copy of generator, we should not iterate thru | |
173 | an original as it's needed for repeating operations on |
|
173 | an original as it's needed for repeating operations on | |
174 | this instance of DiffProcessor |
|
174 | this instance of DiffProcessor | |
175 | """ |
|
175 | """ | |
176 | self.__udiff, iterator_copy = tee(self.__udiff) |
|
176 | self.__udiff, iterator_copy = tee(self.__udiff) | |
177 | return iterator_copy |
|
177 | return iterator_copy | |
178 |
|
178 | |||
179 | def _extract_rev(self, line1, line2): |
|
179 | def _extract_rev(self, line1, line2): | |
180 | """ |
|
180 | """ | |
181 | Extract the operation (A/M/D), filename and revision hint from a line. |
|
181 | Extract the operation (A/M/D), filename and revision hint from a line. | |
182 | """ |
|
182 | """ | |
183 |
|
183 | |||
184 | try: |
|
184 | try: | |
185 | if line1.startswith('--- ') and line2.startswith('+++ '): |
|
185 | if line1.startswith('--- ') and line2.startswith('+++ '): | |
186 | l1 = line1[4:].split(None, 1) |
|
186 | l1 = line1[4:].split(None, 1) | |
187 | old_filename = (l1[0].replace('a/', '', 1) |
|
187 | old_filename = (l1[0].replace('a/', '', 1) | |
188 | if len(l1) >= 1 else None) |
|
188 | if len(l1) >= 1 else None) | |
189 | old_rev = l1[1] if len(l1) == 2 else 'old' |
|
189 | old_rev = l1[1] if len(l1) == 2 else 'old' | |
190 |
|
190 | |||
191 | l2 = line2[4:].split(None, 1) |
|
191 | l2 = line2[4:].split(None, 1) | |
192 | new_filename = (l2[0].replace('b/', '', 1) |
|
192 | new_filename = (l2[0].replace('b/', '', 1) | |
193 | if len(l1) >= 1 else None) |
|
193 | if len(l1) >= 1 else None) | |
194 | new_rev = l2[1] if len(l2) == 2 else 'new' |
|
194 | new_rev = l2[1] if len(l2) == 2 else 'new' | |
195 |
|
195 | |||
196 | filename = (old_filename |
|
196 | filename = (old_filename | |
197 | if old_filename != '/dev/null' else new_filename) |
|
197 | if old_filename != '/dev/null' else new_filename) | |
198 |
|
198 | |||
199 | operation = 'D' if new_filename == '/dev/null' else None |
|
199 | operation = 'D' if new_filename == '/dev/null' else None | |
200 | if not operation: |
|
200 | if not operation: | |
201 | operation = 'M' if old_filename != '/dev/null' else 'A' |
|
201 | operation = 'M' if old_filename != '/dev/null' else 'A' | |
202 |
|
202 | |||
203 | return operation, filename, new_rev, old_rev |
|
203 | return operation, filename, new_rev, old_rev | |
204 | except (ValueError, IndexError): |
|
204 | except (ValueError, IndexError): | |
205 | pass |
|
205 | pass | |
206 |
|
206 | |||
207 | return None, None, None, None |
|
207 | return None, None, None, None | |
208 |
|
208 | |||
209 | def _parse_gitdiff(self, diffiterator): |
|
209 | def _parse_gitdiff(self, diffiterator): | |
210 | def line_decoder(l): |
|
210 | def line_decoder(l): | |
211 | if l.startswith('+') and not l.startswith('+++'): |
|
211 | if l.startswith('+') and not l.startswith('+++'): | |
212 | self.adds += 1 |
|
212 | self.adds += 1 | |
213 | elif l.startswith('-') and not l.startswith('---'): |
|
213 | elif l.startswith('-') and not l.startswith('---'): | |
214 | self.removes += 1 |
|
214 | self.removes += 1 | |
215 | return l.decode('utf8', 'replace') |
|
215 | return l.decode('utf8', 'replace') | |
216 |
|
216 | |||
217 | output = list(diffiterator) |
|
217 | output = list(diffiterator) | |
218 | size = len(output) |
|
218 | size = len(output) | |
219 |
|
219 | |||
220 | if size == 2: |
|
220 | if size == 2: | |
221 | l = [] |
|
221 | l = [] | |
222 | l.extend([output[0]]) |
|
222 | l.extend([output[0]]) | |
223 | l.extend(output[1].splitlines(1)) |
|
223 | l.extend(output[1].splitlines(1)) | |
224 | return map(line_decoder, l) |
|
224 | return map(line_decoder, l) | |
225 | elif size == 1: |
|
225 | elif size == 1: | |
226 | return map(line_decoder, output[0].splitlines(1)) |
|
226 | return map(line_decoder, output[0].splitlines(1)) | |
227 | elif size == 0: |
|
227 | elif size == 0: | |
228 | return [] |
|
228 | return [] | |
229 |
|
229 | |||
230 | raise Exception('wrong size of diff %s' % size) |
|
230 | raise Exception('wrong size of diff %s' % size) | |
231 |
|
231 | |||
232 | def _highlight_line_difflib(self, line, next_): |
|
232 | def _highlight_line_difflib(self, line, next_): | |
233 | """ |
|
233 | """ | |
234 | Highlight inline changes in both lines. |
|
234 | Highlight inline changes in both lines. | |
235 | """ |
|
235 | """ | |
236 |
|
236 | |||
237 | if line['action'] == 'del': |
|
237 | if line['action'] == 'del': | |
238 | old, new = line, next_ |
|
238 | old, new = line, next_ | |
239 | else: |
|
239 | else: | |
240 | old, new = next_, line |
|
240 | old, new = next_, line | |
241 |
|
241 | |||
242 | oldwords = re.split(r'(\W)', old['line']) |
|
242 | oldwords = re.split(r'(\W)', old['line']) | |
243 | newwords = re.split(r'(\W)', new['line']) |
|
243 | newwords = re.split(r'(\W)', new['line']) | |
244 |
|
244 | |||
245 | sequence = difflib.SequenceMatcher(None, oldwords, newwords) |
|
245 | sequence = difflib.SequenceMatcher(None, oldwords, newwords) | |
246 |
|
246 | |||
247 | oldfragments, newfragments = [], [] |
|
247 | oldfragments, newfragments = [], [] | |
248 | for tag, i1, i2, j1, j2 in sequence.get_opcodes(): |
|
248 | for tag, i1, i2, j1, j2 in sequence.get_opcodes(): | |
249 | oldfrag = ''.join(oldwords[i1:i2]) |
|
249 | oldfrag = ''.join(oldwords[i1:i2]) | |
250 | newfrag = ''.join(newwords[j1:j2]) |
|
250 | newfrag = ''.join(newwords[j1:j2]) | |
251 | if tag != 'equal': |
|
251 | if tag != 'equal': | |
252 | if oldfrag: |
|
252 | if oldfrag: | |
253 | oldfrag = '<del>%s</del>' % oldfrag |
|
253 | oldfrag = '<del>%s</del>' % oldfrag | |
254 | if newfrag: |
|
254 | if newfrag: | |
255 | newfrag = '<ins>%s</ins>' % newfrag |
|
255 | newfrag = '<ins>%s</ins>' % newfrag | |
256 | oldfragments.append(oldfrag) |
|
256 | oldfragments.append(oldfrag) | |
257 | newfragments.append(newfrag) |
|
257 | newfragments.append(newfrag) | |
258 |
|
258 | |||
259 | old['line'] = "".join(oldfragments) |
|
259 | old['line'] = "".join(oldfragments) | |
260 | new['line'] = "".join(newfragments) |
|
260 | new['line'] = "".join(newfragments) | |
261 |
|
261 | |||
262 | def _highlight_line_udiff(self, line, next_): |
|
262 | def _highlight_line_udiff(self, line, next_): | |
263 | """ |
|
263 | """ | |
264 | Highlight inline changes in both lines. |
|
264 | Highlight inline changes in both lines. | |
265 | """ |
|
265 | """ | |
266 | start = 0 |
|
266 | start = 0 | |
267 | limit = min(len(line['line']), len(next_['line'])) |
|
267 | limit = min(len(line['line']), len(next_['line'])) | |
268 | while start < limit and line['line'][start] == next_['line'][start]: |
|
268 | while start < limit and line['line'][start] == next_['line'][start]: | |
269 | start += 1 |
|
269 | start += 1 | |
270 | end = -1 |
|
270 | end = -1 | |
271 | limit -= start |
|
271 | limit -= start | |
272 | while -end <= limit and line['line'][end] == next_['line'][end]: |
|
272 | while -end <= limit and line['line'][end] == next_['line'][end]: | |
273 | end -= 1 |
|
273 | end -= 1 | |
274 | end += 1 |
|
274 | end += 1 | |
275 | if start or end: |
|
275 | if start or end: | |
276 | def do(l): |
|
276 | def do(l): | |
277 | last = end + len(l['line']) |
|
277 | last = end + len(l['line']) | |
278 | if l['action'] == 'add': |
|
278 | if l['action'] == 'add': | |
279 | tag = 'ins' |
|
279 | tag = 'ins' | |
280 | else: |
|
280 | else: | |
281 | tag = 'del' |
|
281 | tag = 'del' | |
282 | l['line'] = '%s<%s>%s</%s>%s' % ( |
|
282 | l['line'] = '%s<%s>%s</%s>%s' % ( | |
283 | l['line'][:start], |
|
283 | l['line'][:start], | |
284 | tag, |
|
284 | tag, | |
285 | l['line'][start:last], |
|
285 | l['line'][start:last], | |
286 | tag, |
|
286 | tag, | |
287 | l['line'][last:] |
|
287 | l['line'][last:] | |
288 | ) |
|
288 | ) | |
289 |
|
||||
290 | do(line) |
|
289 | do(line) | |
291 | do(next_) |
|
290 | do(next_) | |
292 |
|
291 | |||
293 | def _parse_udiff(self): |
|
292 | def _parse_udiff(self): | |
294 | """ |
|
293 | """ | |
295 | Parse the diff an return data for the template. |
|
294 | Parse the diff an return data for the template. | |
296 | """ |
|
295 | """ | |
297 | lineiter = self.lines |
|
296 | lineiter = self.lines | |
298 | files = [] |
|
297 | files = [] | |
299 | try: |
|
298 | try: | |
300 | line = lineiter.next() |
|
299 | line = lineiter.next() | |
301 | # skip first context |
|
|||
302 | skipfirst = True |
|
|||
303 |
|
||||
304 | while 1: |
|
300 | while 1: | |
305 | # continue until we found the old file |
|
301 | # continue until we found the old file | |
306 | if not line.startswith('--- '): |
|
302 | if not line.startswith('--- '): | |
307 | line = lineiter.next() |
|
303 | line = lineiter.next() | |
308 | continue |
|
304 | continue | |
309 |
|
305 | |||
310 | chunks = [] |
|
306 | chunks = [] | |
311 | stats = [0, 0] |
|
307 | stats = [0, 0] | |
312 | operation, filename, old_rev, new_rev = \ |
|
308 | operation, filename, old_rev, new_rev = \ | |
313 | self._extract_rev(line, lineiter.next()) |
|
309 | self._extract_rev(line, lineiter.next()) | |
314 | files.append({ |
|
310 | files.append({ | |
315 | 'filename': filename, |
|
311 | 'filename': filename, | |
316 | 'old_revision': old_rev, |
|
312 | 'old_revision': old_rev, | |
317 | 'new_revision': new_rev, |
|
313 | 'new_revision': new_rev, | |
318 | 'chunks': chunks, |
|
314 | 'chunks': chunks, | |
319 | 'operation': operation, |
|
315 | 'operation': operation, | |
320 | 'stats': stats, |
|
316 | 'stats': stats, | |
321 | }) |
|
317 | }) | |
322 |
|
318 | |||
323 | line = lineiter.next() |
|
319 | line = lineiter.next() | |
324 | while line: |
|
320 | while line: | |
325 |
|
||||
326 | match = self._chunk_re.match(line) |
|
321 | match = self._chunk_re.match(line) | |
327 | if not match: |
|
322 | if not match: | |
328 | break |
|
323 | break | |
329 |
|
324 | |||
330 | lines = [] |
|
325 | lines = [] | |
331 | chunks.append(lines) |
|
326 | chunks.append(lines) | |
332 |
|
327 | |||
333 | old_line, old_end, new_line, new_end = \ |
|
328 | old_line, old_end, new_line, new_end = \ | |
334 | [int(x or 1) for x in match.groups()[:-1]] |
|
329 | [int(x or 1) for x in match.groups()[:-1]] | |
335 | old_line -= 1 |
|
330 | old_line -= 1 | |
336 | new_line -= 1 |
|
331 | new_line -= 1 | |
337 |
|
|
332 | gr = match.groups() | |
|
333 | context = len(gr) == 5 | |||
338 | old_end += old_line |
|
334 | old_end += old_line | |
339 | new_end += new_line |
|
335 | new_end += new_line | |
340 |
|
336 | |||
341 | if context: |
|
337 | if context: | |
342 |
|
|
338 | # skip context only if it's first line | |
|
339 | if int(gr[0]) > 1: | |||
343 | lines.append({ |
|
340 | lines.append({ | |
344 | 'old_lineno': '...', |
|
341 | 'old_lineno': '...', | |
345 | 'new_lineno': '...', |
|
342 | 'new_lineno': '...', | |
346 | 'action': 'context', |
|
343 | 'action': 'context', | |
347 | 'line': line, |
|
344 | 'line': line, | |
348 | }) |
|
345 | }) | |
349 | else: |
|
|||
350 | skipfirst = False |
|
|||
351 |
|
346 | |||
352 | line = lineiter.next() |
|
347 | line = lineiter.next() | |
353 | while old_line < old_end or new_line < new_end: |
|
348 | while old_line < old_end or new_line < new_end: | |
354 | if line: |
|
349 | if line: | |
355 | command, line = line[0], line[1:] |
|
350 | command, line = line[0], line[1:] | |
356 | else: |
|
351 | else: | |
357 | command = ' ' |
|
352 | command = ' ' | |
358 | affects_old = affects_new = False |
|
353 | affects_old = affects_new = False | |
359 |
|
354 | |||
360 | # ignore those if we don't expect them |
|
355 | # ignore those if we don't expect them | |
361 | if command in '#@': |
|
356 | if command in '#@': | |
362 | continue |
|
357 | continue | |
363 | elif command == '+': |
|
358 | elif command == '+': | |
364 | affects_new = True |
|
359 | affects_new = True | |
365 | action = 'add' |
|
360 | action = 'add' | |
366 | stats[0] += 1 |
|
361 | stats[0] += 1 | |
367 | elif command == '-': |
|
362 | elif command == '-': | |
368 | affects_old = True |
|
363 | affects_old = True | |
369 | action = 'del' |
|
364 | action = 'del' | |
370 | stats[1] += 1 |
|
365 | stats[1] += 1 | |
371 | else: |
|
366 | else: | |
372 | affects_old = affects_new = True |
|
367 | affects_old = affects_new = True | |
373 | action = 'unmod' |
|
368 | action = 'unmod' | |
374 |
|
369 | |||
375 | old_line += affects_old |
|
370 | if line.find('No newline at end of file') != -1: | |
376 |
|
|
371 | lines.append({ | |
377 |
|
|
372 | 'old_lineno': '...', | |
378 |
' |
|
373 | 'new_lineno': '...', | |
379 |
' |
|
374 | 'action': 'context', | |
380 |
' |
|
375 | 'line': line | |
381 |
|
|
376 | }) | |
382 | }) |
|
377 | ||
|
378 | else: | |||
|
379 | old_line += affects_old | |||
|
380 | new_line += affects_new | |||
|
381 | lines.append({ | |||
|
382 | 'old_lineno': affects_old and old_line or '', | |||
|
383 | 'new_lineno': affects_new and new_line or '', | |||
|
384 | 'action': action, | |||
|
385 | 'line': line | |||
|
386 | }) | |||
|
387 | ||||
383 | line = lineiter.next() |
|
388 | line = lineiter.next() | |
384 | except StopIteration: |
|
389 | except StopIteration: | |
385 | pass |
|
390 | pass | |
386 |
|
391 | |||
387 | # highlight inline changes |
|
392 | # highlight inline changes | |
388 | for diff_data in files: |
|
393 | for diff_data in files: | |
389 | for chunk in diff_data['chunks']: |
|
394 | for chunk in diff_data['chunks']: | |
390 | lineiter = iter(chunk) |
|
395 | lineiter = iter(chunk) | |
391 | try: |
|
396 | try: | |
392 | while 1: |
|
397 | while 1: | |
393 | line = lineiter.next() |
|
398 | line = lineiter.next() | |
394 | if line['action'] != 'unmod': |
|
399 | if line['action'] != 'unmod': | |
395 | nextline = lineiter.next() |
|
400 | nextline = lineiter.next() | |
396 |
if nextline['action'] |
|
401 | if nextline['action'] in ['unmod', 'context'] or \ | |
397 | nextline['action'] == line['action']: |
|
402 | nextline['action'] == line['action']: | |
398 | continue |
|
403 | continue | |
399 | self.differ(line, nextline) |
|
404 | self.differ(line, nextline) | |
400 | except StopIteration: |
|
405 | except StopIteration: | |
401 | pass |
|
406 | pass | |
402 | return files |
|
407 | return files | |
403 |
|
408 | |||
404 | def prepare(self): |
|
409 | def prepare(self): | |
405 | """ |
|
410 | """ | |
406 | Prepare the passed udiff for HTML rendering. It'l return a list |
|
411 | Prepare the passed udiff for HTML rendering. It'l return a list | |
407 | of dicts |
|
412 | of dicts | |
408 | """ |
|
413 | """ | |
409 | return self._parse_udiff() |
|
414 | return self._parse_udiff() | |
410 |
|
415 | |||
411 | def _safe_id(self, idstring): |
|
416 | def _safe_id(self, idstring): | |
412 | """Make a string safe for including in an id attribute. |
|
417 | """Make a string safe for including in an id attribute. | |
413 |
|
418 | |||
414 | The HTML spec says that id attributes 'must begin with |
|
419 | The HTML spec says that id attributes 'must begin with | |
415 | a letter ([A-Za-z]) and may be followed by any number |
|
420 | a letter ([A-Za-z]) and may be followed by any number | |
416 | of letters, digits ([0-9]), hyphens ("-"), underscores |
|
421 | of letters, digits ([0-9]), hyphens ("-"), underscores | |
417 | ("_"), colons (":"), and periods (".")'. These regexps |
|
422 | ("_"), colons (":"), and periods (".")'. These regexps | |
418 | are slightly over-zealous, in that they remove colons |
|
423 | are slightly over-zealous, in that they remove colons | |
419 | and periods unnecessarily. |
|
424 | and periods unnecessarily. | |
420 |
|
425 | |||
421 | Whitespace is transformed into underscores, and then |
|
426 | Whitespace is transformed into underscores, and then | |
422 | anything which is not a hyphen or a character that |
|
427 | anything which is not a hyphen or a character that | |
423 | matches \w (alphanumerics and underscore) is removed. |
|
428 | matches \w (alphanumerics and underscore) is removed. | |
424 |
|
429 | |||
425 | """ |
|
430 | """ | |
426 | # Transform all whitespace to underscore |
|
431 | # Transform all whitespace to underscore | |
427 | idstring = re.sub(r'\s', "_", '%s' % idstring) |
|
432 | idstring = re.sub(r'\s', "_", '%s' % idstring) | |
428 | # Remove everything that is not a hyphen or a member of \w |
|
433 | # Remove everything that is not a hyphen or a member of \w | |
429 | idstring = re.sub(r'(?!-)\W', "", idstring).lower() |
|
434 | idstring = re.sub(r'(?!-)\W', "", idstring).lower() | |
430 | return idstring |
|
435 | return idstring | |
431 |
|
436 | |||
432 | def raw_diff(self): |
|
437 | def raw_diff(self): | |
433 | """ |
|
438 | """ | |
434 | Returns raw string as udiff |
|
439 | Returns raw string as udiff | |
435 | """ |
|
440 | """ | |
436 | udiff_copy = self.copy_iterator() |
|
441 | udiff_copy = self.copy_iterator() | |
437 | if self.__format == 'gitdiff': |
|
442 | if self.__format == 'gitdiff': | |
438 | udiff_copy = self._parse_gitdiff(udiff_copy) |
|
443 | udiff_copy = self._parse_gitdiff(udiff_copy) | |
439 | return u''.join(udiff_copy) |
|
444 | return u''.join(udiff_copy) | |
440 |
|
445 | |||
441 | def as_html(self, table_class='code-difftable', line_class='line', |
|
446 | def as_html(self, table_class='code-difftable', line_class='line', | |
442 | new_lineno_class='lineno old', old_lineno_class='lineno new', |
|
447 | new_lineno_class='lineno old', old_lineno_class='lineno new', | |
443 | code_class='code', enable_comments=False, diff_lines=None): |
|
448 | code_class='code', enable_comments=False, diff_lines=None): | |
444 | """ |
|
449 | """ | |
445 | Return given diff as html table with customized css classes |
|
450 | Return given diff as html table with customized css classes | |
446 | """ |
|
451 | """ | |
447 | def _link_to_if(condition, label, url): |
|
452 | def _link_to_if(condition, label, url): | |
448 | """ |
|
453 | """ | |
449 | Generates a link if condition is meet or just the label if not. |
|
454 | Generates a link if condition is meet or just the label if not. | |
450 | """ |
|
455 | """ | |
451 |
|
456 | |||
452 | if condition: |
|
457 | if condition: | |
453 | return '''<a href="%(url)s">%(label)s</a>''' % { |
|
458 | return '''<a href="%(url)s">%(label)s</a>''' % { | |
454 | 'url': url, |
|
459 | 'url': url, | |
455 | 'label': label |
|
460 | 'label': label | |
456 | } |
|
461 | } | |
457 | else: |
|
462 | else: | |
458 | return label |
|
463 | return label | |
459 | if diff_lines is None: |
|
464 | if diff_lines is None: | |
460 | diff_lines = self.prepare() |
|
465 | diff_lines = self.prepare() | |
461 | _html_empty = True |
|
466 | _html_empty = True | |
462 | _html = [] |
|
467 | _html = [] | |
463 | _html.append('''<table class="%(table_class)s">\n''' % { |
|
468 | _html.append('''<table class="%(table_class)s">\n''' % { | |
464 | 'table_class': table_class |
|
469 | 'table_class': table_class | |
465 | }) |
|
470 | }) | |
466 | for diff in diff_lines: |
|
471 | for diff in diff_lines: | |
467 | for line in diff['chunks']: |
|
472 | for line in diff['chunks']: | |
468 | _html_empty = False |
|
473 | _html_empty = False | |
469 | for change in line: |
|
474 | for change in line: | |
470 | _html.append('''<tr class="%(lc)s %(action)s">\n''' % { |
|
475 | _html.append('''<tr class="%(lc)s %(action)s">\n''' % { | |
471 | 'lc': line_class, |
|
476 | 'lc': line_class, | |
472 | 'action': change['action'] |
|
477 | 'action': change['action'] | |
473 | }) |
|
478 | }) | |
474 | anchor_old_id = '' |
|
479 | anchor_old_id = '' | |
475 | anchor_new_id = '' |
|
480 | anchor_new_id = '' | |
476 | anchor_old = "%(filename)s_o%(oldline_no)s" % { |
|
481 | anchor_old = "%(filename)s_o%(oldline_no)s" % { | |
477 | 'filename': self._safe_id(diff['filename']), |
|
482 | 'filename': self._safe_id(diff['filename']), | |
478 | 'oldline_no': change['old_lineno'] |
|
483 | 'oldline_no': change['old_lineno'] | |
479 | } |
|
484 | } | |
480 | anchor_new = "%(filename)s_n%(oldline_no)s" % { |
|
485 | anchor_new = "%(filename)s_n%(oldline_no)s" % { | |
481 | 'filename': self._safe_id(diff['filename']), |
|
486 | 'filename': self._safe_id(diff['filename']), | |
482 | 'oldline_no': change['new_lineno'] |
|
487 | 'oldline_no': change['new_lineno'] | |
483 | } |
|
488 | } | |
484 | cond_old = (change['old_lineno'] != '...' and |
|
489 | cond_old = (change['old_lineno'] != '...' and | |
485 | change['old_lineno']) |
|
490 | change['old_lineno']) | |
486 | cond_new = (change['new_lineno'] != '...' and |
|
491 | cond_new = (change['new_lineno'] != '...' and | |
487 | change['new_lineno']) |
|
492 | change['new_lineno']) | |
488 | if cond_old: |
|
493 | if cond_old: | |
489 | anchor_old_id = 'id="%s"' % anchor_old |
|
494 | anchor_old_id = 'id="%s"' % anchor_old | |
490 | if cond_new: |
|
495 | if cond_new: | |
491 | anchor_new_id = 'id="%s"' % anchor_new |
|
496 | anchor_new_id = 'id="%s"' % anchor_new | |
492 | ########################################################### |
|
497 | ########################################################### | |
493 | # OLD LINE NUMBER |
|
498 | # OLD LINE NUMBER | |
494 | ########################################################### |
|
499 | ########################################################### | |
495 | _html.append('''\t<td %(a_id)s class="%(olc)s">''' % { |
|
500 | _html.append('''\t<td %(a_id)s class="%(olc)s">''' % { | |
496 | 'a_id': anchor_old_id, |
|
501 | 'a_id': anchor_old_id, | |
497 | 'olc': old_lineno_class |
|
502 | 'olc': old_lineno_class | |
498 | }) |
|
503 | }) | |
499 |
|
504 | |||
500 | _html.append('''%(link)s''' % { |
|
505 | _html.append('''%(link)s''' % { | |
501 | 'link': _link_to_if(True, change['old_lineno'], |
|
506 | 'link': _link_to_if(True, change['old_lineno'], | |
502 | '#%s' % anchor_old) |
|
507 | '#%s' % anchor_old) | |
503 | }) |
|
508 | }) | |
504 | _html.append('''</td>\n''') |
|
509 | _html.append('''</td>\n''') | |
505 | ########################################################### |
|
510 | ########################################################### | |
506 | # NEW LINE NUMBER |
|
511 | # NEW LINE NUMBER | |
507 | ########################################################### |
|
512 | ########################################################### | |
508 |
|
513 | |||
509 | _html.append('''\t<td %(a_id)s class="%(nlc)s">''' % { |
|
514 | _html.append('''\t<td %(a_id)s class="%(nlc)s">''' % { | |
510 | 'a_id': anchor_new_id, |
|
515 | 'a_id': anchor_new_id, | |
511 | 'nlc': new_lineno_class |
|
516 | 'nlc': new_lineno_class | |
512 | }) |
|
517 | }) | |
513 |
|
518 | |||
514 | _html.append('''%(link)s''' % { |
|
519 | _html.append('''%(link)s''' % { | |
515 | 'link': _link_to_if(True, change['new_lineno'], |
|
520 | 'link': _link_to_if(True, change['new_lineno'], | |
516 | '#%s' % anchor_new) |
|
521 | '#%s' % anchor_new) | |
517 | }) |
|
522 | }) | |
518 | _html.append('''</td>\n''') |
|
523 | _html.append('''</td>\n''') | |
519 | ########################################################### |
|
524 | ########################################################### | |
520 | # CODE |
|
525 | # CODE | |
521 | ########################################################### |
|
526 | ########################################################### | |
522 | comments = '' if enable_comments else 'no-comment' |
|
527 | comments = '' if enable_comments else 'no-comment' | |
523 | _html.append('''\t<td class="%(cc)s %(inc)s">''' % { |
|
528 | _html.append('''\t<td class="%(cc)s %(inc)s">''' % { | |
524 | 'cc': code_class, |
|
529 | 'cc': code_class, | |
525 | 'inc': comments |
|
530 | 'inc': comments | |
526 | }) |
|
531 | }) | |
527 | _html.append('''\n\t\t<pre>%(code)s</pre>\n''' % { |
|
532 | _html.append('''\n\t\t<pre>%(code)s</pre>\n''' % { | |
528 | 'code': change['line'] |
|
533 | 'code': change['line'] | |
529 | }) |
|
534 | }) | |
530 | _html.append('''\t</td>''') |
|
535 | _html.append('''\t</td>''') | |
531 | _html.append('''\n</tr>\n''') |
|
536 | _html.append('''\n</tr>\n''') | |
532 | _html.append('''</table>''') |
|
537 | _html.append('''</table>''') | |
533 | if _html_empty: |
|
538 | if _html_empty: | |
534 | return None |
|
539 | return None | |
535 | return ''.join(_html) |
|
540 | return ''.join(_html) | |
536 |
|
541 | |||
537 | def stat(self): |
|
542 | def stat(self): | |
538 | """ |
|
543 | """ | |
539 | Returns tuple of added, and removed lines for this instance |
|
544 | Returns tuple of added, and removed lines for this instance | |
540 | """ |
|
545 | """ | |
541 | return self.adds, self.removes |
|
546 | return self.adds, self.removes | |
542 |
|
547 | |||
543 |
|
548 | |||
544 | def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None): |
|
549 | def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None): | |
545 | """ |
|
550 | """ | |
546 | General differ between branches, bookmarks or separate but releated |
|
551 | General differ between branches, bookmarks or separate but releated | |
547 | repositories |
|
552 | repositories | |
548 |
|
553 | |||
549 | :param org_repo: |
|
554 | :param org_repo: | |
550 | :type org_repo: |
|
555 | :type org_repo: | |
551 | :param org_ref: |
|
556 | :param org_ref: | |
552 | :type org_ref: |
|
557 | :type org_ref: | |
553 | :param other_repo: |
|
558 | :param other_repo: | |
554 | :type other_repo: |
|
559 | :type other_repo: | |
555 | :param other_ref: |
|
560 | :param other_ref: | |
556 | :type other_ref: |
|
561 | :type other_ref: | |
557 | """ |
|
562 | """ | |
558 |
|
563 | |||
559 | ignore_whitespace = False |
|
564 | ignore_whitespace = False | |
560 | context = 3 |
|
565 | context = 3 | |
561 | org_repo = org_repo.scm_instance._repo |
|
566 | org_repo = org_repo.scm_instance._repo | |
562 | other_repo = other_repo.scm_instance._repo |
|
567 | other_repo = other_repo.scm_instance._repo | |
563 | opts = diffopts(git=True, ignorews=ignore_whitespace, context=context) |
|
568 | opts = diffopts(git=True, ignorews=ignore_whitespace, context=context) | |
564 | org_ref = org_ref[1] |
|
569 | org_ref = org_ref[1] | |
565 | other_ref = other_ref[1] |
|
570 | other_ref = other_ref[1] | |
566 |
|
571 | |||
567 | if org_repo != other_repo: |
|
572 | if org_repo != other_repo: | |
568 |
|
573 | |||
569 | common, incoming, rheads = discovery_data |
|
574 | common, incoming, rheads = discovery_data | |
570 | # create a bundle (uncompressed if other repo is not local) |
|
575 | # create a bundle (uncompressed if other repo is not local) | |
571 | if other_repo.capable('getbundle'): |
|
576 | if other_repo.capable('getbundle'): | |
572 | # disable repo hooks here since it's just bundle ! |
|
577 | # disable repo hooks here since it's just bundle ! | |
573 | # patch and reset hooks section of UI config to not run any |
|
578 | # patch and reset hooks section of UI config to not run any | |
574 | # hooks on fetching archives with subrepos |
|
579 | # hooks on fetching archives with subrepos | |
575 | for k, _ in other_repo.ui.configitems('hooks'): |
|
580 | for k, _ in other_repo.ui.configitems('hooks'): | |
576 | other_repo.ui.setconfig('hooks', k, None) |
|
581 | other_repo.ui.setconfig('hooks', k, None) | |
577 |
|
582 | |||
578 | unbundle = other_repo.getbundle('incoming', common=common, |
|
583 | unbundle = other_repo.getbundle('incoming', common=common, | |
579 | heads=rheads) |
|
584 | heads=rheads) | |
580 |
|
585 | |||
581 | buf = io.BytesIO() |
|
586 | buf = io.BytesIO() | |
582 | while True: |
|
587 | while True: | |
583 | chunk = unbundle._stream.read(1024*4) |
|
588 | chunk = unbundle._stream.read(1024*4) | |
584 | if not chunk: |
|
589 | if not chunk: | |
585 | break |
|
590 | break | |
586 | buf.write(chunk) |
|
591 | buf.write(chunk) | |
587 |
|
592 | |||
588 | buf.seek(0) |
|
593 | buf.seek(0) | |
589 | unbundle._stream = buf |
|
594 | unbundle._stream = buf | |
590 |
|
595 | |||
591 | class InMemoryBundleRepo(bundlerepository): |
|
596 | class InMemoryBundleRepo(bundlerepository): | |
592 | def __init__(self, ui, path, bundlestream): |
|
597 | def __init__(self, ui, path, bundlestream): | |
593 | self._tempparent = None |
|
598 | self._tempparent = None | |
594 | localrepo.localrepository.__init__(self, ui, path) |
|
599 | localrepo.localrepository.__init__(self, ui, path) | |
595 | self.ui.setconfig('phases', 'publish', False) |
|
600 | self.ui.setconfig('phases', 'publish', False) | |
596 |
|
601 | |||
597 | self.bundle = bundlestream |
|
602 | self.bundle = bundlestream | |
598 |
|
603 | |||
599 | # dict with the mapping 'filename' -> position in the bundle |
|
604 | # dict with the mapping 'filename' -> position in the bundle | |
600 | self.bundlefilespos = {} |
|
605 | self.bundlefilespos = {} | |
601 |
|
606 | |||
602 | ui = make_ui('db') |
|
607 | ui = make_ui('db') | |
603 | bundlerepo = InMemoryBundleRepo(ui, path=other_repo.root, |
|
608 | bundlerepo = InMemoryBundleRepo(ui, path=other_repo.root, | |
604 | bundlestream=unbundle) |
|
609 | bundlestream=unbundle) | |
605 | return ''.join(patch.diff(bundlerepo, node1=org_ref, node2=other_ref, |
|
610 | return ''.join(patch.diff(bundlerepo, node1=org_ref, node2=other_ref, | |
606 | opts=opts)) |
|
611 | opts=opts)) | |
607 | else: |
|
612 | else: | |
608 | return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref, |
|
613 | return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref, | |
609 | opts=opts)) |
|
614 | opts=opts)) |
General Comments 0
You need to be logged in to leave comments.
Login now