├── .github └── workflows │ └── build.yaml ├── .gitignore ├── .gitmodules ├── Dockerfile ├── LICENSE ├── README.md ├── fast-export2.pro ├── samples ├── ignore-branch.rules ├── merged-branches-tags.rules ├── min-max-revision.rules ├── recurse.rules ├── standardlayout.rules └── two-projects.rules ├── src ├── CommandLineParser.cpp ├── CommandLineParser.h ├── main.cpp ├── repository.cpp ├── repository.h ├── ruleparser.cpp ├── ruleparser.h ├── src.pro ├── svn.cpp └── svn.h ├── test.sh └── test ├── base-fixture.tar ├── command-line.bats ├── common.bash ├── copy-directories.bats ├── empty-dirs.bats └── svn-ignore.bats /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Sebastian Pipping 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | name: Build (Linux, Ubuntu) 18 | 19 | on: 20 | pull_request: 21 | push: 22 | schedule: 23 | - cron: '0 2 * * 5' # Every Friday at 2am 24 | workflow_dispatch: 25 | 26 | # Reduce permissions to minimum for security 27 | permissions: 28 | contents: read 29 | 30 | jobs: 31 | build: 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | include: 36 | - runs-on: ubuntu-24.04 37 | qt_major: 6 38 | qt_qmake: qmake6 39 | qt_packages: qmake6 qt6-base-dev qt6-5compat-dev 40 | - runs-on: ubuntu-24.04 41 | qt_major: 5 42 | qt_qmake: qmake 43 | qt_packages: qt5-qmake qtbase5-dev 44 | - runs-on: ubuntu-22.04 45 | qt_major: 6 46 | qt_qmake: qmake6 47 | qt_packages: qmake6 qt6-base-dev libqt6core5compat6-dev 48 | - runs-on: ubuntu-22.04 49 | qt_major: 5 50 | qt_qmake: qmake 51 | qt_packages: qt5-qmake qtbase5-dev 52 | 53 | name: Build (Linux, ${{ matrix.runs-on }}, Qt ${{ matrix.qt_major }}) 54 | runs-on: ${{ matrix.runs-on }} 55 | steps: 56 | - name: 'Install build dependencies' 57 | run: |- 58 | set -e 59 | sudo apt-get update 60 | sudo apt-get install --yes --no-install-recommends \ 61 | build-essential \ 62 | libapr1-dev \ 63 | libsvn-dev \ 64 | ${{ matrix.qt_packages }} \ 65 | subversion 66 | 67 | - name: 'Checkout Git branch' 68 | uses: actions/checkout@v3 69 | with: 70 | submodules: true 71 | 72 | - name: 'Configure' 73 | env: 74 | QMAKE: ${{ matrix.qt_qmake }} 75 | run: |- 76 | ${QMAKE} 77 | 78 | - name: 'Build' 79 | run: |- 80 | make 81 | 82 | - name: 'Test' 83 | run: |- 84 | ./test.sh --no-make 85 | 86 | - name: 'Install' 87 | run: |- 88 | set -e 89 | make INSTALL_ROOT="${PWD}"/ROOT install 90 | find ROOT | sort 91 | 92 | docker: 93 | name: Check Dockerfile 94 | runs-on: ubuntu-latest 95 | steps: 96 | - name: 'Checkout Git branch' 97 | uses: actions/checkout@v3 98 | with: 99 | submodules: true 100 | 101 | - name: 'Build' 102 | run: |- 103 | docker build . 104 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | *~ 3 | *.o 4 | svn-all-fast-export 5 | svn-all-fast-export.exe 6 | src/local-config.pri 7 | /build/ 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "test/libs/bats-core"] 2 | path = test/libs/bats-core 3 | url = https://github.com/bats-core/bats-core 4 | [submodule "test/libs/bats-assert"] 5 | path = test/libs/bats-assert 6 | url = https://github.com/bats-core/bats-assert 7 | [submodule "test/libs/bats-support"] 8 | path = test/libs/bats-support 9 | url = https://github.com/bats-core/bats-support 10 | [submodule "test/libs/bats-file"] 11 | path = test/libs/bats-file 12 | url = https://github.com/tralston/bats-file 13 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | # Change locale to let svn handle international characters 4 | ENV LC_ALL C.UTF-8 5 | 6 | # Install dependencies 7 | RUN apt-get update && apt-get install --yes --no-install-recommends \ 8 | build-essential \ 9 | libapr1-dev \ 10 | libsvn-dev \ 11 | qt5-qmake \ 12 | qtbase5-dev \ 13 | git \ 14 | subversion \ 15 | && rm -rf /var/lib/apt/lists/* 16 | 17 | # Build the binary 18 | RUN mkdir /usr/local/svn2git 19 | ADD . /usr/local/svn2git 20 | RUN cd /usr/local/svn2git && qmake && make 21 | 22 | # Docker interface 23 | WORKDIR /workdir 24 | CMD /usr/local/svn2git/svn-all-fast-export 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | svn-all-fast-export aka svn2git 2 | =============================== 3 | This project contains all the tools required to do a conversion of an svn repository (server side, not a checkout) to one or more git repositories. 4 | 5 | This is the tool used to convert KDE's Subversion into multiple Git repositories. You can find more description and usage examples at https://techbase.kde.org/Projects/MoveToGit/UsingSvn2Git 6 | 7 | 8 | How does it work 9 | ---------------- 10 | The svn2git repository gets you an application that will do the actual conversion. 11 | The conversion exists of looping over each and every commit in the subversion repository and matching the changes to a ruleset after which the changes are applied to a certain path in a git repo. 12 | The ruleset can specify which git repository to use and thus you can have more than one git repository as a result of running the conversion. 13 | Also noteworthy is that you can have a rule that, for example, changes in svnrepo/branches/foo/2.1/ will appear as a git-branch in a repository. 14 | 15 | If you have a proper ruleset the tool will create the git repositories for you and show progress while converting commit by commit. 16 | 17 | After it is done you likely want to run `git repack -a -d -f` to compress the pack file as it can get quite big. 18 | 19 | Running as Docker image 20 | ----------------------- 21 | Just mount your SVN folder, plus another working directory where Git repository will be created. 22 | Sample usage with input mounted in /tmp and output produced in /workdir: 23 | ``` 24 | docker build -t svn2git . 25 | docker run --rm -it -v `pwd`/workdir:/workdir -v /var/lib/svn/project1:/tmp/svn -v `pwd`/conf:/tmp/conf svn2git /usr/local/svn2git/svn-all-fast-export --identity-map /tmp/conf/project1.authors --rules /tmp/conf/project1.rules --add-metadata --svn-branches --debug-rules --svn-ignore --empty-dirs /tmp/svn/ 26 | ``` 27 | 28 | Building the tool 29 | ----------------- 30 | Run `qmake && make`. You get `./svn-all-fast-export`. 31 | (Do a checkout of the repo .git' and run qmake and make. You can only build it after having installed libsvn-dev, and naturally Qt. Running the command will give you all the options you can pass to the tool.) 32 | 33 | You will need to have some packages to compile it. For Ubuntu distros, use this command to install them all: 34 | `sudo apt-get install build-essential subversion git qtchooser qt5-default libapr1 libapr1-dev libsvn-dev` 35 | 36 | To run all tests you can simply call the `test.sh` script in the root directory. 37 | This will run all [Bats](https://github.com/bats-core/bats-core) based tests 38 | found in `.bats` files in the directory `test`. Running the script will automatically 39 | execute `qmake` and `make` first to build the current code if necessary. 40 | If you want to run tests without running make, you can give `--no-make` as first parameter. 41 | If you want to only run a subset of the tests, you can specify the base-name of one 42 | or multiple `.bats` files to only run these tests like `./test.sh command-line svn-ignore`. 43 | If you want to investigate the temporary files generated during a test run, 44 | you can set the environment variables `BATSLIB_TEMP_PRESERVE=1` or `BATSLIB_TEMP_PRESERVE_ON_FAILURE=1`. 45 | So if for example some test in `svn-ignore.bats` failed, you can investigate the failed case like 46 | `BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 ./test.sh --no-make svn-ignore` and then look 47 | in `build/tmp` to investigate the situation. 48 | 49 | KDE 50 | --- 51 | there is a repository kde-ruleset which has several example files and one file that should become the final ruleset for the whole of KDE called 'kde-rules-main'. 52 | 53 | Write the Rules 54 | --------------- 55 | You need to write a rules file that describes how to slice the Subversion history into Git repositories and branches. See https://techbase.kde.org/Projects/MoveToGit/UsingSvn2Git. 56 | The rules are also documented in the 'samples' directory of the svn2git repository. Feel free to add more documentation here as well. 57 | 58 | Rules 59 | ----- 60 | ### `create respository` 61 | 62 | ``` 63 | create repository REPOSITORY NAME 64 | [PARAMETERS...] 65 | end repository 66 | ``` 67 | 68 | `PARAMETERS` is any number of: 69 | 70 | - `repository TARGET REPOSITORY` Creates a forwarding repository , which allows for redirecting to another repository, typically with some `prefix`. 71 | - `prefix PREFIX` prefixes each file with `PREFIX`, allowing for merging repositories. 72 | - `description DESCRIPTION TEXT` writes a `DESCRIPTION TEXT` to the `description` file in the repository 73 | 74 | ### `match` 75 | 76 | ``` 77 | match REGEX 78 | [PARAMETERS...] 79 | end match 80 | ``` 81 | 82 | Creates a rule that matches paths by `REGEX` and applies some `PARAMETERS` to them. Matching groups can be created, and the values used in the parameters. 83 | You need to make sure the regex matching a SVN directory path matches also the end slash (e.g. `./`) otherwise Git fast-import will crash with an `fatal: Empty path component found in input` errors. 84 | For example, the rule `/project/trunk/.*/myFolder`, should become `/project/trunk/.*/myFolder/`. 85 | 86 | 87 | 88 | `PARAMETERS` is any number of: 89 | 90 | - `repository TARGET REPOSITORY` determines the repository 91 | - `branch BRANCH NAME` determines which branch this path will be placed in. Can also be used to make lightweight tags with `refs/tags/TAG NAME` although note that tags in SVN are not always a single commit, and will not be created correctly unless they are a single copy from somewhere else, with no further changes. See also `annotate true` to make them annotated tags. 92 | - `[min|max] revision REVISION NUMBER` only match if revision is above/below the specified revision number 93 | - `prefix PREFIX` prefixes each file with `PREFIX`, allowing for merging repositories. Same as when used in a `create repository` stanza. 94 | - Note that this will create a separate commit for each prefix matched, even if they were in the same SVN revision. 95 | - `substitute [repository|branch] s/PATTERN/REPLACEMENT/` performs a regex substitution on the repository or branch name. Useful when eliminating characters not supported in git branch names. 96 | - `action ACTION` determines the action to take, from the below three: 97 | 98 | - `export` I have no idea what this does 99 | - `ignore` ignores this path 100 | - `recurse` tells svn2git to ignore this path and continue searching its children. 101 | 102 | - `annotated true` creates annotated tags instead of lightweight tags. You can see the commit log with `git tag -n`. 103 | 104 | ### `include FILENAME` 105 | 106 | Include the contents of another rules file 107 | 108 | ### `declare VAR=VALUE` 109 | 110 | Define variables that can be referenced later. `${VAR}` in any line will be replaced by `VALUE`. 111 | 112 | 113 | Work flow 114 | --------- 115 | Please feel free to fill this section in. 116 | 117 | Some SVN tricks 118 | --------------- 119 | You can access your newly rsynced SVN repo with commands like `svn ls file:///path/to/repo/trunk/KDE`. 120 | A common issue is tracking when an item left playground for kdereview and then went from kdereview to its final destination. There is no straightforward way to do this. So the following command comes in handy: `svn log -v file:///path/to/repo/kde-svn/kde/trunk/kdereview | grep /trunk/kdereview/mplayerthumbs -A 5 -B 5` This will print all commits relevant to the package you are trying to track. You can also pipe the above command to head or tail to see the first and last commit it was in that directory. 121 | -------------------------------------------------------------------------------- /fast-export2.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | # Directories 4 | SUBDIRS = src 5 | -------------------------------------------------------------------------------- /samples/ignore-branch.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Declare the repositories we know about: 3 | # 4 | 5 | create repository myproject 6 | end repository 7 | 8 | # 9 | # Declare the rules 10 | # Note: rules must end in a slash 11 | # 12 | 13 | match /trunk/ 14 | repository myproject 15 | branch main 16 | end match 17 | 18 | # Ignore this branch: 19 | # We ignore a branch by not telling svn-all-fast-export what to do 20 | # with this path 21 | # Note that rules are applied in order of appearance, so this rule 22 | # must appear before the generic branch rule 23 | match /branches/abandoned-work/ 24 | end match 25 | 26 | match /branches/([^/]+)/ 27 | repository myproject 28 | branch \1 29 | end match 30 | 31 | # No tag processing 32 | -------------------------------------------------------------------------------- /samples/merged-branches-tags.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Declare the repositories we know about: 3 | # 4 | 5 | create repository myproject 6 | end repository 7 | 8 | # 9 | # Declare the rules 10 | # Note: rules must end in a slash 11 | # 12 | 13 | match /trunk/ 14 | repository myproject 15 | branch main 16 | end match 17 | 18 | # Subversion doesn't understand the Git concept of tags 19 | # In Subversion, tags are really branches 20 | # 21 | # Only a post-processing (i.e., after converting to Git) of the tag 22 | # branches can we be sure that a tag wasn't moved or changed from the 23 | # branch it was copied from 24 | # 25 | # So we don't pretend that SVN tags are Git tags and then import 26 | # everything as one 27 | 28 | match /(branches|tags)/([^/]+)/ 29 | repository myproject 30 | branch \2 31 | end match 32 | -------------------------------------------------------------------------------- /samples/min-max-revision.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Declare the repositories we know about: 3 | # 4 | 5 | create repository myproject 6 | end repository 7 | 8 | # 9 | # Declare the rules 10 | # Note: rules must end in a slash 11 | # 12 | 13 | # Ignore this particular revision in trunk 14 | # See ignore-branch.rules first 15 | # Note that rules are applied in order of appearance, so this rule 16 | # must appear before the generic trunk rule 17 | match /trunk/ 18 | min revision 123 19 | max revision 123 20 | end match 21 | 22 | # Stop importing trunk 23 | # If we don't specify a max revision, then there is no limit 24 | # The same applies to min revision (i.e., min revision is 0) 25 | match /trunk/ 26 | min revision 1234 27 | end match 28 | 29 | match /trunk/ 30 | repository myproject 31 | branch main 32 | end match 33 | 34 | match /branches/([^/]+)/ 35 | repository myproject 36 | branch \1 37 | end match 38 | 39 | # No tag processing 40 | -------------------------------------------------------------------------------- /samples/recurse.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Declare the repositories we know about: 3 | # 4 | 5 | create repository project1 6 | end repository 7 | 8 | create repository project2 9 | end repository 10 | 11 | # 12 | # Declare the rules 13 | # Note: rules must end in a slash 14 | # 15 | 16 | match /trunk/([^/]+)/ 17 | repository \1 18 | branch main 19 | end match 20 | 21 | # 22 | # SVN layout: 23 | # /branches/branchname/project1 24 | # /branches/branchname/project2 25 | match /branches/([^/]+)/([^/]+)/ 26 | repository \2 27 | branch \1 28 | end match 29 | 30 | 31 | # 32 | # Example of the recurse rule: 33 | # We tell svn-all-fast-export to not import anything 34 | # but to go inside and recurse in the subdirs 35 | # Note how the ending slash is missing in this particular case 36 | 37 | match /branches/[^/]+ 38 | action recurse 39 | end match 40 | 41 | # No tag processing 42 | -------------------------------------------------------------------------------- /samples/standardlayout.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Declare the repositories we know about: 3 | # 4 | 5 | create repository myproject 6 | end repository 7 | 8 | # 9 | # Declare the rules 10 | # Note: rules must end in a slash 11 | # 12 | 13 | match /trunk/ 14 | repository myproject 15 | branch main 16 | end match 17 | 18 | match /branches/([^/]+)/ 19 | repository myproject 20 | branch \1 21 | end match 22 | 23 | # Important: 24 | # Subversion doesn't understand the Git concept of tags 25 | # In Subversion, tags are really branches 26 | # 27 | # Only a post-processing (i.e., after converting to Git) of the tag 28 | # branches can we be sure that a tag wasn't moved or changed from the 29 | # branch it was copied from 30 | # 31 | # This rule will create tags that don't exist in any of the 32 | # branches. It's not what you want. 33 | # See the merged-branches-tags.rules file 34 | match /tags/([^/]+)/ 35 | repository myproject 36 | branch refs/tags/\1 37 | end match 38 | -------------------------------------------------------------------------------- /samples/two-projects.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Declare the repositories we know about: 3 | # 4 | 5 | create repository project1 6 | end repository 7 | 8 | create repository project2 9 | end repository 10 | 11 | # 12 | # Declare the rules 13 | # Note: rules must end in a slash 14 | # 15 | 16 | match /project1/trunk/ 17 | repository project1 18 | branch main 19 | end match 20 | 21 | match /project2/trunk/ 22 | repository project2 23 | branch main 24 | end match 25 | 26 | # Note how we can use regexp to capture the repository name 27 | match /([^/]+)/branches/([^/]+)/ 28 | repository \1 29 | branch \2 30 | end match 31 | 32 | # No tag processing 33 | -------------------------------------------------------------------------------- /src/CommandLineParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the vng project 3 | * Copyright (C) 2008 Thomas Zander 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "CommandLineParser.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | CommandLineParser *CommandLineParser::self = 0; 28 | 29 | class CommandLineParser::Private 30 | { 31 | public: 32 | Private(int argc, char **argv); 33 | 34 | // functions 35 | void addDefinitions(const CommandLineOption * options); 36 | void setArgumentDefinition(const char *definition); 37 | void parse(); 38 | 39 | // variables; 40 | const int argumentCount; 41 | char ** const argumentStrings; 42 | bool dirty; 43 | int requiredArguments; 44 | QString argumentDefinition; 45 | 46 | struct OptionDefinition { 47 | OptionDefinition() : optionalParameters(0), requiredParameters(0) { } 48 | QString name; 49 | QString comment; 50 | QChar shortName; 51 | int optionalParameters; 52 | int requiredParameters; 53 | }; 54 | 55 | // result of what the user typed 56 | struct ParsedOption { 57 | QString option; 58 | QList parameters; 59 | }; 60 | 61 | QList definitions; 62 | QHash options; 63 | QList arguments; 64 | QList undefinedOptions; 65 | QList errors; 66 | }; 67 | 68 | 69 | CommandLineParser::Private::Private(int argc, char **argv) 70 | : argumentCount(argc), argumentStrings(argv), dirty(true), 71 | requiredArguments(0) 72 | { 73 | } 74 | 75 | void CommandLineParser::Private::addDefinitions(const CommandLineOption * options) 76 | { 77 | for (int i=0; options[i].specification != 0; i++) { 78 | OptionDefinition definition; 79 | QString option = QString::fromLatin1(options[i].specification); 80 | // options with optional params are written as "--option required[, optional] 81 | if (option.indexOf(QLatin1Char(',')) >= 0 && ( option.indexOf(QLatin1Char('[')) < 0 || option.indexOf(QLatin1Char(']')) < 0) ) { 82 | QStringList optionParts = option.split(QLatin1Char(','), Qt::SkipEmptyParts); 83 | if (optionParts.count() != 2) { 84 | qWarning() << "WARN: option definition '" << option << "' is faulty; only one ',' allowed"; 85 | continue; 86 | } 87 | foreach (QString s, optionParts) { 88 | s = s.trimmed(); 89 | if (s.startsWith(QLatin1String("--")) && s.length() > 2) 90 | definition.name = s.mid(2); 91 | else if (s.startsWith(QLatin1String("-")) && s.length() > 1) 92 | definition.shortName = s.at(1); 93 | else { 94 | qWarning() << "WARN: option definition '" << option << "' is faulty; the option should start with a -"; 95 | break; 96 | } 97 | } 98 | } 99 | else if (option.startsWith(QLatin1String("--")) && option.length() > 2) 100 | definition.name = option.mid(2); 101 | else 102 | qWarning() << "WARN: option definition '" << option << "' has unrecognized format. See the api docs for CommandLineParser for a howto"; 103 | 104 | if(definition.name.isEmpty()) 105 | continue; 106 | if (option.indexOf(QLatin1Char(' ')) > 0) { 107 | QStringList optionParts = definition.name.split(QLatin1Char(' '), Qt::SkipEmptyParts); 108 | definition.name = optionParts[0]; 109 | bool first = true; 110 | foreach (QString s, optionParts) { 111 | if (first) { 112 | first = false; 113 | continue; 114 | } 115 | s = s.trimmed(); 116 | if (s[0].unicode() == '[' && s.endsWith(QLatin1Char(']'))) 117 | definition.optionalParameters++; 118 | else 119 | definition.requiredParameters++; 120 | } 121 | } 122 | 123 | definition.comment = QString::fromLatin1(options[i].description); 124 | definitions << definition; 125 | } 126 | /* 127 | foreach (OptionDefinition def, definitions) { 128 | qDebug() << "definition:" << (def.shortName != 0 ? def.shortName : QChar(32)) << "|" << def.name << "|" << def.comment 129 | << "|" << def.requiredParameters << "+" << def.optionalParameters; 130 | } 131 | */ 132 | 133 | dirty = true; 134 | } 135 | 136 | void CommandLineParser::Private::setArgumentDefinition(const char *defs) 137 | { 138 | requiredArguments = 0; 139 | argumentDefinition = QString::fromLatin1(defs); 140 | QStringList optionParts = argumentDefinition.split(QLatin1Char(' '), Qt::SkipEmptyParts); 141 | bool inArg = false; 142 | foreach (QString s, optionParts) { 143 | s = s.trimmed(); 144 | if (s[0].unicode() == '<') { 145 | inArg = true; 146 | requiredArguments++; 147 | } 148 | else if (s[0].unicode() == '[') 149 | inArg = true; 150 | if (s.endsWith(QLatin1Char('>'))) 151 | inArg = false; 152 | else if (!inArg) 153 | requiredArguments++; 154 | } 155 | } 156 | 157 | void CommandLineParser::Private::parse() 158 | { 159 | if (dirty == false) 160 | return; 161 | errors.clear(); 162 | options.clear(); 163 | arguments.clear(); 164 | undefinedOptions.clear(); 165 | dirty = false; 166 | 167 | class OptionProcessor { 168 | public: 169 | OptionProcessor(Private *d) : clp(d) { } 170 | 171 | void next(Private::ParsedOption &option) { 172 | if (! option.option.isEmpty()) { 173 | // find the definition to match. 174 | OptionDefinition def; 175 | foreach (Private::OptionDefinition definition, clp->definitions) { 176 | if (definition.name == option.option) { 177 | def = definition; 178 | break; 179 | } 180 | } 181 | if (! def.name.isEmpty() && def.requiredParameters >= option.parameters.count() && 182 | def.requiredParameters + def.optionalParameters <= option.parameters.count()) 183 | clp->options.insert(option.option, option); 184 | else if (!clp->undefinedOptions.contains(option.option)) 185 | clp->undefinedOptions << option.option; 186 | else 187 | clp->errors.append(QLatin1String("Not enough arguments passed for option `") 188 | + option.option +QLatin1Char('\'')); 189 | } 190 | option.option.clear(); 191 | option.parameters.clear(); 192 | } 193 | 194 | private: 195 | CommandLineParser::Private *clp; 196 | }; 197 | OptionProcessor processor(this); 198 | 199 | bool optionsAllowed = true; 200 | ParsedOption option; 201 | OptionDefinition currentDefinition; 202 | for (int i = 1; i < argumentCount; i++) { 203 | QString arg = QString::fromLocal8Bit(argumentStrings[i]); 204 | if (optionsAllowed) { 205 | if (arg == QLatin1String("--")) { 206 | optionsAllowed = false; 207 | continue; 208 | } 209 | if (arg.startsWith(QLatin1String("--"))) { 210 | processor.next(option); 211 | int end = arg.indexOf(QLatin1Char('=')); 212 | option.option = arg.mid(2, end - 2); 213 | if (end > 0) 214 | option.parameters << arg.mid(end+1); 215 | continue; 216 | } 217 | if (arg[0].unicode() == '-' && arg.length() > 1) { 218 | for (int x = 1; x < arg.length(); x++) { 219 | bool resolved = false; 220 | foreach (OptionDefinition definition, definitions) { 221 | if (definition.shortName == arg[x]) { 222 | resolved = true; 223 | processor.next(option); 224 | currentDefinition = definition; 225 | option.option = definition.name; 226 | 227 | if (definition.requiredParameters == 1 && arg.length() >= x+2) { 228 | option.parameters << arg.mid(x+1, arg.length()); 229 | x = arg.length(); 230 | } 231 | break; 232 | } 233 | } 234 | if (!resolved) { // nothing found; copy char so it ends up in unrecognized 235 | option.option = arg[x]; 236 | processor.next(option); 237 | } 238 | } 239 | continue; 240 | } 241 | } 242 | if (! option.option.isEmpty()) { 243 | if (currentDefinition.name != option.option) { 244 | // find the definition to match. 245 | foreach (OptionDefinition definition, definitions) { 246 | if (definition.name == option.option) { 247 | currentDefinition = definition; 248 | break; 249 | } 250 | } 251 | } 252 | if (currentDefinition.requiredParameters + currentDefinition.optionalParameters <= option.parameters.count()) 253 | processor.next(option); 254 | } 255 | if (option.option.isEmpty()) 256 | arguments << arg; 257 | else 258 | option.parameters << arg; 259 | } 260 | processor.next(option); 261 | 262 | if (requiredArguments > arguments.count()) 263 | errors.append(QLatin1String("Not enough arguments, usage: ") + QString::fromLocal8Bit(argumentStrings[0]) 264 | + QLatin1Char(' ') + argumentDefinition); 265 | 266 | /* 267 | foreach (QString key, options.keys()) { 268 | ParsedOption p = options[key]; 269 | qDebug() << "-> " << p.option; 270 | foreach (QString v, p.parameters) 271 | qDebug() << " +" << v; 272 | } 273 | qDebug() << "---"; 274 | foreach (QString arg, arguments) { 275 | qDebug() << arg; 276 | } 277 | */ 278 | } 279 | 280 | // ----------------------------------- 281 | 282 | 283 | // static 284 | void CommandLineParser::init(int argc, char **argv) 285 | { 286 | if (self) 287 | delete self; 288 | self = new CommandLineParser(argc, argv); 289 | } 290 | 291 | // static 292 | void CommandLineParser::addOptionDefinitions(const CommandLineOption * optionList) 293 | { 294 | if (!self) { 295 | qWarning() << "WARN: CommandLineParser:: Use init before addOptionDefinitions!"; 296 | return; 297 | } 298 | self->d->addDefinitions(optionList); 299 | } 300 | 301 | // static 302 | CommandLineParser *CommandLineParser::instance() 303 | { 304 | return self; 305 | } 306 | 307 | // static 308 | void CommandLineParser::setArgumentDefinition(const char *definition) 309 | { 310 | if (!self) { 311 | qWarning() << "WARN: CommandLineParser:: Use init before addOptionDefinitions!"; 312 | return; 313 | } 314 | self->d->setArgumentDefinition(definition); 315 | } 316 | 317 | 318 | CommandLineParser::CommandLineParser(int argc, char **argv) 319 | : d(new Private(argc, argv)) 320 | { 321 | } 322 | 323 | CommandLineParser::~CommandLineParser() 324 | { 325 | delete d; 326 | } 327 | 328 | void CommandLineParser::usage(const QString &name, const QString &argumentDescription) 329 | { 330 | #if QT_VERSION >= 0x060000 331 | QTextStream cout(stdout, QIODeviceBase::WriteOnly); 332 | #else 333 | QTextStream cout(stdout, QIODevice::WriteOnly); 334 | #endif 335 | cout << "Usage: " << d->argumentStrings[0]; 336 | if (! name.isEmpty()) 337 | cout << " " << name; 338 | if (d->definitions.count()) 339 | cout << " [OPTION]"; 340 | if (! argumentDescription.isEmpty()) 341 | cout << " " << argumentDescription; 342 | cout << Qt::endl << Qt::endl; 343 | 344 | if (d->definitions.count() > 0) 345 | cout << "Options:" << Qt::endl; 346 | int commandLength = 0; 347 | foreach (Private::OptionDefinition definition, d->definitions) 348 | commandLength = qMax(definition.name.length(), commandLength); 349 | 350 | foreach (Private::OptionDefinition definition, d->definitions) { 351 | cout << " "; 352 | if (definition.shortName == 0) 353 | cout << " --"; 354 | else 355 | cout << "-" << definition.shortName << " --"; 356 | cout << definition.name; 357 | for (int i = definition.name.length(); i <= commandLength; i++) 358 | cout << ' '; 359 | cout << definition.comment << Qt::endl; 360 | } 361 | } 362 | 363 | QStringList CommandLineParser::options() const 364 | { 365 | d->parse(); 366 | return d->options.keys(); 367 | } 368 | 369 | bool CommandLineParser::contains(const QString & key) const 370 | { 371 | d->parse(); 372 | return d->options.contains(key); 373 | } 374 | 375 | QStringList CommandLineParser::arguments() const 376 | { 377 | d->parse(); 378 | return d->arguments; 379 | } 380 | 381 | QStringList CommandLineParser::undefinedOptions() const 382 | { 383 | d->parse(); 384 | return d->undefinedOptions; 385 | } 386 | 387 | QString CommandLineParser::optionArgument(const QString &optionName, const QString &defaultValue) const 388 | { 389 | QStringList answer = optionArguments(optionName); 390 | if (answer.isEmpty()) 391 | return defaultValue; 392 | return answer.first(); 393 | } 394 | 395 | QStringList CommandLineParser::optionArguments(const QString &optionName) const 396 | { 397 | if (! contains(optionName)) 398 | return QStringList(); 399 | Private::ParsedOption po = d->options[optionName]; 400 | return po.parameters; 401 | } 402 | 403 | QStringList CommandLineParser::parseErrors() const 404 | { 405 | d->parse(); 406 | return d->errors; 407 | } 408 | -------------------------------------------------------------------------------- /src/CommandLineParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the vng project 3 | * Copyright (C) 2008 Thomas Zander 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef COMMANDLINEPARSER_H 20 | #define COMMANDLINEPARSER_H 21 | 22 | #include 23 | 24 | struct CommandLineOption { 25 | /** 26 | * The specification of an option includes the name of the option the user must pass and optional arguments it has. 27 | * Example specifications are; 28 | *
    29 | *
  1. "-a, --all"
  2. 30 | *
  3. "--version"
  4. 31 | *
  5. "--type name"
  6. 32 | *
  7. "--list item[,item]"
  8. 33 | *
  9. "-f, --format name [suffix] [foo]"
34 | * Number 1 allows the user to either type -a or --all (or /A on Windows) to activate this option. 35 | * Number 2 allows the user to type --version to activate this option. 36 | * Number 3 requires the user to type a single argument after the option. 37 | * Number 4 allows the user to use an option that takes a required argument and one or more optional ones 38 | * Number 5 Allows the user to either use -f or --format, which is followed by one required argument 39 | * and optionally 2 more arguments. 40 | */ 41 | const char *specification; 42 | /** 43 | * A textual description of the option that will be printed when the user asks for help. 44 | */ 45 | const char *description; 46 | }; 47 | 48 | #define CommandLineLastOption { 0, 0 } 49 | 50 | /** 51 | * The CommandLineParser singleton 52 | */ 53 | class CommandLineParser 54 | { 55 | public: 56 | static void init(int argc, char *argv[]); 57 | static void addOptionDefinitions(const CommandLineOption *definitions); 58 | static void setArgumentDefinition(const char *definition); 59 | static CommandLineParser *instance(); 60 | 61 | ~CommandLineParser(); 62 | 63 | void usage(const QString &name, const QString &argumentDescription = QString()); 64 | 65 | /// return the options that the user passed 66 | QStringList options() const; 67 | /** 68 | * returns true if the option was found. 69 | * Consider the following definition "--expert level" The user can type as an argument 70 | * "--expert 10". Calling contains("expert") will return true. 71 | * @see optionArgument() 72 | */ 73 | bool contains(const QString & key) const; 74 | 75 | /// returns the list of items that are not options, note that the first one is the name of the command called 76 | QStringList arguments() const; 77 | 78 | /// return the list of options that the user passed but we don't have a definition for. 79 | QStringList undefinedOptions() const; 80 | 81 | /** 82 | * Return the argument passed to an option. 83 | * Consider the following definition "--expert level" The user can type as an argument 84 | * "--expert 10". Calling optionArgument("expert") will return a string "10" 85 | * @see contains() 86 | */ 87 | QString optionArgument(const QString &optionName, const QString &defaultValue = QString()) const; 88 | QStringList optionArguments(const QString &optionName) const; 89 | 90 | QStringList parseErrors() const; 91 | 92 | private: 93 | CommandLineParser(int argc, char **argv); 94 | class Private; 95 | Private * const d; 96 | static CommandLineParser *self; 97 | }; 98 | 99 | #endif 100 | 101 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 Thiago Macieira 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include "CommandLineParser.h" 28 | #include "ruleparser.h" 29 | #include "repository.h" 30 | #include "svn.h" 31 | 32 | QHash loadIdentityMapFile(const QString &fileName) 33 | { 34 | QHash result; 35 | if (fileName.isEmpty()) 36 | return result; 37 | 38 | QFile file(fileName); 39 | if (!file.open(QIODevice::ReadOnly)) { 40 | fprintf(stderr, "Could not open file %s: %s", 41 | qPrintable(fileName), qPrintable(file.errorString())); 42 | return result; 43 | } 44 | 45 | bool found_author; 46 | while (!file.atEnd()) { 47 | QByteArray line = file.readLine(); 48 | int comment_pos = line.indexOf('#'); 49 | if (comment_pos != -1) 50 | line.truncate(comment_pos); 51 | line = line.trimmed(); 52 | int space = line.indexOf(' '); 53 | if (space == -1) 54 | continue; // invalid line 55 | 56 | // Support git-svn author files, too 57 | // - svn2git native: loginname Joe User 58 | // - git-svn: loginname = Joe User 59 | int rightspace = line.indexOf(" = "); 60 | int leftspace = space; 61 | if (rightspace == -1) { 62 | rightspace = space; 63 | } else { 64 | leftspace = rightspace; 65 | rightspace += 2; 66 | } 67 | 68 | QByteArray realname = line.mid(rightspace).trimmed(); 69 | line.truncate(leftspace); 70 | 71 | result.insert(line, realname); 72 | found_author = true; 73 | }; 74 | file.close(); 75 | 76 | if(!found_author) { 77 | fprintf(stderr, "No authors found in identity-map file. Check supported formats.\n"); 78 | } 79 | return result; 80 | } 81 | 82 | QSet loadRevisionsFile( const QString &fileName, Svn &svn ) 83 | { 84 | QRegExp revint("(\\d+)\\s*(?:-\\s*(\\d+|HEAD))?"); 85 | QSet revisions; 86 | if(fileName.isEmpty()) 87 | return revisions; 88 | 89 | QFile file(fileName); 90 | if( !file.open(QIODevice::ReadOnly)) { 91 | fprintf(stderr, "Could not open file %s: %s\n", qPrintable(fileName), qPrintable(file.errorString())); 92 | return revisions; 93 | } 94 | 95 | bool ok; 96 | while(!file.atEnd()) { 97 | QByteArray line = file.readLine().trimmed(); 98 | revint.indexIn(line); 99 | if( revint.cap(2).isEmpty() ) { 100 | int rev = revint.cap(1).toInt(&ok); 101 | if(ok) { 102 | revisions.insert(rev); 103 | } else { 104 | fprintf(stderr, "Unable to convert %s to int, skipping revision.\n", qPrintable(QString(line))); 105 | } 106 | } else if( revint.captureCount() == 2 ) { 107 | int rev = revint.cap(1).toInt(&ok); 108 | if(!ok) { 109 | fprintf(stderr, "Unable to convert %s (%s) to int, skipping revisions.\n", qPrintable(revint.cap(1)), qPrintable(QString(line))); 110 | continue; 111 | } 112 | int lastrev = 0; 113 | if(revint.cap(2) == "HEAD") { 114 | lastrev = svn.youngestRevision(); 115 | ok = true; 116 | } else { 117 | lastrev = revint.cap(2).toInt(&ok); 118 | } 119 | if(!ok) { 120 | fprintf(stderr, "Unable to convert %s (%s) to int, skipping revisions.\n", qPrintable(revint.cap(2)), qPrintable(QString(line))); 121 | continue; 122 | } 123 | for(; rev <= lastrev; ++rev ) 124 | revisions.insert(rev); 125 | } else { 126 | fprintf(stderr, "Unable to convert %s to int, skipping revision.\n", qPrintable(QString(line))); 127 | } 128 | } 129 | file.close(); 130 | return revisions; 131 | } 132 | 133 | static const CommandLineOption options[] = { 134 | {"--identity-map FILENAME", "provide map between svn username and email"}, 135 | {"--identity-domain DOMAIN", "provide user domain if no map was given"}, 136 | {"--revisions-file FILENAME", "provide a file with revision number that should be processed"}, 137 | {"--rules FILENAME[,FILENAME]", "the rules file(s) that determines what goes where"}, 138 | {"--msg-filter FILENAME", "External program / script to modify svn log message"}, 139 | {"--add-metadata", "if passed, each git commit will have svn commit info"}, 140 | {"--add-metadata-notes", "if passed, each git commit will have notes with svn commit info"}, 141 | {"--resume-from revision", "start importing at svn revision number"}, 142 | {"--max-rev revision", "stop importing at svn revision number"}, 143 | {"--dry-run", "don't actually write anything"}, 144 | {"--create-dump", "don't create the repository but a dump file suitable for piping into fast-import"}, 145 | {"--debug-rules", "print what rule is being used for each file"}, 146 | {"--commit-interval NUMBER", "if passed the cache will be flushed to git every NUMBER of commits"}, 147 | {"--stats", "after a run print some statistics about the rules"}, 148 | {"--svn-branches", "Use the contents of SVN when creating branches, Note: SVN tags are branches as well"}, 149 | {"--empty-dirs", "Add .gitignore-file for empty dirs"}, 150 | {"--svn-ignore", "Import svn-ignore-properties via .gitignore"}, 151 | {"--propcheck", "Check for svn-properties except svn-ignore"}, 152 | {"--fast-import-timeout SECONDS", "number of seconds to wait before terminating fast-import, 0 to wait forever"}, 153 | {"-h, --help", "show help"}, 154 | {"-v, --version", "show version"}, 155 | CommandLineLastOption 156 | }; 157 | 158 | int main(int argc, char **argv) 159 | { 160 | printf("Invoked as:'"); 161 | for(int i = 0; i < argc; ++i) 162 | printf(" %s", argv[i]); 163 | printf("'\n"); 164 | CommandLineParser::init(argc, argv); 165 | CommandLineParser::addOptionDefinitions(options); 166 | Stats::init(); 167 | CommandLineParser *args = CommandLineParser::instance(); 168 | if(args->contains(QLatin1String("version"))) { 169 | printf("Git version: %s\n", VER); 170 | return 0; 171 | } 172 | if (args->contains(QLatin1String("help"))) { 173 | args->usage(QString(), "--rules RULES_FILE SVN_REPO_DIR/"); 174 | return 0; 175 | } 176 | if (args->arguments().count() != 1) { 177 | args->usage(QString(), "--rules RULES_FILE SVN_REPO_DIR/"); 178 | return 12; 179 | } 180 | if (args->undefinedOptions().count()) { 181 | QTextStream out(stderr); 182 | out << "svn-all-fast-export failed: "; 183 | bool first = true; 184 | foreach (QString option, args->undefinedOptions()) { 185 | if (!first) 186 | out << " : "; 187 | out << "unrecognized option or missing argument for; `" << option << "'" << Qt::endl; 188 | first = false; 189 | } 190 | return 10; 191 | } 192 | if (!args->contains("rules")) { 193 | QTextStream out(stderr); 194 | out << "svn-all-fast-export failed: please specify the rules using the 'rules' argument\n"; 195 | return 11; 196 | } 197 | if (!args->contains("identity-map") && !args->contains("identity-domain")) { 198 | QTextStream out(stderr); 199 | out << "WARNING; no identity-map or -domain specified, all commits will use default @localhost email address\n\n"; 200 | } 201 | 202 | QCoreApplication app(argc, argv); 203 | // Load the configuration 204 | RulesList rulesList(args->optionArgument(QLatin1String("rules"))); 205 | rulesList.load(); 206 | 207 | int resume_from = args->optionArgument(QLatin1String("resume-from")).toInt(); 208 | int max_rev = args->optionArgument(QLatin1String("max-rev")).toInt(); 209 | 210 | // create the repository list 211 | QHash repositories; 212 | 213 | int cutoff = resume_from ? resume_from : INT_MAX; 214 | retry: 215 | int min_rev = 1; 216 | foreach (Rules::Repository rule, rulesList.allRepositories()) { 217 | Repository *repo = createRepository(rule, repositories); 218 | if (!repo) 219 | return EXIT_FAILURE; 220 | repositories.insert(rule.name, repo); 221 | 222 | int repo_next = repo->setupIncremental(cutoff); 223 | repo->restoreAnnotatedTags(); 224 | repo->restoreBranchNotes(); 225 | 226 | /* 227 | * cutoff < resume_from => error exit eventually 228 | * repo_next == cutoff => probably truncated log 229 | */ 230 | if (cutoff < resume_from && repo_next == cutoff) 231 | /* 232 | * Restore the log file so we fail the next time 233 | * svn2git is invoked with the same arguments 234 | */ 235 | repo->restoreLog(); 236 | 237 | if (cutoff < min_rev) 238 | /* 239 | * We've rewound before the last revision of some 240 | * repository that we've already seen. Start over 241 | * from the beginning. (since cutoff is decreasing, 242 | * we're sure we'll make forward progress eventually) 243 | */ 244 | goto retry; 245 | 246 | if (min_rev < repo_next) 247 | min_rev = repo_next; 248 | } 249 | 250 | if (cutoff < resume_from) { 251 | qCritical() << "Cannot resume from" << resume_from 252 | << "as there are errors in revision" << cutoff; 253 | return EXIT_FAILURE; 254 | } 255 | 256 | if (min_rev < resume_from) 257 | qDebug() << "skipping revisions" << min_rev << "to" << resume_from - 1 << "as requested"; 258 | 259 | if (resume_from) 260 | min_rev = resume_from; 261 | 262 | Svn::initialize(); 263 | Svn svn(args->arguments().first()); 264 | svn.setMatchRules(rulesList.allMatchRules()); 265 | svn.setRepositories(repositories); 266 | svn.setIdentityMap(loadIdentityMapFile(args->optionArgument("identity-map"))); 267 | // Massage user input a little, no guarantees that input makes sense. 268 | QString domain = args->optionArgument("identity-domain").simplified().remove(QChar('@')); 269 | if (domain.isEmpty()) 270 | domain = QString("localhost"); 271 | svn.setIdentityDomain(domain); 272 | 273 | if (max_rev < 1) 274 | max_rev = svn.youngestRevision(); 275 | 276 | bool errors = false; 277 | QSet revisions = loadRevisionsFile(args->optionArgument(QLatin1String("revisions-file")), svn); 278 | const bool filerRevisions = !revisions.isEmpty(); 279 | for (int i = min_rev; i <= max_rev; ++i) { 280 | if(filerRevisions) { 281 | if( !revisions.contains(i) ) { 282 | printf("."); 283 | continue; 284 | } else { 285 | printf("\n"); 286 | } 287 | } 288 | if (!svn.exportRevision(i)) { 289 | errors = true; 290 | break; 291 | } 292 | } 293 | 294 | foreach (Repository *repo, repositories) { 295 | repo->finalizeTags(); 296 | repo->saveBranchNotes(); 297 | delete repo; 298 | } 299 | Stats::instance()->printStats(); 300 | return errors ? EXIT_FAILURE : EXIT_SUCCESS; 301 | } 302 | -------------------------------------------------------------------------------- /src/repository.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 Thiago Macieira 3 | * Copyright (C) 2009 Thomas Zander 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "repository.h" 20 | #include "CommandLineParser.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | static const int maxSimultaneousProcesses = 100; 29 | 30 | typedef unsigned long long mark_t; 31 | static const mark_t maxMark = ULONG_MAX; 32 | 33 | class FastImportRepository : public Repository 34 | { 35 | public: 36 | struct AnnotatedTag 37 | { 38 | QString supportingRef; 39 | QByteArray svnprefix; 40 | QByteArray author; 41 | QByteArray log; 42 | uint dt; 43 | int revnum; 44 | }; 45 | class Transaction : public Repository::Transaction 46 | { 47 | Q_DISABLE_COPY(Transaction) 48 | friend class FastImportRepository; 49 | 50 | FastImportRepository *repository; 51 | QByteArray branch; 52 | QByteArray svnprefix; 53 | QByteArray author; 54 | QByteArray log; 55 | uint datetime; 56 | int revnum; 57 | 58 | QVector merges; 59 | 60 | QStringList deletedFiles; 61 | QByteArray modifiedFiles; 62 | 63 | inline Transaction() {} 64 | public: 65 | ~Transaction(); 66 | int commit(); 67 | 68 | void setAuthor(const QByteArray &author); 69 | void setDateTime(uint dt); 70 | void setLog(const QByteArray &log); 71 | 72 | void noteCopyFromBranch (const QString &prevbranch, int revFrom); 73 | 74 | void deleteFile(const QString &path); 75 | QIODevice *addFile(const QString &path, int mode, qint64 length); 76 | 77 | bool commitNote(const QByteArray ¬eText, bool append, 78 | const QByteArray &commit = QByteArray()); 79 | }; 80 | FastImportRepository(const Rules::Repository &rule); 81 | int setupIncremental(int &cutoff); 82 | void restoreAnnotatedTags(); 83 | void restoreBranchNotes(); 84 | void restoreLog(); 85 | ~FastImportRepository(); 86 | 87 | void reloadBranches(); 88 | int createBranch(const QString &branch, int revnum, 89 | const QString &branchFrom, int revFrom); 90 | int deleteBranch(const QString &branch, int revnum); 91 | Repository::Transaction *newTransaction(const QString &branch, const QString &svnprefix, int revnum); 92 | 93 | void createAnnotatedTag(const QString &name, const QString &svnprefix, int revnum, 94 | const QByteArray &author, uint dt, 95 | const QByteArray &log); 96 | void finalizeTags(); 97 | void saveBranchNotes(); 98 | void commit(); 99 | 100 | bool branchExists(const QString& branch) const; 101 | const QByteArray branchNote(const QString& branch) const; 102 | void setBranchNote(const QString& branch, const QByteArray& noteText); 103 | 104 | bool hasPrefix() const; 105 | 106 | QString getName() const; 107 | Repository *getEffectiveRepository(); 108 | private: 109 | struct Branch 110 | { 111 | int created; 112 | QVector commits; 113 | QVector marks; 114 | }; 115 | 116 | QString defaultBranch; 117 | QHash branches; 118 | QHash branchNotes; 119 | QHash annotatedTags; 120 | QString name; 121 | QString prefix; 122 | LoggingQProcess fastImport; 123 | int commitCount; 124 | int outstandingTransactions; 125 | QByteArray deletedBranches; 126 | QByteArray resetBranches; 127 | QSet deletedBranchNames; 128 | QSet resetBranchNames; 129 | 130 | /* Optional filter to fix up log messages */ 131 | QProcess filterMsg; 132 | QByteArray msgFilter(QByteArray); 133 | 134 | /* starts at 0, and counts up. */ 135 | mark_t last_commit_mark; 136 | 137 | /* starts at maxMark - 1 and counts down. Reset after each SVN revision */ 138 | mark_t next_file_mark; 139 | 140 | bool processHasStarted; 141 | 142 | void startFastImport(); 143 | void closeFastImport(); 144 | 145 | // called when a transaction is deleted 146 | void forgetTransaction(Transaction *t); 147 | 148 | int resetBranch(const QString &branch, int revnum, mark_t mark, const QByteArray &resetTo, const QByteArray &comment); 149 | long long markFrom(const QString &branchFrom, int branchRevNum, QByteArray &desc); 150 | 151 | friend class ProcessCache; 152 | Q_DISABLE_COPY(FastImportRepository) 153 | }; 154 | 155 | class ForwardingRepository : public Repository 156 | { 157 | QString name; 158 | Repository *repo; 159 | QString prefix; 160 | public: 161 | class Transaction : public Repository::Transaction 162 | { 163 | Q_DISABLE_COPY(Transaction) 164 | 165 | Repository::Transaction *txn; 166 | QString prefix; 167 | public: 168 | Transaction(Repository::Transaction *t, const QString &p) : txn(t), prefix(p) {} 169 | ~Transaction() { delete txn; } 170 | int commit() { return txn->commit(); } 171 | 172 | void setAuthor(const QByteArray &author) { txn->setAuthor(author); } 173 | void setDateTime(uint dt) { txn->setDateTime(dt); } 174 | void setLog(const QByteArray &log) { txn->setLog(log); } 175 | 176 | void noteCopyFromBranch (const QString &prevbranch, int revFrom) 177 | { txn->noteCopyFromBranch(prevbranch, revFrom); } 178 | 179 | void deleteFile(const QString &path) { txn->deleteFile(prefix + path); } 180 | QIODevice *addFile(const QString &path, int mode, qint64 length) 181 | { return txn->addFile(prefix + path, mode, length); } 182 | 183 | bool commitNote(const QByteArray ¬eText, bool append, 184 | const QByteArray &commit) 185 | { return txn->commitNote(noteText, append, commit); } 186 | }; 187 | 188 | ForwardingRepository(const QString &n, Repository *r, const QString &p) : name(n), repo(r), prefix(p) {} 189 | 190 | int setupIncremental(int &) { return 1; } 191 | void restoreAnnotatedTags() {} 192 | void restoreBranchNotes() {} 193 | void restoreLog() {} 194 | 195 | void reloadBranches() { return repo->reloadBranches(); } 196 | int createBranch(const QString &branch, int revnum, 197 | const QString &branchFrom, int revFrom) 198 | { return repo->createBranch(branch, revnum, branchFrom, revFrom); } 199 | 200 | int deleteBranch(const QString &branch, int revnum) 201 | { return repo->deleteBranch(branch, revnum); } 202 | 203 | Repository::Transaction *newTransaction(const QString &branch, const QString &svnprefix, int revnum) 204 | { 205 | Repository::Transaction *t = repo->newTransaction(branch, svnprefix, revnum); 206 | return new Transaction(t, prefix); 207 | } 208 | 209 | void createAnnotatedTag(const QString &name, const QString &svnprefix, int revnum, 210 | const QByteArray &author, uint dt, 211 | const QByteArray &log) 212 | { repo->createAnnotatedTag(name, svnprefix, revnum, author, dt, log); } 213 | void finalizeTags() { /* loop that called this will invoke it on 'repo' too */ } 214 | void saveBranchNotes() { /* loop that called this will invoke it on 'repo' too */ } 215 | void commit() { repo->commit(); } 216 | 217 | bool branchExists(const QString& branch) const 218 | { return repo->branchExists(branch); } 219 | const QByteArray branchNote(const QString& branch) const 220 | { return repo->branchNote(branch); } 221 | void setBranchNote(const QString& branch, const QByteArray& noteText) 222 | { repo->setBranchNote(branch, noteText); } 223 | 224 | bool hasPrefix() const 225 | { return !prefix.isEmpty() || repo->hasPrefix(); } 226 | 227 | QString getName() const 228 | { return name; } 229 | Repository *getEffectiveRepository() 230 | { return repo->getEffectiveRepository(); } 231 | }; 232 | 233 | class ProcessCache: QLinkedList 234 | { 235 | public: 236 | void touch(FastImportRepository *repo) 237 | { 238 | remove(repo); 239 | 240 | // if the cache is too big, remove from the front 241 | while (size() >= maxSimultaneousProcesses) 242 | takeFirst()->closeFastImport(); 243 | 244 | // append to the end 245 | append(repo); 246 | } 247 | 248 | inline void remove(FastImportRepository *repo) 249 | { 250 | #if QT_VERSION >= 0x040400 251 | removeOne(repo); 252 | #else 253 | removeAll(repo); 254 | #endif 255 | } 256 | }; 257 | static ProcessCache processCache; 258 | 259 | QDataStream &operator<<(QDataStream &out, const FastImportRepository::AnnotatedTag &annotatedTag) 260 | { 261 | out << annotatedTag.supportingRef 262 | << annotatedTag.svnprefix 263 | << annotatedTag.author 264 | << annotatedTag.log 265 | << (quint64) annotatedTag.dt 266 | << (qint64) annotatedTag.revnum; 267 | return out; 268 | } 269 | 270 | QDataStream &operator>>(QDataStream &in, FastImportRepository::AnnotatedTag &annotatedTag) 271 | { 272 | quint64 dt; 273 | qint64 revnum; 274 | 275 | in >> annotatedTag.supportingRef 276 | >> annotatedTag.svnprefix 277 | >> annotatedTag.author 278 | >> annotatedTag.log 279 | >> dt 280 | >> revnum; 281 | annotatedTag.dt = (uint) dt; 282 | annotatedTag.revnum = (int) revnum; 283 | return in; 284 | } 285 | 286 | Repository *createRepository(const Rules::Repository &rule, const QHash &repositories) 287 | { 288 | if (rule.forwardTo.isEmpty()) 289 | return new FastImportRepository(rule); 290 | Repository *r = repositories[rule.forwardTo]; 291 | if (!r) { 292 | qCritical() << "no repository with name" << rule.forwardTo << "found at" << rule.info(); 293 | return r; 294 | } 295 | return new ForwardingRepository(rule.name, r, rule.prefix); 296 | } 297 | 298 | static QString marksFileName(QString name) 299 | { 300 | name.replace('/', '_'); 301 | name.prepend("marks-"); 302 | return name; 303 | } 304 | 305 | static QString annotatedTagsFileName(QString name) 306 | { 307 | name.replace('/', '_'); 308 | name.prepend("annotatedTags-"); 309 | return name; 310 | } 311 | 312 | static QString branchNotesFileName(QString name) 313 | { 314 | name.replace('/', '_'); 315 | name.prepend("branchNotes-"); 316 | return name; 317 | } 318 | 319 | FastImportRepository::FastImportRepository(const Rules::Repository &rule) 320 | : name(rule.name), prefix(rule.forwardTo), fastImport(name), commitCount(0), outstandingTransactions(0), 321 | last_commit_mark(0), next_file_mark(maxMark - 1), processHasStarted(false) 322 | { 323 | foreach (Rules::Repository::Branch branchRule, rule.branches) { 324 | Branch branch; 325 | branch.created = 1; 326 | 327 | branches.insert(branchRule.name, branch); 328 | } 329 | 330 | // create the defaultBranch from the config 331 | QProcess config; 332 | config.start("git", QStringList() << "config" << "init.defaultBranch"); 333 | config.waitForFinished(-1); 334 | defaultBranch = QString(config.readAllStandardOutput()).trimmed(); 335 | 336 | // Create the default branch 337 | if (defaultBranch.isEmpty()) { 338 | defaultBranch = "master"; 339 | } 340 | 341 | branches[defaultBranch].created = 1; 342 | 343 | if (!CommandLineParser::instance()->contains("dry-run") && !CommandLineParser::instance()->contains("create-dump")) { 344 | fastImport.setWorkingDirectory(name); 345 | if (!QDir(name).exists()) { // repo doesn't exist yet. 346 | qDebug() << "Creating new repository" << name; 347 | QDir::current().mkpath(name); 348 | QProcess init; 349 | init.setWorkingDirectory(name); 350 | init.start("git", QStringList() << "--bare" << "init"); 351 | init.waitForFinished(-1); 352 | QProcess casesensitive; 353 | casesensitive.setWorkingDirectory(name); 354 | casesensitive.start("git", QStringList() << "config" << "core.ignorecase" << "false"); 355 | casesensitive.waitForFinished(-1); 356 | // Write description 357 | if (!rule.description.isEmpty()) { 358 | QFile fDesc(QDir(name).filePath("description")); 359 | if (fDesc.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { 360 | fDesc.write(rule.description.toUtf8()); 361 | fDesc.putChar('\n'); 362 | fDesc.close(); 363 | } 364 | } 365 | { 366 | QFile marks(name + "/" + marksFileName(name)); 367 | marks.open(QIODevice::WriteOnly); 368 | marks.close(); 369 | } 370 | } 371 | } 372 | } 373 | 374 | static QString logFileName(QString name) 375 | { 376 | name.replace('/', '_'); 377 | if (CommandLineParser::instance()->contains("create-dump")) 378 | name.append(".fi"); 379 | else 380 | name.prepend("log-"); 381 | return name; 382 | } 383 | 384 | static mark_t lastValidMark(QString name) 385 | { 386 | QFile marksfile(name + "/" + marksFileName(name)); 387 | if (!marksfile.open(QIODevice::ReadOnly)) 388 | return 0; 389 | 390 | qDebug() << "marksfile " << marksfile.fileName() ; 391 | mark_t prev_mark = 0; 392 | 393 | int lineno = 0; 394 | while (!marksfile.atEnd()) { 395 | QString line = marksfile.readLine(); 396 | ++lineno; 397 | if (line.isEmpty()) 398 | continue; 399 | 400 | mark_t mark = 0; 401 | if (line[0] == ':') { 402 | int sp = line.indexOf(' '); 403 | if (sp != -1) { 404 | QString m = line.mid(1, sp-1); 405 | mark = m.toULongLong(); 406 | } 407 | } 408 | 409 | if (!mark) { 410 | qCritical() << marksfile.fileName() << "line" << lineno << "marks file corrupt?" << "mark " << mark; 411 | return 0; 412 | } 413 | 414 | if (mark == prev_mark) { 415 | qCritical() << marksfile.fileName() << "line" << lineno << "marks file has duplicates"; 416 | return 0; 417 | } 418 | 419 | if (mark < prev_mark) { 420 | qCritical() << marksfile.fileName() << "line" << lineno << "marks file not sorted"; 421 | return 0; 422 | } 423 | 424 | if (mark > prev_mark + 1) 425 | break; 426 | 427 | prev_mark = mark; 428 | } 429 | 430 | return prev_mark; 431 | } 432 | 433 | int FastImportRepository::setupIncremental(int &cutoff) 434 | { 435 | QFile logfile(logFileName(name)); 436 | if (!logfile.exists()) 437 | return 1; 438 | 439 | logfile.open(QIODevice::ReadWrite); 440 | 441 | QRegExp progress("progress SVN r(\\d+) branch (.*) = :(\\d+)"); 442 | 443 | mark_t last_valid_mark = lastValidMark(name); 444 | 445 | int last_revnum = 0; 446 | qint64 pos = 0; 447 | int retval = 0; 448 | QString bkup = logfile.fileName() + ".old"; 449 | 450 | while (!logfile.atEnd()) { 451 | pos = logfile.pos(); 452 | QByteArray line = logfile.readLine(); 453 | int hash = line.indexOf('#'); 454 | if (hash != -1) 455 | line.truncate(hash); 456 | line = line.trimmed(); 457 | if (line.isEmpty()) 458 | continue; 459 | if (!progress.exactMatch(line)) 460 | continue; 461 | 462 | int revnum = progress.cap(1).toInt(); 463 | QString branch = progress.cap(2); 464 | mark_t mark = progress.cap(3).toULongLong(); 465 | 466 | if (revnum >= cutoff) 467 | goto beyond_cutoff; 468 | 469 | if (revnum < last_revnum) 470 | qWarning() << "WARN:" << name << "revision numbers are not monotonic: " 471 | << "got" << QString::number(last_revnum) 472 | << "and then" << QString::number(revnum); 473 | 474 | if (mark > last_valid_mark) { 475 | qWarning() << "WARN:" << name << "unknown commit mark found: rewinding -- did you hit Ctrl-C?"; 476 | cutoff = revnum; 477 | goto beyond_cutoff; 478 | } 479 | 480 | last_revnum = revnum; 481 | 482 | if (last_commit_mark < mark) 483 | last_commit_mark = mark; 484 | 485 | Branch &br = branches[branch]; 486 | if (!br.created || !mark || br.marks.isEmpty() || !br.marks.last()) 487 | br.created = revnum; 488 | br.commits.append(revnum); 489 | br.marks.append(mark); 490 | } 491 | 492 | retval = last_revnum + 1; 493 | if (retval == cutoff) 494 | /* 495 | * If a stale backup file exists already, remove it, so that 496 | * we don't confuse ourselves in 'restoreLog()' 497 | */ 498 | QFile::remove(bkup); 499 | 500 | return retval; 501 | 502 | beyond_cutoff: 503 | // backup file, since we'll truncate 504 | QFile::remove(bkup); 505 | logfile.copy(bkup); 506 | 507 | // truncate, so that we ignore the rest of the revisions 508 | qDebug() << name << "truncating history to revision" << cutoff; 509 | logfile.resize(pos); 510 | return cutoff; 511 | } 512 | 513 | void FastImportRepository::restoreAnnotatedTags() 514 | { 515 | QFile annotatedTagsFile(name + "/" + annotatedTagsFileName(name)); 516 | if (!annotatedTagsFile.exists()) 517 | return; 518 | annotatedTagsFile.open(QIODevice::ReadOnly); 519 | QDataStream annotatedTagsStream(&annotatedTagsFile); 520 | annotatedTagsStream >> annotatedTags; 521 | annotatedTagsFile.close(); 522 | } 523 | 524 | void FastImportRepository::restoreBranchNotes() 525 | { 526 | QFile branchNotesFile(name + "/" + branchNotesFileName(name)); 527 | if (!branchNotesFile.exists()) 528 | return; 529 | branchNotesFile.open(QIODevice::ReadOnly); 530 | QDataStream branchNotesStream(&branchNotesFile); 531 | branchNotesStream >> branchNotes; 532 | branchNotesFile.close(); 533 | } 534 | 535 | void FastImportRepository::restoreLog() 536 | { 537 | QString file = logFileName(name); 538 | QString bkup = file + ".old"; 539 | if (!QFile::exists(bkup)) 540 | return; 541 | QFile::remove(file); 542 | QFile::rename(bkup, file); 543 | } 544 | 545 | FastImportRepository::~FastImportRepository() 546 | { 547 | Q_ASSERT(outstandingTransactions == 0); 548 | closeFastImport(); 549 | } 550 | 551 | void FastImportRepository::closeFastImport() 552 | { 553 | if (fastImport.state() != QProcess::NotRunning) { 554 | int fastImportTimeout = CommandLineParser::instance()->optionArgument(QLatin1String("fast-import-timeout"), QLatin1String("30")).toInt(); 555 | if(fastImportTimeout == 0) { 556 | qDebug() << "Waiting forever for fast-import to finish."; 557 | fastImportTimeout = -1; 558 | } else { 559 | qDebug() << "Waiting" << fastImportTimeout << "seconds for fast-import to finish."; 560 | fastImportTimeout *= 10000; 561 | } 562 | fastImport.write("checkpoint\n"); 563 | fastImport.waitForBytesWritten(-1); 564 | fastImport.closeWriteChannel(); 565 | if (!fastImport.waitForFinished(fastImportTimeout)) { 566 | fastImport.terminate(); 567 | if (!fastImport.waitForFinished(200)) 568 | qWarning() << "WARN: git-fast-import for repository" << name << "did not die"; 569 | } 570 | } 571 | processHasStarted = false; 572 | processCache.remove(this); 573 | } 574 | 575 | void FastImportRepository::reloadBranches() 576 | { 577 | bool reset_notes = false; 578 | foreach (QString branch, branches.keys()) { 579 | Branch &br = branches[branch]; 580 | 581 | if (br.marks.isEmpty() || !br.marks.last()) 582 | continue; 583 | 584 | reset_notes = true; 585 | 586 | QByteArray branchRef = branch.toUtf8(); 587 | if (!branchRef.startsWith("refs/")) 588 | branchRef.prepend("refs/heads/"); 589 | 590 | startFastImport(); 591 | fastImport.write("reset " + branchRef + 592 | "\nfrom :" + QByteArray::number(br.marks.last()) + "\n\n" 593 | "progress Branch " + branchRef + " reloaded\n"); 594 | } 595 | 596 | if (reset_notes && 597 | CommandLineParser::instance()->contains("add-metadata-notes")) { 598 | 599 | startFastImport(); 600 | fastImport.write("reset refs/notes/commits\nfrom :" + 601 | QByteArray::number(maxMark) + 602 | "\n"); 603 | } 604 | } 605 | 606 | long long FastImportRepository::markFrom(const QString &branchFrom, int branchRevNum, QByteArray &branchFromDesc) 607 | { 608 | Branch &brFrom = branches[branchFrom]; 609 | if (!brFrom.created) 610 | return -1; 611 | 612 | if (brFrom.commits.isEmpty()) { 613 | return -1; 614 | } 615 | if (branchRevNum == brFrom.commits.last()) { 616 | return brFrom.marks.last(); 617 | } 618 | 619 | QVector::const_iterator it = std::upper_bound(brFrom.commits.constBegin(), brFrom.commits.constEnd(), branchRevNum); 620 | if (it == brFrom.commits.begin()) { 621 | return 0; 622 | } 623 | 624 | int closestCommit = *--it; 625 | 626 | if (!branchFromDesc.isEmpty()) { 627 | branchFromDesc += " at r" + QByteArray::number(branchRevNum); 628 | if (closestCommit != branchRevNum) { 629 | branchFromDesc += " => r" + QByteArray::number(closestCommit); 630 | } 631 | } 632 | 633 | return brFrom.marks[it - brFrom.commits.begin()]; 634 | } 635 | 636 | int FastImportRepository::createBranch(const QString &branch, int revnum, 637 | const QString &branchFrom, int branchRevNum) 638 | { 639 | QByteArray branchFromDesc = "from branch " + branchFrom.toUtf8(); 640 | long long mark = markFrom(branchFrom, branchRevNum, branchFromDesc); 641 | 642 | if (mark == -1) { 643 | qCritical() << branch << "in repository" << name 644 | << "is branching from branch" << branchFrom 645 | << "but the latter doesn't exist. Can't continue."; 646 | return EXIT_FAILURE; 647 | } 648 | 649 | QByteArray branchFromRef = ":" + QByteArray::number(mark); 650 | if (!mark) { 651 | qWarning() << "WARN:" << branch << "in repository" << name << "is branching but no exported commits exist in repository" 652 | << "creating an empty branch."; 653 | branchFromRef = branchFrom.toUtf8(); 654 | if (!branchFromRef.startsWith("refs/")) 655 | branchFromRef.prepend("refs/heads/"); 656 | branchFromDesc += ", deleted/unknown"; 657 | } 658 | 659 | qDebug() << "Creating branch:" << branch << "from" << branchFrom << "(" << branchRevNum << branchFromDesc << ")"; 660 | 661 | // Preserve note 662 | branchNotes[branch] = branchNotes.value(branchFrom); 663 | 664 | return resetBranch(branch, revnum, mark, branchFromRef, branchFromDesc); 665 | } 666 | 667 | int FastImportRepository::deleteBranch(const QString &branch, int revnum) 668 | { 669 | static QByteArray null_sha(40, '0'); 670 | return resetBranch(branch, revnum, 0, null_sha, "delete"); 671 | } 672 | 673 | int FastImportRepository::resetBranch(const QString &branch, int revnum, mark_t mark, const QByteArray &resetTo, const QByteArray &comment) 674 | { 675 | QByteArray branchRef = branch.toUtf8(); 676 | if (!branchRef.startsWith("refs/")) 677 | branchRef.prepend("refs/heads/"); 678 | 679 | Branch &br = branches[branch]; 680 | QByteArray backupCmd; 681 | if (br.created && br.created != revnum && !br.marks.isEmpty() && br.marks.last()) { 682 | QByteArray backupBranch; 683 | if ((comment == "delete") && branchRef.startsWith("refs/heads/")) 684 | backupBranch = "refs/tags/backups/" + branchRef.mid(11) + "@" + QByteArray::number(revnum); 685 | else 686 | backupBranch = "refs/backups/r" + QByteArray::number(revnum) + branchRef.mid(4); 687 | qWarning() << "WARN: backing up branch" << branch << "to" << backupBranch; 688 | 689 | backupCmd = "reset " + backupBranch + "\nfrom " + branchRef + "\n\n"; 690 | } 691 | 692 | br.created = revnum; 693 | br.commits.append(revnum); 694 | br.marks.append(mark); 695 | 696 | QByteArray cmd = "reset " + branchRef + "\nfrom " + resetTo + "\n\n" 697 | "progress SVN r" + QByteArray::number(revnum) 698 | + " branch " + branch.toUtf8() + " = :" + QByteArray::number(mark) 699 | + " # " + comment + "\n\n"; 700 | if(comment == "delete") { 701 | deletedBranches.append(backupCmd).append(cmd); 702 | deletedBranchNames.insert(branchRef); 703 | } else { 704 | resetBranches.append(backupCmd).append(cmd); 705 | resetBranchNames.insert(branchRef); 706 | } 707 | 708 | return EXIT_SUCCESS; 709 | } 710 | 711 | void FastImportRepository::commit() 712 | { 713 | if (deletedBranches.isEmpty() && resetBranches.isEmpty()) { 714 | return; 715 | } 716 | startFastImport(); 717 | fastImport.write(deletedBranches); 718 | fastImport.write(resetBranches); 719 | deletedBranches.clear(); 720 | resetBranches.clear(); 721 | QSet::ConstIterator it = deletedBranchNames.constBegin(); 722 | for ( ; it != deletedBranchNames.constEnd(); ++it) { 723 | QString tagName = *it; 724 | if (resetBranchNames.contains(tagName)) 725 | continue; 726 | if (tagName.startsWith("refs/tags/")) 727 | tagName.remove(0, 10); 728 | if (annotatedTags.remove(tagName) > 0) { 729 | qDebug() << "Removing annotated tag" << tagName << "for" << name; 730 | } 731 | } 732 | deletedBranchNames.clear(); 733 | resetBranchNames.clear(); 734 | } 735 | 736 | Repository::Transaction *FastImportRepository::newTransaction(const QString &branch, const QString &svnprefix, 737 | int revnum) 738 | { 739 | if (!branchExists(branch)) { 740 | qWarning() << "WARN: Transaction:" << branch << "is not a known branch in repository" << name << Qt::endl 741 | << "Going to create it automatically"; 742 | } 743 | 744 | Transaction *txn = new Transaction; 745 | txn->repository = this; 746 | txn->branch = branch.toUtf8(); 747 | txn->svnprefix = svnprefix.toUtf8(); 748 | txn->datetime = 0; 749 | txn->revnum = revnum; 750 | 751 | if ((++commitCount % CommandLineParser::instance()->optionArgument(QLatin1String("commit-interval"), QLatin1String("10000")).toInt()) == 0) { 752 | startFastImport(); 753 | // write everything to disk every 10000 commits 754 | fastImport.write("checkpoint\n"); 755 | qDebug() << "checkpoint!, marks file truncated"; 756 | } 757 | outstandingTransactions++; 758 | return txn; 759 | } 760 | 761 | void FastImportRepository::forgetTransaction(Transaction *) 762 | { 763 | if (!--outstandingTransactions) 764 | next_file_mark = maxMark - 1; 765 | } 766 | 767 | void FastImportRepository::createAnnotatedTag(const QString &ref, const QString &svnprefix, 768 | int revnum, 769 | const QByteArray &author, uint dt, 770 | const QByteArray &log) 771 | { 772 | QString tagName = ref; 773 | if (tagName.startsWith("refs/tags/")) 774 | tagName.remove(0, 10); 775 | 776 | if (!annotatedTags.contains(tagName)) 777 | printf("\nCreating annotated tag %s (%s) for %s\n", qPrintable(tagName), qPrintable(ref), qPrintable(name)); 778 | else 779 | printf("\nRe-creating annotated tag %s for %s\n", qPrintable(tagName), qPrintable(name)); 780 | 781 | AnnotatedTag &tag = annotatedTags[tagName]; 782 | tag.supportingRef = ref; 783 | tag.svnprefix = svnprefix.toUtf8(); 784 | tag.revnum = revnum; 785 | tag.author = author; 786 | tag.log = log; 787 | tag.dt = dt; 788 | } 789 | 790 | void FastImportRepository::finalizeTags() 791 | { 792 | if (annotatedTags.isEmpty()) 793 | return; 794 | 795 | QFile annotatedTagsFile(name + "/" + annotatedTagsFileName(name)); 796 | annotatedTagsFile.open(QIODevice::WriteOnly); 797 | QDataStream annotatedTagsStream(&annotatedTagsFile); 798 | annotatedTagsStream << annotatedTags; 799 | annotatedTagsFile.close(); 800 | 801 | printf("Finalising annotated tags for %s...", qPrintable(name)); 802 | startFastImport(); 803 | 804 | QHash::ConstIterator it = annotatedTags.constBegin(); 805 | for ( ; it != annotatedTags.constEnd(); ++it) { 806 | const QString &tagName = it.key(); 807 | const AnnotatedTag &tag = it.value(); 808 | 809 | QByteArray message = tag.log; 810 | if (!message.endsWith('\n')) 811 | message += '\n'; 812 | if (CommandLineParser::instance()->contains("add-metadata")) 813 | message += "\n" + formatMetadataMessage(tag.svnprefix, tag.revnum, tagName.toUtf8()); 814 | 815 | { 816 | QByteArray branchRef = tag.supportingRef.toUtf8(); 817 | if (!branchRef.startsWith("refs/")) 818 | branchRef.prepend("refs/heads/"); 819 | 820 | QByteArray s = "progress Creating annotated tag " + tagName.toUtf8() + " from ref " + branchRef + "\n" 821 | + "tag " + tagName.toUtf8() + "\n" 822 | + "from " + branchRef + "\n" 823 | + "tagger " + tag.author + ' ' + QByteArray::number(tag.dt) + " +0000" + "\n" 824 | + "data " + QByteArray::number( message.length() ) + "\n"; 825 | fastImport.write(s); 826 | } 827 | 828 | fastImport.write(message); 829 | fastImport.putChar('\n'); 830 | if (!fastImport.waitForBytesWritten(-1)) 831 | qFatal("Failed to write to process: %s", qPrintable(fastImport.errorString())); 832 | 833 | // Append note to the tip commit of the supporting ref. There is no 834 | // easy way to attach a note to the tag itself with fast-import. 835 | if (CommandLineParser::instance()->contains("add-metadata-notes")) { 836 | Repository::Transaction *txn = newTransaction(tag.supportingRef, tag.svnprefix, tag.revnum); 837 | txn->setAuthor(tag.author); 838 | txn->setDateTime(tag.dt); 839 | bool written = txn->commitNote(formatMetadataMessage(tag.svnprefix, tag.revnum, tagName.toUtf8()), true); 840 | delete txn; 841 | 842 | if (written && !fastImport.waitForBytesWritten(-1)) 843 | qFatal("Failed to write to process: %s", qPrintable(fastImport.errorString())); 844 | } 845 | 846 | printf(" %s", qPrintable(tagName)); 847 | fflush(stdout); 848 | } 849 | 850 | while (fastImport.bytesToWrite()) 851 | if (!fastImport.waitForBytesWritten(-1)) 852 | qFatal("Failed to write to process: %s", qPrintable(fastImport.errorString())); 853 | printf("\n"); 854 | } 855 | 856 | void FastImportRepository::saveBranchNotes() 857 | { 858 | if (branchNotes.isEmpty()) 859 | return; 860 | 861 | QFile branchNotesFile(name + "/" + branchNotesFileName(name)); 862 | branchNotesFile.open(QIODevice::WriteOnly); 863 | QDataStream branchNotesStream(&branchNotesFile); 864 | branchNotesStream << branchNotes; 865 | branchNotesFile.close(); 866 | } 867 | 868 | QByteArray 869 | FastImportRepository::msgFilter(QByteArray msg) 870 | { 871 | QByteArray output = msg; 872 | 873 | if (CommandLineParser::instance()->contains("msg-filter")) { 874 | if (filterMsg.state() == QProcess::Running) 875 | qFatal("filter process already running?"); 876 | 877 | filterMsg.start(CommandLineParser::instance()->optionArgument("msg-filter")); 878 | 879 | if(!(filterMsg.waitForStarted(-1))) 880 | qFatal("Failed to Start Filter %d %s", __LINE__, qPrintable(filterMsg.errorString())); 881 | 882 | filterMsg.write(msg); 883 | filterMsg.closeWriteChannel(); 884 | filterMsg.waitForFinished(); 885 | output = filterMsg.readAllStandardOutput(); 886 | } 887 | return output; 888 | } 889 | 890 | void FastImportRepository::startFastImport() 891 | { 892 | processCache.touch(this); 893 | 894 | if (fastImport.state() == QProcess::NotRunning) { 895 | if (processHasStarted) 896 | qFatal("git-fast-import has been started once and crashed?"); 897 | processHasStarted = true; 898 | 899 | // start the process 900 | QString marksFile = marksFileName(name); 901 | QStringList marksOptions; 902 | marksOptions << "--import-marks=" + marksFile; 903 | marksOptions << "--export-marks=" + marksFile; 904 | marksOptions << "--force"; 905 | 906 | fastImport.setStandardOutputFile(logFileName(name), QIODevice::Append); 907 | fastImport.setProcessChannelMode(QProcess::MergedChannels); 908 | 909 | if (!CommandLineParser::instance()->contains("dry-run") && !CommandLineParser::instance()->contains("create-dump")) { 910 | fastImport.start("git", QStringList() << "fast-import" << marksOptions); 911 | } else { 912 | fastImport.start("cat", QStringList()); 913 | } 914 | fastImport.waitForStarted(-1); 915 | 916 | reloadBranches(); 917 | } 918 | } 919 | 920 | QByteArray Repository::formatMetadataMessage(const QByteArray &svnprefix, int revnum, const QByteArray &tag) 921 | { 922 | QByteArray msg = "svn path=" + svnprefix + "; revision=" + QByteArray::number(revnum); 923 | if (!tag.isEmpty()) 924 | msg += "; tag=" + tag; 925 | msg += "\n"; 926 | return msg; 927 | } 928 | 929 | bool FastImportRepository::branchExists(const QString& branch) const 930 | { 931 | return branches.contains(branch); 932 | } 933 | 934 | const QByteArray FastImportRepository::branchNote(const QString& branch) const 935 | { 936 | return branchNotes.value(branch); 937 | } 938 | 939 | void FastImportRepository::setBranchNote(const QString& branch, const QByteArray& noteText) 940 | { 941 | if (branches.contains(branch)) 942 | branchNotes[branch] = noteText; 943 | } 944 | 945 | bool FastImportRepository::hasPrefix() const 946 | { 947 | return !prefix.isEmpty(); 948 | } 949 | 950 | QString FastImportRepository::getName() const 951 | { 952 | return name; 953 | } 954 | 955 | Repository *FastImportRepository::getEffectiveRepository() 956 | { 957 | return this; 958 | } 959 | 960 | FastImportRepository::Transaction::~Transaction() 961 | { 962 | repository->forgetTransaction(this); 963 | } 964 | 965 | void FastImportRepository::Transaction::setAuthor(const QByteArray &a) 966 | { 967 | author = a; 968 | } 969 | 970 | void FastImportRepository::Transaction::setDateTime(uint dt) 971 | { 972 | datetime = dt; 973 | } 974 | 975 | void FastImportRepository::Transaction::setLog(const QByteArray &l) 976 | { 977 | log = l; 978 | } 979 | 980 | void FastImportRepository::Transaction::noteCopyFromBranch(const QString &branchFrom, int branchRevNum) 981 | { 982 | if(branch == branchFrom) { 983 | qWarning() << "WARN: Cannot merge inside a branch"; 984 | return; 985 | } 986 | static QByteArray dummy; 987 | long long mark = repository->markFrom(branchFrom, branchRevNum, dummy); 988 | Q_ASSERT(dummy.isEmpty()); 989 | 990 | if (mark == -1) { 991 | qWarning() << "WARN:" << branch << "is copying from branch" << branchFrom 992 | << "but the latter doesn't exist. Continuing, assuming the files exist."; 993 | } else if (mark == 0) { 994 | qWarning() << "WARN: Unknown revision r" << QByteArray::number(branchRevNum) 995 | << ". Continuing, assuming the files exist."; 996 | } else { 997 | qWarning() << "WARN: repository " + repository->name + " branch " + branch + " has some files copied from " + branchFrom + "@" + QByteArray::number(branchRevNum); 998 | 999 | if (!merges.contains(mark)) { 1000 | merges.append(mark); 1001 | qDebug() << "adding" << branchFrom + "@" + QByteArray::number(branchRevNum) << ":" << mark << "as a merge point"; 1002 | } else { 1003 | qDebug() << "merge point already recorded"; 1004 | } 1005 | } 1006 | } 1007 | 1008 | void FastImportRepository::Transaction::deleteFile(const QString &path) 1009 | { 1010 | QString pathNoSlash = repository->prefix + path; 1011 | if(pathNoSlash.endsWith('/')) 1012 | pathNoSlash.chop(1); 1013 | deletedFiles.append(pathNoSlash); 1014 | } 1015 | 1016 | QIODevice *FastImportRepository::Transaction::addFile(const QString &path, int mode, qint64 length) 1017 | { 1018 | mark_t mark = repository->next_file_mark--; 1019 | 1020 | // in case the two mark allocations meet, we might as well just abort 1021 | Q_ASSERT(mark > repository->last_commit_mark + 1); 1022 | 1023 | if (modifiedFiles.capacity() == 0) 1024 | modifiedFiles.reserve(2048); 1025 | modifiedFiles.append("M "); 1026 | modifiedFiles.append(QByteArray::number(mode, 8)); 1027 | modifiedFiles.append(" :"); 1028 | modifiedFiles.append(QByteArray::number(mark)); 1029 | modifiedFiles.append(' '); 1030 | modifiedFiles.append(repository->prefix.toUtf8() + path.toUtf8()); 1031 | modifiedFiles.append("\n"); 1032 | 1033 | // it is returned for being written to, so start the process in any case 1034 | repository->startFastImport(); 1035 | if (!CommandLineParser::instance()->contains("dry-run")) { 1036 | repository->fastImport.writeNoLog("blob\nmark :"); 1037 | repository->fastImport.writeNoLog(QByteArray::number(mark)); 1038 | repository->fastImport.writeNoLog("\ndata "); 1039 | repository->fastImport.writeNoLog(QByteArray::number(length)); 1040 | repository->fastImport.writeNoLog("\n", 1); 1041 | } 1042 | 1043 | return &repository->fastImport; 1044 | } 1045 | 1046 | bool FastImportRepository::Transaction::commitNote(const QByteArray ¬eText, bool append, const QByteArray &commit) 1047 | { 1048 | QByteArray branchRef = branch; 1049 | if (!branchRef.startsWith("refs/")) 1050 | { 1051 | branchRef.prepend("refs/heads/"); 1052 | } 1053 | const QByteArray &commitRef = commit.isNull() ? branchRef : commit; 1054 | QByteArray message = "Adding Git note for current " + commitRef + "\n"; 1055 | QByteArray text = noteText; 1056 | if (noteText[noteText.size() - 1] != '\n') 1057 | { 1058 | text += '\n'; 1059 | } 1060 | 1061 | QByteArray branchNote = repository->branchNote(branch); 1062 | if (!branchNote.isEmpty() && (branchNote[branchNote.size() - 1] != '\n')) 1063 | { 1064 | branchNote += '\n'; 1065 | } 1066 | if (append && commit.isNull() && 1067 | repository->branchExists(branch) && 1068 | !branchNote.isEmpty()) 1069 | { 1070 | int i = branchNote.indexOf(text); 1071 | if ((i == 0) || ((i != -1) && (branchNote[i - 1] == '\n'))) 1072 | { 1073 | // note is already present at the start or somewhere within following a newline 1074 | return false; 1075 | } 1076 | text = branchNote + text; 1077 | message = "Appending Git note for current " + commitRef + "\n"; 1078 | } 1079 | 1080 | QByteArray s(""); 1081 | s.append("commit refs/notes/commits\n"); 1082 | s.append("mark :" + QByteArray::number(maxMark) + "\n"); 1083 | s.append("committer " + author + " " + QByteArray::number(datetime) + " +0000" + "\n"); 1084 | s.append("data " + QByteArray::number(message.length()) + "\n"); 1085 | s.append(message + "\n"); 1086 | s.append("N inline " + commitRef + "\n"); 1087 | s.append("data " + QByteArray::number(text.length()) + "\n"); 1088 | s.append(text + "\n"); 1089 | repository->startFastImport(); 1090 | repository->fastImport.write(s); 1091 | 1092 | if (commit.isNull()) 1093 | { 1094 | repository->setBranchNote(QString::fromUtf8(branch), text); 1095 | } 1096 | 1097 | return true; 1098 | } 1099 | 1100 | int FastImportRepository::Transaction::commit() 1101 | { 1102 | foreach (QString branchName, repository->branches.keys()) 1103 | { 1104 | if (branchName.toUtf8().startsWith(branch + "/") || branch.startsWith((branchName + "/").toUtf8())) 1105 | { 1106 | qCritical() << "Branch" << branch << "conflicts with already existing branch" << branchName; 1107 | return EXIT_FAILURE; 1108 | } 1109 | } 1110 | 1111 | repository->startFastImport(); 1112 | 1113 | // We might be tempted to use the SVN revision number as the fast-import commit mark. 1114 | // However, a single SVN revision can modify multiple branches, and thus lead to multiple 1115 | // commits in the same repo. So, we need to maintain a separate commit mark counter. 1116 | mark_t mark = ++repository->last_commit_mark; 1117 | 1118 | // in case the two mark allocations meet, we might as well just abort 1119 | Q_ASSERT(mark < repository->next_file_mark - 1); 1120 | 1121 | // create the commit message 1122 | QByteArray message = log; 1123 | if (!message.endsWith('\n')) 1124 | message += '\n'; 1125 | if (CommandLineParser::instance()->contains("add-metadata")) 1126 | message += "\n" + Repository::formatMetadataMessage(svnprefix, revnum); 1127 | 1128 | // Call external message filter if provided 1129 | message = repository->msgFilter(message); 1130 | 1131 | mark_t parentmark = 0; 1132 | Branch &br = repository->branches[branch]; 1133 | if (br.created && !br.marks.isEmpty() && br.marks.last()) { 1134 | parentmark = br.marks.last(); 1135 | } else { 1136 | if (revnum > 1 && branch != repository->defaultBranch) { 1137 | // Any branch at revision 1 isn't going to exist -> do not alarm the user. 1138 | // Default branch might also not exist yet -> do not alarm the user. 1139 | qWarning() << "WARN: Branch" << branch << "in repository" << repository->name << "doesn't exist at revision" 1140 | << revnum << "-- did you resume from the wrong revision?"; 1141 | } 1142 | br.created = revnum; 1143 | } 1144 | br.commits.append(revnum); 1145 | br.marks.append(mark); 1146 | 1147 | QByteArray branchRef = branch; 1148 | if (!branchRef.startsWith("refs/")) 1149 | branchRef.prepend("refs/heads/"); 1150 | 1151 | QByteArray s(""); 1152 | s.append("commit " + branchRef + "\n"); 1153 | s.append("mark :" + QByteArray::number(mark) + "\n"); 1154 | s.append("committer " + author + " " + QString::number(datetime).toUtf8() + " +0000" + "\n"); 1155 | s.append("data " + QByteArray::number(message.length()) + "\n"); 1156 | s.append(message + "\n"); 1157 | repository->fastImport.write(s); 1158 | 1159 | // note some of the inferred merges 1160 | QByteArray desc = ""; 1161 | mark_t i = !!parentmark; // if parentmark != 0, there's at least one parent 1162 | 1163 | if(log.contains("This commit was manufactured by cvs2svn") && merges.count() > 1) { 1164 | std::sort(merges.begin(), merges.end()); 1165 | repository->fastImport.write("merge :" + QByteArray::number(merges.last()) + "\n"); 1166 | merges.pop_back(); 1167 | qWarning() << "WARN: Discarding all but the highest merge point as a workaround for cvs2svn created branch/tag" 1168 | << "Discarded marks:" << merges; 1169 | } else { 1170 | foreach (const mark_t merge, merges) { 1171 | if (merge == parentmark) { 1172 | qDebug() << "Skipping marking" << merge << "as a merge point as it matches the parent"; 1173 | continue; 1174 | } 1175 | 1176 | if (++i > 16) { 1177 | // FIXME: options: 1178 | // (1) ignore the 16 parent limit 1179 | // (2) don't emit more than 16 parents 1180 | // (3) create another commit on branch to soak up additional parents 1181 | // we've chosen option (2) for now, since only artificial commits 1182 | // created by cvs2svn seem to have this issue 1183 | qWarning() << "WARN: too many merge parents"; 1184 | break; 1185 | } 1186 | 1187 | QByteArray m = " :" + QByteArray::number(merge); 1188 | desc += m; 1189 | repository->fastImport.write("merge" + m + "\n"); 1190 | } 1191 | } 1192 | // write the file deletions 1193 | if (deletedFiles.contains("")) 1194 | repository->fastImport.write("deleteall\n"); 1195 | else 1196 | foreach (QString df, deletedFiles) 1197 | repository->fastImport.write("D " + df.toUtf8() + "\n"); 1198 | 1199 | // write the file modifications 1200 | repository->fastImport.write(modifiedFiles); 1201 | 1202 | repository->fastImport.write("\nprogress SVN r" + QByteArray::number(revnum) 1203 | + " branch " + branch + " = :" + QByteArray::number(mark) 1204 | + (desc.isEmpty() ? "" : " # merge from") + desc 1205 | + "\n\n"); 1206 | printf(" %d modifications from SVN %s to %s/%s", 1207 | deletedFiles.count() + modifiedFiles.count('\n'), svnprefix.data(), 1208 | qPrintable(repository->name), branch.data()); 1209 | 1210 | // Commit metadata note if requested 1211 | if (CommandLineParser::instance()->contains("add-metadata-notes")) 1212 | commitNote(Repository::formatMetadataMessage(svnprefix, revnum), false); 1213 | 1214 | while (repository->fastImport.bytesToWrite()) 1215 | if (!repository->fastImport.waitForBytesWritten(-1)) 1216 | qFatal("Failed to write to process: %s for repository %s", qPrintable(repository->fastImport.errorString()), qPrintable(repository->name)); 1217 | 1218 | return EXIT_SUCCESS; 1219 | } 1220 | -------------------------------------------------------------------------------- /src/repository.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 Thiago Macieira 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef REPOSITORY_H 19 | #define REPOSITORY_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "ruleparser.h" 27 | #include "CommandLineParser.h" 28 | 29 | class LoggingQProcess : public QProcess 30 | { 31 | QFile log; 32 | bool logging; 33 | public: 34 | LoggingQProcess(const QString filename) : QProcess(), log() { 35 | if(CommandLineParser::instance()->contains("debug-rules")) { 36 | logging = true; 37 | QString name = filename; 38 | name.replace('/', '_'); 39 | name.prepend("gitlog-"); 40 | log.setFileName(name); 41 | log.open(QIODevice::WriteOnly); 42 | } else { 43 | logging = false; 44 | } 45 | }; 46 | ~LoggingQProcess() { 47 | if(logging) { 48 | log.close(); 49 | } 50 | }; 51 | 52 | qint64 write(const char *data) { 53 | Q_ASSERT(state() == QProcess::Running); 54 | if(logging) { 55 | log.write(data); 56 | } 57 | return QProcess::write(data); 58 | } 59 | qint64 write(const char *data, qint64 length) { 60 | Q_ASSERT(state() == QProcess::Running); 61 | if(logging) { 62 | log.write(data); 63 | } 64 | return QProcess::write(data, length); 65 | } 66 | qint64 write(const QByteArray &data) { 67 | Q_ASSERT(state() == QProcess::Running); 68 | if(logging) { 69 | log.write(data); 70 | } 71 | return QProcess::write(data); 72 | } 73 | qint64 writeNoLog(const char *data) { 74 | Q_ASSERT(state() == QProcess::Running); 75 | return QProcess::write(data); 76 | } 77 | qint64 writeNoLog(const char *data, qint64 length) { 78 | Q_ASSERT(state() == QProcess::Running); 79 | return QProcess::write(data, length); 80 | } 81 | qint64 writeNoLog(const QByteArray &data) { 82 | Q_ASSERT(state() == QProcess::Running); 83 | return QProcess::write(data); 84 | } 85 | bool putChar( char c) { 86 | Q_ASSERT(state() == QProcess::Running); 87 | if(logging) { 88 | log.putChar(c); 89 | } 90 | return QProcess::putChar(c); 91 | } 92 | }; 93 | 94 | class Repository 95 | { 96 | public: 97 | class Transaction 98 | { 99 | Q_DISABLE_COPY(Transaction) 100 | protected: 101 | Transaction() {} 102 | public: 103 | virtual ~Transaction() {} 104 | virtual int commit() = 0; 105 | 106 | virtual void setAuthor(const QByteArray &author) = 0; 107 | virtual void setDateTime(uint dt) = 0; 108 | virtual void setLog(const QByteArray &log) = 0; 109 | 110 | virtual void noteCopyFromBranch (const QString &prevbranch, int revFrom) = 0; 111 | 112 | virtual void deleteFile(const QString &path) = 0; 113 | virtual QIODevice *addFile(const QString &path, int mode, qint64 length) = 0; 114 | 115 | virtual bool commitNote(const QByteArray ¬eText, bool append, 116 | const QByteArray &commit = QByteArray()) = 0; 117 | }; 118 | virtual int setupIncremental(int &cutoff) = 0; 119 | virtual void restoreAnnotatedTags() = 0; 120 | virtual void restoreBranchNotes() = 0; 121 | virtual void restoreLog() = 0; 122 | virtual ~Repository() {} 123 | 124 | virtual void reloadBranches() = 0; 125 | virtual int createBranch(const QString &branch, int revnum, 126 | const QString &branchFrom, int revFrom) = 0; 127 | virtual int deleteBranch(const QString &branch, int revnum) = 0; 128 | virtual Repository::Transaction *newTransaction(const QString &branch, const QString &svnprefix, int revnum) = 0; 129 | 130 | virtual void createAnnotatedTag(const QString &name, const QString &svnprefix, int revnum, 131 | const QByteArray &author, uint dt, 132 | const QByteArray &log) = 0; 133 | virtual void finalizeTags() = 0; 134 | virtual void saveBranchNotes() = 0; 135 | virtual void commit() = 0; 136 | 137 | static QByteArray formatMetadataMessage(const QByteArray &svnprefix, int revnum, 138 | const QByteArray &tag = QByteArray()); 139 | 140 | virtual bool branchExists(const QString& branch) const = 0; 141 | virtual const QByteArray branchNote(const QString& branch) const = 0; 142 | virtual void setBranchNote(const QString& branch, const QByteArray& noteText) = 0; 143 | 144 | virtual bool hasPrefix() const = 0; 145 | 146 | virtual QString getName() const = 0; 147 | virtual Repository *getEffectiveRepository() = 0; 148 | }; 149 | 150 | Repository *createRepository(const Rules::Repository &rule, const QHash &repositories); 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /src/ruleparser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 Thiago Macieira 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "ruleparser.h" 24 | #include "CommandLineParser.h" 25 | 26 | RulesList::RulesList(const QString &filenames) 27 | : m_filenames(filenames) 28 | { 29 | } 30 | 31 | RulesList::~RulesList() {} 32 | 33 | void RulesList::load() 34 | { 35 | foreach(const QString filename, m_filenames.split(',') ) { 36 | qDebug() << "Loading rules from:" << filename; 37 | Rules *rules = new Rules(filename); 38 | m_rules.append(rules); 39 | rules->load(); 40 | m_allrepositories.append(rules->repositories()); 41 | QList matchRules = rules->matchRules(); 42 | m_allMatchRules.append( QList(matchRules)); 43 | } 44 | } 45 | 46 | const QList RulesList::allRepositories() const 47 | { 48 | return m_allrepositories; 49 | } 50 | 51 | const QList > RulesList::allMatchRules() const 52 | { 53 | return m_allMatchRules; 54 | } 55 | 56 | const QList RulesList::rules() const 57 | { 58 | return m_rules; 59 | } 60 | 61 | Rules::Rules(const QString &fn) 62 | : filename(fn) 63 | { 64 | } 65 | 66 | Rules::~Rules() 67 | { 68 | } 69 | 70 | const QList Rules::repositories() const 71 | { 72 | return m_repositories; 73 | } 74 | 75 | const QList Rules::matchRules() const 76 | { 77 | return m_matchRules; 78 | } 79 | 80 | Rules::Match::Substitution Rules::parseSubstitution(const QString &string) 81 | { 82 | if (string.at(0) != 's' || string.length() < 5) 83 | return Match::Substitution(); 84 | 85 | const QChar sep = string.at(1); 86 | 87 | if (string.at(string.length() - 1) != sep) 88 | return Match::Substitution(); 89 | 90 | int i = 2, end = 0; 91 | Match::Substitution subst; 92 | 93 | // Separator might have been escaped with a backslash 94 | while (i > end) { 95 | int backslashCount = 0; 96 | if ((end = string.indexOf(sep, i)) > -1) { 97 | for (i = end - 1; i >= 2; i--) { 98 | if (string.at(i) == '\\') 99 | backslashCount++; 100 | else 101 | break; 102 | } 103 | } else { 104 | return Match::Substitution(); // error 105 | } 106 | 107 | if (backslashCount % 2 != 0) { 108 | // Separator was escaped. Search for another one 109 | i = end + 1; 110 | } 111 | } 112 | 113 | // Found the end of the pattern 114 | subst.pattern = QRegExp(string.mid(2, end - 2)); 115 | if (!subst.pattern.isValid()) 116 | return Match::Substitution(); // error 117 | subst.replacement = string.mid(end + 1, string.length() - 1 - end - 1); 118 | 119 | return subst; 120 | } 121 | 122 | void Rules::load() 123 | { 124 | load(filename); 125 | } 126 | 127 | void Rules::load(const QString &filename) 128 | { 129 | qDebug() << "Loading rules from" << filename; 130 | // initialize the regexps we will use 131 | QRegExp repoLine("create repository\\s+(\\S+)", Qt::CaseInsensitive); 132 | 133 | QString varRegex("[A-Za-z0-9_]+"); 134 | 135 | QRegExp matchLine("match\\s+(.*)", Qt::CaseInsensitive); 136 | QRegExp matchActionLine("action\\s+(\\w+)", Qt::CaseInsensitive); 137 | QRegExp matchRepoLine("repository\\s+(\\S+)", Qt::CaseInsensitive); 138 | QRegExp matchDescLine("description\\s+(.+)$", Qt::CaseInsensitive); 139 | QRegExp matchRepoSubstLine("substitute repository\\s+(.+)$", Qt::CaseInsensitive); 140 | QRegExp matchBranchLine("branch\\s+(\\S+)", Qt::CaseInsensitive); 141 | QRegExp matchBranchSubstLine("substitute branch\\s+(.+)$", Qt::CaseInsensitive); 142 | QRegExp matchRevLine("(min|max) revision (\\d+)", Qt::CaseInsensitive); 143 | QRegExp matchAnnotateLine("annotated\\s+(\\S+)", Qt::CaseInsensitive); 144 | QRegExp matchPrefixLine("prefix\\s+(.*)$", Qt::CaseInsensitive); 145 | QRegExp declareLine("declare\\s+("+varRegex+")\\s*=\\s*(\\S+)", Qt::CaseInsensitive); 146 | QRegExp variableLine("\\$\\{("+varRegex+")(\\|[^}$]*)?\\}", Qt::CaseInsensitive); 147 | QRegExp includeLine("include\\s+(.*)", Qt::CaseInsensitive); 148 | 149 | enum { ReadingNone, ReadingRepository, ReadingMatch } state = ReadingNone; 150 | Repository repo; 151 | Match match; 152 | int lineNumber = 0; 153 | 154 | QFile file(filename); 155 | if (!file.open(QIODevice::ReadOnly)) 156 | qFatal("Could not read the rules file: %s", qPrintable(filename)); 157 | 158 | QTextStream s(&file); 159 | QStringList lines = s.readAll().split('\n', Qt::KeepEmptyParts); 160 | 161 | QStringList::iterator it; 162 | for(it = lines.begin(); it != lines.end(); ++it) { 163 | ++lineNumber; 164 | QString origLine = *it; 165 | QString line = origLine; 166 | 167 | int hash = line.indexOf('#'); 168 | if (hash != -1) 169 | line.truncate(hash); 170 | line = line.trimmed(); 171 | if (line.isEmpty()) 172 | continue; 173 | 174 | bool isIncludeRule = includeLine.exactMatch(line); 175 | if (isIncludeRule) { 176 | int index = filename.lastIndexOf("/"); 177 | QString includeFile = filename.left( index + 1) + includeLine.cap(1); 178 | load(includeFile); 179 | } else { 180 | while( variableLine.indexIn(line) != -1 ) { 181 | QString replacement; 182 | if (m_variables.contains(variableLine.cap(1))) { 183 | replacement = m_variables[variableLine.cap(1)]; 184 | } else { 185 | if (variableLine.cap(2).startsWith('|')) { 186 | replacement = variableLine.cap(2).mid(1); 187 | } else { 188 | qFatal("Undeclared variable: %s", qPrintable(variableLine.cap(1))); 189 | } 190 | } 191 | line = line.replace(variableLine.cap(0), replacement); 192 | } 193 | if (state == ReadingRepository) { 194 | if (matchBranchLine.exactMatch(line)) { 195 | Repository::Branch branch; 196 | branch.name = matchBranchLine.cap(1); 197 | 198 | repo.branches += branch; 199 | continue; 200 | } else if (matchDescLine.exactMatch(line)) { 201 | repo.description = matchDescLine.cap(1); 202 | continue; 203 | } else if (matchRepoLine.exactMatch(line)) { 204 | repo.forwardTo = matchRepoLine.cap(1); 205 | continue; 206 | } else if (matchPrefixLine.exactMatch(line)) { 207 | repo.prefix = matchPrefixLine.cap(1); 208 | continue; 209 | } else if (line == "end repository") { 210 | if (!repo.forwardTo.isEmpty() 211 | && !repo.description.isEmpty()) { 212 | 213 | qFatal("Specifing repository and description on repository is invalid on line %d", lineNumber); 214 | } 215 | 216 | if (!repo.forwardTo.isEmpty() 217 | && !repo.branches.isEmpty()) { 218 | 219 | qFatal("Specifing repository and branches on repository is invalid on line %d", lineNumber); 220 | } 221 | 222 | m_repositories += repo; 223 | { 224 | // clear out 'repo' 225 | Repository temp; 226 | std::swap(repo, temp); 227 | } 228 | state = ReadingNone; 229 | continue; 230 | } 231 | } else if (state == ReadingMatch) { 232 | if (matchRepoLine.exactMatch(line)) { 233 | match.repository = matchRepoLine.cap(1); 234 | continue; 235 | } else if (matchBranchLine.exactMatch(line)) { 236 | match.branch = matchBranchLine.cap(1); 237 | continue; 238 | } else if (matchRepoSubstLine.exactMatch(line)) { 239 | Match::Substitution subst = parseSubstitution(matchRepoSubstLine.cap(1)); 240 | if (!subst.isValid()) { 241 | qFatal("Malformed substitution in rules file: line %d: %s", 242 | lineNumber, qPrintable(origLine)); 243 | } 244 | match.repo_substs += subst; 245 | continue; 246 | } else if (matchBranchSubstLine.exactMatch(line)) { 247 | Match::Substitution subst = parseSubstitution(matchBranchSubstLine.cap(1)); 248 | if (!subst.isValid()) { 249 | qFatal("Malformed substitution in rules file: line %d: %s", 250 | lineNumber, qPrintable(origLine)); 251 | } 252 | match.branch_substs += subst; 253 | continue; 254 | } else if (matchRevLine.exactMatch(line)) { 255 | if (matchRevLine.cap(1) == "min") 256 | match.minRevision = matchRevLine.cap(2).toInt(); 257 | else // must be max 258 | match.maxRevision = matchRevLine.cap(2).toInt(); 259 | continue; 260 | } else if (matchPrefixLine.exactMatch(line)) { 261 | match.prefix = matchPrefixLine.cap(1); 262 | if( match.prefix.startsWith('/')) 263 | match.prefix = match.prefix.mid(1); 264 | continue; 265 | } else if (matchActionLine.exactMatch(line)) { 266 | QString action = matchActionLine.cap(1); 267 | if (action == "export") 268 | match.action = Match::Export; 269 | else if (action == "ignore") 270 | match.action = Match::Ignore; 271 | else if (action == "recurse") 272 | match.action = Match::Recurse; 273 | else 274 | qFatal("Invalid action \"%s\" on line %d", qPrintable(action), lineNumber); 275 | continue; 276 | } else if (matchAnnotateLine.exactMatch(line)) { 277 | match.annotate = matchAnnotateLine.cap(1) == "true"; 278 | continue; 279 | } else if (line == "end match") { 280 | if (!match.repository.isEmpty()) 281 | match.action = Match::Export; 282 | m_matchRules += match; 283 | Stats::instance()->addRule(match); 284 | state = ReadingNone; 285 | continue; 286 | } 287 | } 288 | 289 | bool isRepositoryRule = repoLine.exactMatch(line); 290 | bool isMatchRule = matchLine.exactMatch(line); 291 | bool isVariableRule = declareLine.exactMatch(line); 292 | 293 | if (isRepositoryRule) { 294 | // repository rule 295 | state = ReadingRepository; 296 | repo = Repository(); // clear 297 | repo.name = repoLine.cap(1); 298 | repo.lineNumber = lineNumber; 299 | repo.filename = filename; 300 | } else if (isMatchRule) { 301 | // match rule 302 | state = ReadingMatch; 303 | match = Match(); 304 | match.rx = QRegExp(matchLine.cap(1), Qt::CaseSensitive, QRegExp::RegExp2); 305 | if( !match.rx.isValid() ) 306 | qFatal("Malformed regular expression '%s' in file:'%s':%d, Error: %s", 307 | qPrintable(matchLine.cap(1)), qPrintable(filename), lineNumber, 308 | qPrintable(match.rx.errorString())); 309 | match.lineNumber = lineNumber; 310 | match.filename = filename; 311 | } else if (isVariableRule) { 312 | QString variable = declareLine.cap(1); 313 | QString value = declareLine.cap(2); 314 | m_variables.insert(variable, value); 315 | } else { 316 | qFatal("Malformed line in rules file: line %d: %s", 317 | lineNumber, qPrintable(origLine)); 318 | } 319 | } 320 | } 321 | } 322 | 323 | Stats *Stats::self = 0; 324 | 325 | class Stats::Private 326 | { 327 | public: 328 | Private(); 329 | 330 | void printStats() const; 331 | void ruleMatched(const Rules::Match &rule, const int rev); 332 | void addRule(const Rules::Match &rule); 333 | private: 334 | QMap m_usedRules; 335 | }; 336 | 337 | Stats::Stats() : d(new Private()) 338 | { 339 | use = CommandLineParser::instance()->contains("stats"); 340 | } 341 | 342 | Stats::~Stats() 343 | { 344 | delete d; 345 | } 346 | 347 | void Stats::init() 348 | { 349 | if(self) 350 | delete self; 351 | self = new Stats(); 352 | } 353 | 354 | Stats* Stats::instance() 355 | { 356 | return self; 357 | } 358 | 359 | void Stats::printStats() const 360 | { 361 | if(use) 362 | d->printStats(); 363 | } 364 | 365 | void Stats::ruleMatched(const Rules::Match &rule, const int rev) 366 | { 367 | if(use) 368 | d->ruleMatched(rule, rev); 369 | } 370 | 371 | void Stats::addRule( const Rules::Match &rule) 372 | { 373 | if(use) 374 | d->addRule(rule); 375 | } 376 | 377 | Stats::Private::Private() 378 | { 379 | } 380 | 381 | void Stats::Private::printStats() const 382 | { 383 | printf("\nRule stats\n"); 384 | foreach(const Rules::Match rule, m_usedRules.keys()) { 385 | printf("%s was matched %i times\n", qPrintable(rule.info()), m_usedRules[rule]); 386 | } 387 | } 388 | 389 | void Stats::Private::ruleMatched(const Rules::Match &rule, const int rev) 390 | { 391 | Q_UNUSED(rev); 392 | if(!m_usedRules.contains(rule)) { 393 | m_usedRules.insert(rule, 1); 394 | qWarning() << "WARN: New match rule" << rule.info() << ", should have been added when created."; 395 | } else { 396 | m_usedRules[rule]++; 397 | } 398 | } 399 | 400 | void Stats::Private::addRule( const Rules::Match &rule) 401 | { 402 | if(m_usedRules.contains(rule)) 403 | qWarning() << "WARN: Rule" << rule.info() << "was added multiple times."; 404 | m_usedRules.insert(rule, 0); 405 | } 406 | 407 | #ifndef QT_NO_DEBUG_STREAM 408 | QDebug operator<<(QDebug s, const Rules::Match &rule) 409 | { 410 | s.nospace() << rule.info(); 411 | return s.space(); 412 | } 413 | 414 | #endif 415 | -------------------------------------------------------------------------------- /src/ruleparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 Thiago Macieira 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef RULEPARSER_H 19 | #define RULEPARSER_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | class Rules 29 | { 30 | public: 31 | struct Rule 32 | { 33 | QString filename; 34 | int lineNumber; 35 | Rule() : lineNumber(0) {} 36 | }; 37 | struct Repository : Rule 38 | { 39 | struct Branch 40 | { 41 | QString name; 42 | }; 43 | 44 | QString name; 45 | QList branches; 46 | QString description; 47 | 48 | QString forwardTo; 49 | QString prefix; 50 | 51 | Repository() { } 52 | const QString info() const { 53 | const QString info = Rule::filename % ":" % QByteArray::number(Rule::lineNumber); 54 | return info; 55 | } 56 | 57 | }; 58 | 59 | struct Match : Rule 60 | { 61 | struct Substitution { 62 | QRegExp pattern; 63 | QString replacement; 64 | 65 | bool isValid() { return !pattern.isEmpty(); } 66 | #if QT_VERSION >= 0x060000 67 | QString apply(QString &string) { return pattern.replaceIn(string, replacement); } 68 | #else 69 | QString& apply(QString &string) { return string.replace(pattern, replacement); } 70 | #endif 71 | }; 72 | 73 | QRegExp rx; 74 | QString repository; 75 | QList repo_substs; 76 | QString branch; 77 | QList branch_substs; 78 | QString prefix; 79 | int minRevision; 80 | int maxRevision; 81 | bool annotate; 82 | 83 | enum Action { 84 | Ignore, 85 | Export, 86 | Recurse 87 | } action; 88 | 89 | Match() : minRevision(-1), maxRevision(-1), annotate(false), action(Ignore) { } 90 | bool operator<(const Match other) const { 91 | if (filename != other.filename) 92 | return filename < other.filename; 93 | return lineNumber < other.lineNumber; 94 | } 95 | const QString info() const { 96 | const QString info = Rule::filename % ":" % QByteArray::number(Rule::lineNumber) % " " % rx.pattern(); 97 | return info; 98 | } 99 | }; 100 | 101 | Rules(const QString &filename); 102 | ~Rules(); 103 | 104 | const QList repositories() const; 105 | const QList matchRules() const; 106 | Match::Substitution parseSubstitution(const QString &string); 107 | void load(); 108 | 109 | private: 110 | void load(const QString &filename); 111 | QString filename; 112 | QList m_repositories; 113 | QList m_matchRules; 114 | QMap m_variables; 115 | }; 116 | 117 | class RulesList 118 | { 119 | public: 120 | RulesList( const QString &filenames); 121 | ~RulesList(); 122 | 123 | const QList allRepositories() const; 124 | const QList > allMatchRules() const; 125 | const QList rules() const; 126 | void load(); 127 | 128 | private: 129 | QString m_filenames; 130 | QList m_rules; 131 | QList m_allrepositories; 132 | QList > m_allMatchRules; 133 | }; 134 | 135 | class Stats 136 | { 137 | public: 138 | static Stats *instance(); 139 | void printStats() const; 140 | void ruleMatched(const Rules::Match &rule, const int rev = -1); 141 | void addRule( const Rules::Match &rule); 142 | static void init(); 143 | ~Stats(); 144 | 145 | private: 146 | Stats(); 147 | class Private; 148 | Private * const d; 149 | static Stats *self; 150 | bool use; 151 | }; 152 | 153 | #ifndef QT_NO_DEBUG_STREAM 154 | class QDebug; 155 | QDebug operator<<(QDebug, const Rules::Match &); 156 | #endif 157 | 158 | #endif 159 | -------------------------------------------------------------------------------- /src/src.pro: -------------------------------------------------------------------------------- 1 | if(!defined(SVN_INCLUDE, var)) { 2 | SVN_INCLUDE = /usr/include/subversion-1 /usr/local/include/subversion-1 3 | } 4 | if(!defined(APR_INCLUDE, var)) { 5 | APR_INCLUDE = /usr/include/apr-1.0 /usr/include/apr-1 /usr/local/include/apr-1 6 | } 7 | exists(local-config.pri):include(local-config.pri) 8 | 9 | if(!defined(VERSION, var)) { 10 | VERSION = $$system(git --no-pager show --pretty=oneline --no-notes | head -1 | cut -b-40) 11 | } 12 | 13 | DEFINES += QT_DISABLE_DEPRECATED_UP_TO=0x05FFFF 14 | 15 | VERSTR = '\\"$${VERSION}\\"' # place quotes around the version string 16 | DEFINES += VER=\"$${VERSTR}\" # create a VER macro containing the version string 17 | 18 | TEMPLATE = app 19 | TARGET = ../svn-all-fast-export 20 | 21 | isEmpty(PREFIX) { 22 | PREFIX = /usr/local 23 | } 24 | BINDIR = $$PREFIX/bin 25 | 26 | INSTALLS += target 27 | target.path = $$BINDIR 28 | 29 | DEPENDPATH += . 30 | QT = core 31 | 32 | _MIN_QT_VERSION = 5.14.0 33 | 34 | !versionAtLeast(QT_VERSION, $${_MIN_QT_VERSION}) { 35 | error("Qt $${QT_VERSION} found but Qt >=$${_MIN_QT_VERSION} required, cannot continue.") 36 | } 37 | 38 | greaterThan(QT_MAJOR_VERSION, 5) { 39 | QT += core5compat 40 | } 41 | 42 | INCLUDEPATH += . $$SVN_INCLUDE $$APR_INCLUDE 43 | !isEmpty(SVN_LIBDIR): LIBS += -L$$SVN_LIBDIR 44 | LIBS += -lsvn_fs-1 -lsvn_repos-1 -lapr-1 -lsvn_subr-1 45 | 46 | # Input 47 | SOURCES += ruleparser.cpp \ 48 | repository.cpp \ 49 | svn.cpp \ 50 | main.cpp \ 51 | CommandLineParser.cpp \ 52 | 53 | HEADERS += ruleparser.h \ 54 | repository.h \ 55 | svn.h \ 56 | CommandLineParser.h \ 57 | -------------------------------------------------------------------------------- /src/svn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 Thiago Macieira 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef SVN_H 19 | #define SVN_H 20 | 21 | #include 22 | #include 23 | #include "ruleparser.h" 24 | 25 | class Repository; 26 | 27 | class SvnPrivate; 28 | class Svn 29 | { 30 | public: 31 | static void initialize(); 32 | 33 | Svn(const QString &pathToRepository); 34 | ~Svn(); 35 | 36 | void setMatchRules(const QList > &matchRules); 37 | void setRepositories(const QHash &repositories); 38 | void setIdentityMap(const QHash &identityMap); 39 | void setIdentityDomain(const QString &identityDomain); 40 | 41 | int youngestRevision(); 42 | bool exportRevision(int revnum); 43 | 44 | private: 45 | SvnPrivate * const d; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | # Ensure needed tools are present 6 | svn --version >/dev/null 7 | git --version >/dev/null 8 | tar --version >/dev/null 9 | 10 | # Determine SCRIPT_DIR 11 | # Resolve links: $0 may be a link 12 | PRG="$0" 13 | # Need this for relative symlinks. 14 | while [ -h "$PRG" ]; do 15 | ls=$(ls -ld "$PRG") 16 | link=$(expr "$ls" : '.*-> \(.*\)$') 17 | if expr "$link" : '/.*' >/dev/null; then 18 | PRG="$link" 19 | else 20 | PRG=$(dirname "$PRG")"/$link" 21 | fi 22 | done 23 | cd "$(dirname "$PRG")/" >/dev/null 24 | SCRIPT_DIR="$(pwd -P)" 25 | 26 | if [ "${1-}" == "--no-make" ]; then 27 | shift 28 | else 29 | qmake 30 | make 31 | fi 32 | 33 | if [ $# -eq 0 ]; then 34 | set -- test 35 | else 36 | set -- "${@/#/test/}" 37 | set -- "${@/%/.bats}" 38 | fi 39 | 40 | mkdir -p "$SCRIPT_DIR/build/tmp" 41 | { 42 | TMPDIR="$SCRIPT_DIR/build/tmp" \ 43 | test/libs/bats-core/bin/bats "$@" \ 44 | 4>&1 1>&2 2>&4 | 45 | awk ' 46 | BEGIN { 47 | duplicate_test_names = "" 48 | } 49 | 50 | { 51 | print 52 | } 53 | 54 | /duplicate test name/ { 55 | duplicate_test_names = duplicate_test_names "\n\t" $0 56 | } 57 | 58 | END { 59 | if (length(duplicate_test_names)) { 60 | print "\nERROR: duplicate test name(s) found:" duplicate_test_names 61 | exit 1 62 | } 63 | } 64 | ' 65 | } 4>&1 1>&2 2>&4 66 | -------------------------------------------------------------------------------- /test/base-fixture.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/svn-all-fast-export/svn2git/6e25e1c044afb28cd09738b07c2eaee304df513e/test/base-fixture.tar -------------------------------------------------------------------------------- /test/command-line.bats: -------------------------------------------------------------------------------- 1 | load 'common' 2 | 3 | setup() { 4 | : # suppress common setup, no repository needed 5 | } 6 | 7 | @test 'specifying version parameter should output version and exit with 0 no matter what' { 8 | run svn2git --version --non-existing repo-a repo-b 9 | assert_success 10 | assert_output --partial 'Git version:' 11 | 12 | run svn2git --non-existing repo-a --version repo-b 13 | assert_success 14 | assert_output --partial 'Git version:' 15 | 16 | run svn2git --non-existing repo-a repo-b --version 17 | assert_success 18 | assert_output --partial 'Git version:' 19 | 20 | run svn2git -v --non-existing repo-a repo-b 21 | assert_success 22 | assert_output --partial 'Git version:' 23 | 24 | run svn2git --non-existing repo-a -v repo-b 25 | assert_success 26 | assert_output --partial 'Git version:' 27 | 28 | run svn2git --non-existing repo-a repo-b -v 29 | assert_success 30 | assert_output --partial 'Git version:' 31 | } 32 | 33 | @test 'specifying help parameter should output usage and exit with 0 no matter what' { 34 | run svn2git --help --non-existing repo-a repo-b 35 | assert_success 36 | assert_output --partial 'Usage:' 37 | 38 | run svn2git --non-existing repo-a --help repo-b 39 | assert_success 40 | assert_output --partial 'Usage:' 41 | 42 | run svn2git --non-existing repo-a repo-b --help 43 | assert_success 44 | assert_output --partial 'Usage:' 45 | 46 | run svn2git -h --non-existing repo-a repo-b 47 | assert_success 48 | assert_output --partial 'Usage:' 49 | 50 | run svn2git --non-existing repo-a -h repo-b 51 | assert_success 52 | assert_output --partial 'Usage:' 53 | 54 | run svn2git --non-existing repo-a repo-b -h 55 | assert_success 56 | assert_output --partial 'Usage:' 57 | } 58 | 59 | @test 'not giving a repository should exist with non-zero exit code and print usage' { 60 | run svn2git 61 | assert_failure 12 62 | assert_output --partial 'Usage:' 63 | } 64 | 65 | @test 'giving mutliple repositories should exist with non-zero exit code and print usage' { 66 | run svn2git repo-a repo-b 67 | assert_failure 12 68 | assert_output --partial 'Usage:' 69 | } 70 | -------------------------------------------------------------------------------- /test/common.bash: -------------------------------------------------------------------------------- 1 | load 'libs/bats-support/load' 2 | load 'libs/bats-assert/load' 3 | load 'libs/bats-file/load' 4 | 5 | setup() { 6 | commonSetup 7 | } 8 | 9 | commonSetup() { 10 | TEST_TEMP_DIR="$(temp_make --prefix 'svn2git-')" 11 | BATSLIB_FILE_PATH_REM="#${TEST_TEMP_DIR}" 12 | BATSLIB_FILE_PATH_ADD='' 13 | 14 | SVN_REPO="$TEST_TEMP_DIR/svn-repo" 15 | SVN_WORKTREE="$TEST_TEMP_DIR/svn-worktree" 16 | 17 | tar xf "$BATS_TEST_DIRNAME/base-fixture.tar" --one-top-level="$SVN_REPO" 18 | svn checkout "file:///$SVN_REPO" "$SVN_WORKTREE" 19 | cd "$SVN_WORKTREE" 20 | } 21 | 22 | teardown() { 23 | commonTeardown 24 | } 25 | 26 | commonTeardown() { 27 | if [ -n "${TEST_TEMP_DIR-}" ]; then 28 | temp_del "$TEST_TEMP_DIR" 29 | fi 30 | } 31 | 32 | svn2git() { 33 | "$BATS_TEST_DIRNAME/../svn-all-fast-export" "$@" 34 | } 35 | -------------------------------------------------------------------------------- /test/copy-directories.bats: -------------------------------------------------------------------------------- 1 | load 'common' 2 | 3 | @test 'copying a directory with source not in target repo should dump full directory' { 4 | svn mkdir --parents project-a/dir-a 5 | touch project-a/dir-a/file-a 6 | svn add project-a/dir-a/file-a 7 | svn commit -m 'add project-a/dir-a/file-a' 8 | svn mkdir --parents project-b 9 | svn commit -m 'add project-b' 10 | svn cp project-a/dir-a project-b 11 | svn commit -m 'copy project-a/dir-a to project-b' 12 | 13 | cd "$TEST_TEMP_DIR" 14 | svn2git "$SVN_REPO" --debug-rules --rules <(echo " 15 | create repository git-repo 16 | end repository 17 | 18 | match /project-b/ 19 | repository git-repo 20 | branch master 21 | end match 22 | 23 | match /project-a/ 24 | end match 25 | ") 26 | 27 | assert git -C git-repo show master:dir-a/file-a 28 | } 29 | -------------------------------------------------------------------------------- /test/empty-dirs.bats: -------------------------------------------------------------------------------- 1 | load 'common' 2 | 3 | @test 'empty-dirs parameter should put empty .gitignore files to empty directories' { 4 | svn mkdir dir-a 5 | svn commit -m 'add dir-a' 6 | 7 | cd "$TEST_TEMP_DIR" 8 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 9 | create repository git-repo 10 | end repository 11 | 12 | match / 13 | repository git-repo 14 | branch master 15 | end match 16 | ") 17 | 18 | assert git -C git-repo show master:dir-a/.gitignore 19 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 20 | } 21 | 22 | @test 'empty-dirs parameter should put empty .gitignore files to empty directories (nested)' { 23 | svn mkdir project-a 24 | cd project-a 25 | svn mkdir dir-a 26 | svn commit -m 'add dir-a' 27 | 28 | cd "$TEST_TEMP_DIR" 29 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 30 | create repository git-repo 31 | end repository 32 | 33 | match /project-a/ 34 | repository git-repo 35 | branch master 36 | end match 37 | ") 38 | 39 | assert git -C git-repo show master:dir-a/.gitignore 40 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 41 | } 42 | 43 | @test 'empty-dirs parameter should not put empty .gitignore files to non-empty directories' { 44 | svn mkdir dir-a 45 | touch dir-a/file-a 46 | svn add dir-a/file-a 47 | svn commit -m 'add dir-a/file-a' 48 | 49 | cd "$TEST_TEMP_DIR" 50 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 51 | create repository git-repo 52 | end repository 53 | 54 | match / 55 | repository git-repo 56 | branch master 57 | end match 58 | ") 59 | 60 | refute git -C git-repo show master:dir-a/.gitignore 61 | } 62 | 63 | @test 'empty-dirs parameter should not put empty .gitignore files to non-empty directories (nested)' { 64 | svn mkdir project-a 65 | cd project-a 66 | svn mkdir dir-a 67 | touch dir-a/file-a 68 | svn add dir-a/file-a 69 | svn commit -m 'add dir-a/file-a' 70 | 71 | cd "$TEST_TEMP_DIR" 72 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 73 | create repository git-repo 74 | end repository 75 | 76 | match /project-a/ 77 | repository git-repo 78 | branch master 79 | end match 80 | ") 81 | 82 | refute git -C git-repo show master:dir-a/.gitignore 83 | } 84 | 85 | @test 'empty-dirs parameter should not put empty .gitignore files to directories with generated .gitignore' { 86 | svn mkdir dir-a 87 | svn propset svn:ignore $'ignore-a\nignore-b' dir-a 88 | svn commit -m 'add dir-a with ignores' 89 | 90 | cd "$TEST_TEMP_DIR" 91 | svn2git "$SVN_REPO" --svn-ignore --empty-dirs --rules <(echo " 92 | create repository git-repo 93 | end repository 94 | 95 | match / 96 | repository git-repo 97 | branch master 98 | end match 99 | ") 100 | 101 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" "$(cat <<-EOF 102 | /ignore-a 103 | /ignore-b 104 | EOF 105 | )" 106 | } 107 | 108 | @test 'empty-dirs parameter should not put empty .gitignore files to directories with generated .gitignore (nested)' { 109 | svn mkdir project-a 110 | cd project-a 111 | svn mkdir dir-a 112 | svn propset svn:ignore $'ignore-a\nignore-b' dir-a 113 | svn commit -m 'add dir-a with ignores' 114 | 115 | cd "$TEST_TEMP_DIR" 116 | svn2git "$SVN_REPO" --svn-ignore --empty-dirs --rules <(echo " 117 | create repository git-repo 118 | end repository 119 | 120 | match /project-a/ 121 | repository git-repo 122 | branch master 123 | end match 124 | ") 125 | 126 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" "$(cat <<-EOF 127 | /ignore-a 128 | /ignore-b 129 | EOF 130 | )" 131 | } 132 | 133 | @test 'empty-dirs parameter should not put empty .gitignore files to directories with .gitignore' { 134 | svn mkdir dir-a 135 | echo ignore-a >dir-a/.gitignore 136 | svn add dir-a/.gitignore 137 | svn commit -m 'add dir-a/.gitignore' 138 | 139 | cd "$TEST_TEMP_DIR" 140 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 141 | create repository git-repo 142 | end repository 143 | 144 | match / 145 | repository git-repo 146 | branch master 147 | end match 148 | ") 149 | 150 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" 'ignore-a' 151 | } 152 | 153 | @test 'empty-dirs parameter should not put empty .gitignore files to directories with .gitignore (nested)' { 154 | svn mkdir project-a 155 | cd project-a 156 | svn mkdir dir-a 157 | echo ignore-a >dir-a/.gitignore 158 | svn add dir-a/.gitignore 159 | svn commit -m 'add dir-a/.gitignore' 160 | 161 | cd "$TEST_TEMP_DIR" 162 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 163 | create repository git-repo 164 | end repository 165 | 166 | match /project-a/ 167 | repository git-repo 168 | branch master 169 | end match 170 | ") 171 | 172 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" 'ignore-a' 173 | } 174 | 175 | @test 'empty-dirs parameter should not cause added directories to be dumped multiple times' { 176 | svn mkdir dir-a 177 | echo content-a >dir-a/file-a 178 | svn add dir-a/file-a 179 | svn commit -m 'add dir-a/file-a' 180 | 181 | cd "$TEST_TEMP_DIR" 182 | svn2git "$SVN_REPO" --empty-dirs --create-dump --rules <(echo " 183 | create repository git-repo 184 | end repository 185 | 186 | match / 187 | repository git-repo 188 | branch master 189 | end match 190 | ") 191 | 192 | assert [ "$(grep -c '^M .* dir-a/file-a$' git-repo.fi)" -eq 1 ] 193 | } 194 | 195 | @test 'empty-dirs parameter should not cause added directories to be dumped multiple times (nested)' { 196 | svn mkdir project-a 197 | cd project-a 198 | svn mkdir dir-a 199 | echo content-a >dir-a/file-a 200 | svn add dir-a/file-a 201 | svn commit -m 'add dir-a/file-a' 202 | 203 | cd "$TEST_TEMP_DIR" 204 | svn2git "$SVN_REPO" --empty-dirs --create-dump --rules <(echo " 205 | create repository git-repo 206 | end repository 207 | 208 | match /project-a/ 209 | repository git-repo 210 | branch master 211 | end match 212 | ") 213 | 214 | assert [ "$(grep -c '^M .* dir-a/file-a$' git-repo.fi)" -eq 1 ] 215 | } 216 | 217 | @test 'adding first file to an empty directory should remove empty .gitignore with empty-dirs-parameter' { 218 | svn mkdir dir-a 219 | svn commit -m 'add dir-a' 220 | touch dir-a/file-a 221 | svn add dir-a/file-a 222 | svn commit -m 'add dir-a/file-a' 223 | 224 | cd "$TEST_TEMP_DIR" 225 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 226 | create repository git-repo 227 | end repository 228 | 229 | match / 230 | repository git-repo 231 | branch master 232 | end match 233 | ") 234 | 235 | refute git -C git-repo show master:dir-a/.gitignore 236 | } 237 | 238 | @test 'adding first file to an empty directory should remove empty .gitignore with empty-dirs-parameter (nested)' { 239 | svn mkdir project-a 240 | cd project-a 241 | svn mkdir dir-a 242 | svn commit -m 'add dir-a' 243 | touch dir-a/file-a 244 | svn add dir-a/file-a 245 | svn commit -m 'add dir-a/file-a' 246 | 247 | cd "$TEST_TEMP_DIR" 248 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 249 | create repository git-repo 250 | end repository 251 | 252 | match /project-a/ 253 | repository git-repo 254 | branch master 255 | end match 256 | ") 257 | 258 | refute git -C git-repo show master:dir-a/.gitignore 259 | } 260 | 261 | @test 'adding first file to an empty directory should remove empty .gitignore with empty-dirs- and svn-ignore-parameter' { 262 | svn mkdir dir-a 263 | svn commit -m 'add dir-a' 264 | touch dir-a/file-a 265 | svn add dir-a/file-a 266 | svn commit -m 'add dir-a/file-a' 267 | 268 | cd "$TEST_TEMP_DIR" 269 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 270 | create repository git-repo 271 | end repository 272 | 273 | match / 274 | repository git-repo 275 | branch master 276 | end match 277 | ") 278 | 279 | refute git -C git-repo show master:dir-a/.gitignore 280 | } 281 | 282 | @test 'adding first file to an empty directory should remove empty .gitignore with empty-dirs- and svn-ignore-parameter (nested)' { 283 | svn mkdir project-a 284 | cd project-a 285 | svn mkdir dir-a 286 | svn commit -m 'add dir-a' 287 | touch dir-a/file-a 288 | svn add dir-a/file-a 289 | svn commit -m 'add dir-a/file-a' 290 | 291 | cd "$TEST_TEMP_DIR" 292 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 293 | create repository git-repo 294 | end repository 295 | 296 | match /project-a/ 297 | repository git-repo 298 | branch master 299 | end match 300 | ") 301 | 302 | refute git -C git-repo show master:dir-a/.gitignore 303 | } 304 | 305 | @test 'adding first file to an empty directory with ignores should not remove .gitignore with empty-dirs-parameter and svn-ignore-parameter' { 306 | svn mkdir dir-a 307 | svn propset svn:ignore 'ignore-a' dir-a 308 | svn commit -m 'add dir-a' 309 | touch dir-a/file-a 310 | svn add dir-a/file-a 311 | svn commit -m 'add dir-a/file-a' 312 | 313 | cd "$TEST_TEMP_DIR" 314 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 315 | create repository git-repo 316 | end repository 317 | 318 | match / 319 | repository git-repo 320 | branch master 321 | end match 322 | ") 323 | 324 | assert git -C git-repo show master:dir-a/.gitignore 325 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 326 | } 327 | 328 | @test 'adding first file to an empty directory with ignores should not remove .gitignore with empty-dirs-parameter and svn-ignore-parameter (nested)' { 329 | svn mkdir project-a 330 | cd project-a 331 | svn mkdir dir-a 332 | svn propset svn:ignore 'ignore-a' dir-a 333 | svn commit -m 'add dir-a' 334 | touch dir-a/file-a 335 | svn add dir-a/file-a 336 | svn commit -m 'add dir-a/file-a' 337 | 338 | cd "$TEST_TEMP_DIR" 339 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 340 | create repository git-repo 341 | end repository 342 | 343 | match /project-a/ 344 | repository git-repo 345 | branch master 346 | end match 347 | ") 348 | 349 | assert git -C git-repo show master:dir-a/.gitignore 350 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 351 | } 352 | 353 | @test 'adding first file to an empty directory and at the same time adding ignores should not remove .gitignore with empty-dirs-parameter and svn-ignore-parameter' { 354 | svn mkdir dir-a 355 | svn commit -m 'add dir-a' 356 | svn propset svn:ignore 'ignore-a' dir-a 357 | touch dir-a/file-a 358 | svn add dir-a/file-a 359 | svn commit -m 'add dir-a/file-a and ignores' 360 | 361 | cd "$TEST_TEMP_DIR" 362 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 363 | create repository git-repo 364 | end repository 365 | 366 | match / 367 | repository git-repo 368 | branch master 369 | end match 370 | ") 371 | 372 | assert git -C git-repo show master:dir-a/.gitignore 373 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 374 | } 375 | 376 | @test 'adding first file to an empty directory and at the same time adding ignores should not remove .gitignore with empty-dirs-parameter and svn-ignore-parameter (nested)' { 377 | svn mkdir project-a 378 | cd project-a 379 | svn mkdir dir-a 380 | svn commit -m 'add dir-a' 381 | svn propset svn:ignore 'ignore-a' dir-a 382 | touch dir-a/file-a 383 | svn add dir-a/file-a 384 | svn commit -m 'add dir-a/file-a and ignores' 385 | 386 | cd "$TEST_TEMP_DIR" 387 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 388 | create repository git-repo 389 | end repository 390 | 391 | match /project-a/ 392 | repository git-repo 393 | branch master 394 | end match 395 | ") 396 | 397 | assert git -C git-repo show master:dir-a/.gitignore 398 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 399 | } 400 | 401 | @test 'deleting last file from a directory should add empty .gitignore with empty-dirs-parameter' { 402 | svn mkdir dir-a 403 | touch dir-a/file-a 404 | svn add dir-a/file-a 405 | svn commit -m 'add dir-a/file-a' 406 | svn rm dir-a/file-a 407 | svn commit -m 'delete dir-a/file-a' 408 | 409 | cd "$TEST_TEMP_DIR" 410 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 411 | create repository git-repo 412 | end repository 413 | 414 | match / 415 | repository git-repo 416 | branch master 417 | end match 418 | ") 419 | 420 | refute git -C git-repo show master:.gitignore 421 | assert git -C git-repo show master:dir-a/.gitignore 422 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 423 | } 424 | 425 | @test 'deleting last file from a directory should add empty .gitignore with empty-dirs-parameter (nested)' { 426 | svn mkdir project-a 427 | cd project-a 428 | svn mkdir dir-a 429 | touch dir-a/file-a 430 | svn add dir-a/file-a 431 | svn commit -m 'add dir-a/file-a' 432 | svn rm dir-a/file-a 433 | svn commit -m 'delete dir-a/file-a' 434 | 435 | cd "$TEST_TEMP_DIR" 436 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 437 | create repository git-repo 438 | end repository 439 | 440 | match /project-a/ 441 | repository git-repo 442 | branch master 443 | end match 444 | ") 445 | 446 | refute git -C git-repo show master:.gitignore 447 | assert git -C git-repo show master:dir-a/.gitignore 448 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 449 | } 450 | 451 | @test 'deleting last file from a directory should not add empty .gitignore with empty-dirs-parameter and svn-ignore-parameter if there is an svn:ignore property' { 452 | svn mkdir dir-a 453 | touch dir-a/file-a 454 | svn add dir-a/file-a 455 | svn commit -m 'add dir-a/file-a' 456 | svn propset svn:ignore 'ignore-a' dir-a 457 | svn commit -m 'ignore ignore-a on dir-a' 458 | svn rm dir-a/file-a 459 | svn commit -m 'delete dir-a/file-a' 460 | 461 | cd "$TEST_TEMP_DIR" 462 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 463 | create repository git-repo 464 | end repository 465 | 466 | match / 467 | repository git-repo 468 | branch master 469 | end match 470 | ") 471 | 472 | refute git -C git-repo show master:.gitignore 473 | assert git -C git-repo show master:dir-a/.gitignore 474 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 475 | } 476 | 477 | @test 'deleting last file from a directory should not add empty .gitignore with empty-dirs-parameter and svn-ignore-parameter if there is an svn:ignore property (nested)' { 478 | svn mkdir project-a 479 | cd project-a 480 | svn mkdir dir-a 481 | touch dir-a/file-a 482 | svn add dir-a/file-a 483 | svn commit -m 'add dir-a/file-a' 484 | svn propset svn:ignore 'ignore-a' dir-a 485 | svn commit -m 'ignore ignore-a on dir-a' 486 | svn rm dir-a/file-a 487 | svn commit -m 'delete dir-a/file-a' 488 | 489 | cd "$TEST_TEMP_DIR" 490 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 491 | create repository git-repo 492 | end repository 493 | 494 | match /project-a/ 495 | repository git-repo 496 | branch master 497 | end match 498 | ") 499 | 500 | refute git -C git-repo show master:.gitignore 501 | assert git -C git-repo show master:dir-a/.gitignore 502 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 503 | } 504 | 505 | @test 'deleting last file from root should not add empty .gitignore with empty-dirs-parameter' { 506 | touch file-a 507 | svn add file-a 508 | svn commit -m 'add file-a' 509 | svn rm file-a 510 | svn commit -m 'delete file-a' 511 | 512 | cd "$TEST_TEMP_DIR" 513 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 514 | create repository git-repo 515 | end repository 516 | 517 | match / 518 | repository git-repo 519 | branch master 520 | end match 521 | ") 522 | 523 | refute git -C git-repo show master:.gitignore 524 | refute git -C git-repo show master:file-a/.gitignore 525 | } 526 | 527 | @test 'deleting last file from root should not add empty .gitignore with empty-dirs-parameter (nested)' { 528 | svn mkdir project-a 529 | cd project-a 530 | touch file-a 531 | svn add file-a 532 | svn commit -m 'add file-a' 533 | svn rm file-a 534 | svn commit -m 'delete file-a' 535 | 536 | cd "$TEST_TEMP_DIR" 537 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 538 | create repository git-repo 539 | end repository 540 | 541 | match /project-a/ 542 | repository git-repo 543 | branch master 544 | end match 545 | ") 546 | 547 | refute git -C git-repo show master:.gitignore 548 | refute git -C git-repo show master:file-a/.gitignore 549 | } 550 | 551 | @test 'deleting last directory from a directory should add empty .gitignore with empty-dirs-parameter' { 552 | svn mkdir --parents dir-a/subdir-a 553 | svn commit -m 'add dir-a/subdir-a' 554 | svn rm dir-a/subdir-a 555 | svn commit -m 'delete dir-a/subdir-a' 556 | 557 | cd "$TEST_TEMP_DIR" 558 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 559 | create repository git-repo 560 | end repository 561 | 562 | match / 563 | repository git-repo 564 | branch master 565 | end match 566 | ") 567 | 568 | refute git -C git-repo show master:.gitignore 569 | assert git -C git-repo show master:dir-a/.gitignore 570 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 571 | } 572 | 573 | @test 'deleting last directory from a directory should add empty .gitignore with empty-dirs-parameter (nested)' { 574 | svn mkdir project-a 575 | cd project-a 576 | svn mkdir --parents dir-a/subdir-a 577 | svn commit -m 'add dir-a/subdir-a' 578 | svn rm dir-a/subdir-a 579 | svn commit -m 'delete dir-a/subdir-a' 580 | 581 | cd "$TEST_TEMP_DIR" 582 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 583 | create repository git-repo 584 | end repository 585 | 586 | match /project-a/ 587 | repository git-repo 588 | branch master 589 | end match 590 | ") 591 | 592 | refute git -C git-repo show master:.gitignore 593 | assert git -C git-repo show master:dir-a/.gitignore 594 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 595 | } 596 | 597 | @test 'adding first directory to an empty directory should remove empty .gitignore with empty-dirs-parameter' { 598 | svn mkdir dir-a 599 | svn commit -m 'add dir-a' 600 | svn mkdir dir-a/subdir-a 601 | svn commit -m 'add dir-a/subdir-a' 602 | 603 | cd "$TEST_TEMP_DIR" 604 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 605 | create repository git-repo 606 | end repository 607 | 608 | match / 609 | repository git-repo 610 | branch master 611 | end match 612 | ") 613 | 614 | refute git -C git-repo show master:dir-a/.gitignore 615 | } 616 | 617 | @test 'adding first directory to an empty directory should remove empty .gitignore with empty-dirs-parameter (nested)' { 618 | svn mkdir project-a 619 | cd project-a 620 | svn mkdir dir-a 621 | svn commit -m 'add dir-a' 622 | svn mkdir dir-a/subdir-a 623 | svn commit -m 'add dir-a/subdir-a' 624 | 625 | cd "$TEST_TEMP_DIR" 626 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 627 | create repository git-repo 628 | end repository 629 | 630 | match /project-a/ 631 | repository git-repo 632 | branch master 633 | end match 634 | ") 635 | 636 | refute git -C git-repo show master:dir-a/.gitignore 637 | } 638 | 639 | @test 'adding first directory to an empty directory should remove empty .gitignore with empty-dirs-parameter and svn-ignore-parameter' { 640 | svn mkdir dir-a 641 | svn commit -m 'add dir-a' 642 | svn mkdir dir-a/subdir-a 643 | svn commit -m 'add dir-a/subdir-a' 644 | 645 | cd "$TEST_TEMP_DIR" 646 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 647 | create repository git-repo 648 | end repository 649 | 650 | match / 651 | repository git-repo 652 | branch master 653 | end match 654 | ") 655 | 656 | refute git -C git-repo show master:dir-a/.gitignore 657 | } 658 | 659 | @test 'adding first directory to an empty directory should remove empty .gitignore with empty-dirs-parameter and svn-ignore-parameter (nested)' { 660 | svn mkdir project-a 661 | cd project-a 662 | svn mkdir dir-a 663 | svn commit -m 'add dir-a' 664 | svn mkdir dir-a/subdir-a 665 | svn commit -m 'add dir-a/subdir-a' 666 | 667 | cd "$TEST_TEMP_DIR" 668 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 669 | create repository git-repo 670 | end repository 671 | 672 | match /project-a/ 673 | repository git-repo 674 | branch master 675 | end match 676 | ") 677 | 678 | refute git -C git-repo show master:dir-a/.gitignore 679 | } 680 | 681 | @test 'adding first directory to an empty directory with ignores should not remove .gitignore with empty-dirs-parameter and svn-ignore-parameter' { 682 | svn mkdir dir-a 683 | svn propset svn:ignore 'ignore-a' dir-a 684 | svn commit -m 'add dir-a' 685 | svn mkdir dir-a/subdir-a 686 | svn commit -m 'add dir-a/subdir-a' 687 | 688 | cd "$TEST_TEMP_DIR" 689 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 690 | create repository git-repo 691 | end repository 692 | 693 | match / 694 | repository git-repo 695 | branch master 696 | end match 697 | ") 698 | 699 | assert git -C git-repo show master:dir-a/.gitignore 700 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 701 | } 702 | 703 | @test 'adding first directory to an empty directory with ignores should not remove .gitignore with empty-dirs-parameter and svn-ignore-parameter (nested)' { 704 | svn mkdir project-a 705 | cd project-a 706 | svn mkdir dir-a 707 | svn propset svn:ignore 'ignore-a' dir-a 708 | svn commit -m 'add dir-a' 709 | svn mkdir dir-a/subdir-a 710 | svn commit -m 'add dir-a/subdir-a' 711 | 712 | cd "$TEST_TEMP_DIR" 713 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 714 | create repository git-repo 715 | end repository 716 | 717 | match /project-a/ 718 | repository git-repo 719 | branch master 720 | end match 721 | ") 722 | 723 | assert git -C git-repo show master:dir-a/.gitignore 724 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 725 | } 726 | 727 | @test 'adding first directory to an empty directory and at the same time adding ignores should not remove .gitignore with empty-dirs-parameter and svn-ignore-parameter' { 728 | svn mkdir dir-a 729 | svn commit -m 'add dir-a' 730 | svn mkdir dir-a/subdir-a 731 | svn propset svn:ignore 'ignore-a' dir-a 732 | svn commit -m 'add dir-a/subdir-a and ignores' 733 | 734 | cd "$TEST_TEMP_DIR" 735 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 736 | create repository git-repo 737 | end repository 738 | 739 | match / 740 | repository git-repo 741 | branch master 742 | end match 743 | ") 744 | 745 | assert git -C git-repo show master:dir-a/.gitignore 746 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 747 | } 748 | 749 | @test 'adding first directory to an empty directory and at the same time adding ignores should not remove .gitignore with empty-dirs-parameter and svn-ignore-parameter (nested)' { 750 | svn mkdir project-a 751 | cd project-a 752 | svn mkdir dir-a 753 | svn commit -m 'add dir-a' 754 | svn mkdir dir-a/subdir-a 755 | svn propset svn:ignore 'ignore-a' dir-a 756 | svn commit -m 'add dir-a/subdir-a and ignores' 757 | 758 | cd "$TEST_TEMP_DIR" 759 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 760 | create repository git-repo 761 | end repository 762 | 763 | match /project-a/ 764 | repository git-repo 765 | branch master 766 | end match 767 | ") 768 | 769 | assert git -C git-repo show master:dir-a/.gitignore 770 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 771 | } 772 | 773 | @test 'deleting last directory from a directory should not add empty .gitignore with empty-dirs-parameter and svn-ignore-parameter if there is an svn:ignore property' { 774 | svn mkdir --parents dir-a/subdir-a 775 | svn commit -m 'add dir-a/subdir-a' 776 | svn propset svn:ignore 'ignore-a' dir-a 777 | svn commit -m 'ignore ignore-a on dir-a' 778 | svn rm dir-a/subdir-a 779 | svn commit -m 'delete dir-a/subdir-a' 780 | 781 | cd "$TEST_TEMP_DIR" 782 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 783 | create repository git-repo 784 | end repository 785 | 786 | match / 787 | repository git-repo 788 | branch master 789 | end match 790 | ") 791 | 792 | refute git -C git-repo show master:.gitignore 793 | assert git -C git-repo show master:dir-a/.gitignore 794 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 795 | } 796 | 797 | @test 'deleting last directory from a directory should not add empty .gitignore with empty-dirs-parameter and svn-ignore-parameter if there is an svn:ignore property (nested)' { 798 | svn mkdir project-a 799 | cd project-a 800 | svn mkdir --parents dir-a/subdir-a 801 | svn commit -m 'add dir-a/subdir-a' 802 | svn propset svn:ignore 'ignore-a' dir-a 803 | svn commit -m 'ignore ignore-a on dir-a' 804 | svn rm dir-a/subdir-a 805 | svn commit -m 'delete dir-a/subdir-a' 806 | 807 | cd "$TEST_TEMP_DIR" 808 | svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo " 809 | create repository git-repo 810 | end repository 811 | 812 | match /project-a/ 813 | repository git-repo 814 | branch master 815 | end match 816 | ") 817 | 818 | refute git -C git-repo show master:.gitignore 819 | assert git -C git-repo show master:dir-a/.gitignore 820 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 821 | } 822 | 823 | @test 'deleting last directory from root should not add empty .gitignore with empty-dirs-parameter' { 824 | svn mkdir dir-a 825 | svn commit -m 'add dir-a' 826 | svn rm dir-a 827 | svn commit -m 'delete dir-a' 828 | 829 | cd "$TEST_TEMP_DIR" 830 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 831 | create repository git-repo 832 | end repository 833 | 834 | match / 835 | repository git-repo 836 | branch master 837 | end match 838 | ") 839 | 840 | refute git -C git-repo show master:.gitignore 841 | refute git -C git-repo show master:dir-a/.gitignore 842 | } 843 | 844 | @test 'deleting last directory from root should not add empty .gitignore with empty-dirs-parameter (nested)' { 845 | svn mkdir project-a 846 | cd project-a 847 | svn mkdir dir-a 848 | svn commit -m 'add dir-a' 849 | svn rm dir-a 850 | svn commit -m 'delete dir-a' 851 | 852 | cd "$TEST_TEMP_DIR" 853 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 854 | create repository git-repo 855 | end repository 856 | 857 | match /project-a/ 858 | repository git-repo 859 | branch master 860 | end match 861 | ") 862 | 863 | refute git -C git-repo show master:.gitignore 864 | refute git -C git-repo show master:dir-a/.gitignore 865 | } 866 | 867 | @test 'copying an empty directory should put empty .gitignore file to copy with empty-dirs parameter' { 868 | svn mkdir dir-a 869 | svn commit -m 'add dir-a' 870 | svn cp dir-a dir-b 871 | svn commit -m 'copy dir-a to dir-b' 872 | 873 | cd "$TEST_TEMP_DIR" 874 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 875 | create repository git-repo 876 | end repository 877 | 878 | match / 879 | repository git-repo 880 | branch master 881 | end match 882 | ") 883 | 884 | assert git -C git-repo show master:dir-a/.gitignore 885 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 886 | assert git -C git-repo show master:dir-b/.gitignore 887 | assert_equal "$(git -C git-repo show master:dir-b/.gitignore)" '' 888 | } 889 | 890 | @test 'copying an empty directory should put empty .gitignore file to copy with empty-dirs parameter (nested)' { 891 | svn mkdir project-a 892 | cd project-a 893 | svn mkdir dir-a 894 | svn commit -m 'add dir-a' 895 | svn cp dir-a dir-b 896 | svn commit -m 'copy dir-a to dir-b' 897 | 898 | cd "$TEST_TEMP_DIR" 899 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 900 | create repository git-repo 901 | end repository 902 | 903 | match /project-a/ 904 | repository git-repo 905 | branch master 906 | end match 907 | ") 908 | 909 | assert git -C git-repo show master:dir-a/.gitignore 910 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 911 | assert git -C git-repo show master:dir-b/.gitignore 912 | assert_equal "$(git -C git-repo show master:dir-b/.gitignore)" '' 913 | } 914 | 915 | @test 'copying a directory with empty sub-dirs should put empty .gitignore files to empty directories with empty-dirs parameter' { 916 | svn mkdir --parents dir-a/subdir-a 917 | svn commit -m 'add dir-a/subdir-a' 918 | svn cp dir-a dir-b 919 | svn commit -m 'copy dir-a to dir-b' 920 | 921 | cd "$TEST_TEMP_DIR" 922 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 923 | create repository git-repo 924 | end repository 925 | 926 | match / 927 | repository git-repo 928 | branch master 929 | end match 930 | ") 931 | 932 | assert git -C git-repo show master:dir-a/subdir-a/.gitignore 933 | assert_equal "$(git -C git-repo show master:dir-a/subdir-a/.gitignore)" '' 934 | assert git -C git-repo show master:dir-b/subdir-a/.gitignore 935 | assert_equal "$(git -C git-repo show master:dir-b/subdir-a/.gitignore)" '' 936 | } 937 | 938 | @test 'copying a directory with empty sub-dirs should put empty .gitignore files to empty directories with empty-dirs parameter (nested)' { 939 | svn mkdir project-a 940 | cd project-a 941 | svn mkdir --parents dir-a/subdir-a 942 | svn commit -m 'add dir-a/subdir-a' 943 | svn cp dir-a dir-b 944 | svn commit -m 'copy dir-a to dir-b' 945 | 946 | cd "$TEST_TEMP_DIR" 947 | svn2git "$SVN_REPO" --empty-dirs --rules <(echo " 948 | create repository git-repo 949 | end repository 950 | 951 | match /project-a/ 952 | repository git-repo 953 | branch master 954 | end match 955 | ") 956 | 957 | assert git -C git-repo show master:dir-a/subdir-a/.gitignore 958 | assert_equal "$(git -C git-repo show master:dir-a/subdir-a/.gitignore)" '' 959 | assert git -C git-repo show master:dir-b/subdir-a/.gitignore 960 | assert_equal "$(git -C git-repo show master:dir-b/subdir-a/.gitignore)" '' 961 | } 962 | 963 | @test 'branching with svn-branches and empty-dirs parameter should put empty .gitignore files to empty directories' { 964 | svn mkdir --parents trunk/dir-a 965 | svn commit -m 'add trunk/dir-a' 966 | svn mkdir branches 967 | svn cp trunk branches/branch-a 968 | svn commit -m 'create branch-a' 969 | 970 | cd "$TEST_TEMP_DIR" 971 | svn2git "$SVN_REPO" --empty-dirs --svn-branches --rules <(echo " 972 | create repository git-repo 973 | end repository 974 | 975 | match /trunk/ 976 | repository git-repo 977 | branch master 978 | end match 979 | 980 | match /branches/$ 981 | action recurse 982 | end match 983 | 984 | match /branches/([^/]+)/ 985 | repository git-repo 986 | branch \1 987 | end match 988 | ") 989 | 990 | assert git -C git-repo show master:dir-a/.gitignore 991 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 992 | assert git -C git-repo show branch-a:dir-a/.gitignore 993 | assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" '' 994 | } 995 | 996 | @test 'branching with svn-branches and empty-dirs parameter should put empty .gitignore files to empty directories (nested)' { 997 | svn mkdir project-a 998 | cd project-a 999 | svn mkdir --parents trunk/dir-a 1000 | svn commit -m 'add trunk/dir-a' 1001 | svn mkdir branches 1002 | svn cp trunk branches/branch-a 1003 | svn commit -m 'create branch-a' 1004 | 1005 | cd "$TEST_TEMP_DIR" 1006 | svn2git "$SVN_REPO" --empty-dirs --svn-branches --rules <(echo " 1007 | create repository git-repo 1008 | end repository 1009 | 1010 | match /project-a/trunk/ 1011 | repository git-repo 1012 | branch master 1013 | end match 1014 | 1015 | match /project-a/branches/([^/]+)/ 1016 | repository git-repo 1017 | branch \1 1018 | end match 1019 | 1020 | match /project-a/(branches/)?$ 1021 | action recurse 1022 | end match 1023 | ") 1024 | 1025 | assert git -C git-repo show master:dir-a/.gitignore 1026 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 1027 | assert git -C git-repo show branch-a:dir-a/.gitignore 1028 | assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" '' 1029 | } 1030 | 1031 | @test 'branching with svn-ignore, svn-branches and empty-dirs parameter should not replace filled .gitignore files with empty ones' { 1032 | svn mkdir --parents trunk/dir-a 1033 | svn propset svn:ignore 'ignore-a' trunk/dir-a 1034 | svn commit -m 'add trunk/dir-a' 1035 | svn mkdir branches 1036 | svn cp trunk branches/branch-a 1037 | svn commit -m 'create branch-a' 1038 | 1039 | cd "$TEST_TEMP_DIR" 1040 | svn2git "$SVN_REPO" --empty-dirs --svn-branches --svn-ignore --rules <(echo " 1041 | create repository git-repo 1042 | end repository 1043 | 1044 | match /trunk/ 1045 | repository git-repo 1046 | branch master 1047 | end match 1048 | 1049 | match /branches/$ 1050 | action recurse 1051 | end match 1052 | 1053 | match /branches/([^/]+)/ 1054 | repository git-repo 1055 | branch \1 1056 | end match 1057 | ") 1058 | 1059 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 1060 | assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" '/ignore-a' 1061 | } 1062 | 1063 | @test 'branching with svn-ignore, svn-branches and empty-dirs parameter should not replace filled .gitignore files with empty ones (nested)' { 1064 | svn mkdir project-a 1065 | cd project-a 1066 | svn mkdir --parents trunk/dir-a 1067 | svn propset svn:ignore 'ignore-a' trunk/dir-a 1068 | svn commit -m 'add trunk/dir-a' 1069 | svn mkdir branches 1070 | svn cp trunk branches/branch-a 1071 | svn commit -m 'create branch-a' 1072 | 1073 | cd "$TEST_TEMP_DIR" 1074 | svn2git "$SVN_REPO" --empty-dirs --svn-branches --svn-ignore --rules <(echo " 1075 | create repository git-repo 1076 | end repository 1077 | 1078 | match /project-a/trunk/ 1079 | repository git-repo 1080 | branch master 1081 | end match 1082 | 1083 | match /project-a/branches/([^/]+)/ 1084 | repository git-repo 1085 | branch \1 1086 | end match 1087 | 1088 | match /project-a/(branches/)?$ 1089 | action recurse 1090 | end match 1091 | ") 1092 | 1093 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 1094 | assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" '/ignore-a' 1095 | } 1096 | -------------------------------------------------------------------------------- /test/svn-ignore.bats: -------------------------------------------------------------------------------- 1 | load 'common' 2 | 3 | @test 'svn:ignore entries should only ignore matching direct children' { 4 | svn mkdir dir-a 5 | svn commit -m 'add dir-a' 6 | svn update 7 | svn propset svn:ignore $'ignore-a\nignore-b' dir-a 8 | svn commit -m 'ignore ignore-a and ignore-b on dir-a' 9 | 10 | cd "$TEST_TEMP_DIR" 11 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 12 | create repository git-repo 13 | end repository 14 | 15 | match / 16 | repository git-repo 17 | branch master 18 | end match 19 | ") 20 | 21 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" "$(cat <<-EOF 22 | /ignore-a 23 | /ignore-b 24 | EOF 25 | )" 26 | } 27 | 28 | @test 'svn:ignore entries should only ignore matching direct children (nested)' { 29 | svn mkdir project-a 30 | cd project-a 31 | svn mkdir dir-a 32 | svn commit -m 'add dir-a' 33 | svn update 34 | svn propset svn:ignore $'ignore-a\nignore-b' dir-a 35 | svn commit -m 'ignore ignore-a and ignore-b on dir-a' 36 | 37 | cd "$TEST_TEMP_DIR" 38 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 39 | create repository git-repo 40 | end repository 41 | 42 | match /project-a/ 43 | repository git-repo 44 | branch master 45 | end match 46 | ") 47 | 48 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" "$(cat <<-EOF 49 | /ignore-a 50 | /ignore-b 51 | EOF 52 | )" 53 | } 54 | 55 | @test 'svn:global-ignores entries should ignore all matching descendents' { 56 | svn mkdir dir-a 57 | svn commit -m 'add dir-a' 58 | svn update 59 | svn propset svn:global-ignores $'ignore-a\nignore-b' dir-a 60 | svn commit -m 'ignore ignore-a and ignore-b on dir-a and descendents' 61 | 62 | cd "$TEST_TEMP_DIR" 63 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 64 | create repository git-repo 65 | end repository 66 | 67 | match / 68 | repository git-repo 69 | branch master 70 | end match 71 | ") 72 | 73 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" "$(cat <<-EOF 74 | ignore-a 75 | ignore-b 76 | EOF 77 | )" 78 | } 79 | 80 | @test 'svn:global-ignores entries should ignore all matching descendents (nested)' { 81 | svn mkdir project-a 82 | cd project-a 83 | svn mkdir dir-a 84 | svn commit -m 'add dir-a' 85 | svn update 86 | svn propset svn:global-ignores $'ignore-a\nignore-b' dir-a 87 | svn commit -m 'ignore ignore-a and ignore-b on dir-a and descendents' 88 | 89 | cd "$TEST_TEMP_DIR" 90 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 91 | create repository git-repo 92 | end repository 93 | 94 | match /project-a/ 95 | repository git-repo 96 | branch master 97 | end match 98 | ") 99 | 100 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" "$(cat <<-EOF 101 | ignore-a 102 | ignore-b 103 | EOF 104 | )" 105 | } 106 | 107 | @test 'svn-ignore translation should be done if svn-branches parameter is used' { 108 | svn mkdir trunk 109 | svn commit -m 'create trunk' 110 | svn propset svn:ignore $'ignore-a\nignore-b' trunk 111 | svn commit -m 'ignore ignore-a and ignore-b on root' 112 | svn propset svn:global-ignores 'ignore-c' trunk 113 | svn commit -m 'ignore ignore-c everywhere' 114 | svn mkdir branches 115 | svn copy trunk branches/branch-a 116 | svn commit -m 'create branch branch-a' 117 | 118 | cd "$TEST_TEMP_DIR" 119 | svn2git "$SVN_REPO" --svn-ignore --svn-branches --rules <(echo " 120 | create repository git-repo 121 | end repository 122 | 123 | match /trunk/ 124 | repository git-repo 125 | branch master 126 | end match 127 | 128 | match /branches/$ 129 | action recurse 130 | end match 131 | 132 | match /branches/([^/]+)/ 133 | repository git-repo 134 | branch \1 135 | end match 136 | ") 137 | 138 | assert_equal "$(git -C git-repo show master:.gitignore)" "$(cat <<-EOF 139 | /ignore-a 140 | /ignore-b 141 | ignore-c 142 | EOF 143 | )" 144 | assert_equal "$(git -C git-repo show branch-a:.gitignore)" "$(cat <<-EOF 145 | /ignore-a 146 | /ignore-b 147 | ignore-c 148 | EOF 149 | )" 150 | } 151 | 152 | @test 'svn-ignore translation should be done if svn-branches parameter is used (nested)' { 153 | svn mkdir project-a 154 | cd project-a 155 | svn mkdir trunk 156 | svn commit -m 'create trunk' 157 | svn propset svn:ignore $'ignore-a\nignore-b' trunk 158 | svn commit -m 'ignore ignore-a and ignore-b on root' 159 | svn propset svn:global-ignores 'ignore-c' trunk 160 | svn commit -m 'ignore ignore-c everywhere' 161 | svn mkdir branches 162 | svn copy trunk branches/branch-a 163 | svn commit -m 'create branch branch-a' 164 | 165 | cd "$TEST_TEMP_DIR" 166 | svn2git "$SVN_REPO" --svn-ignore --svn-branches --rules <(echo " 167 | create repository git-repo 168 | end repository 169 | 170 | match /project-a/trunk/ 171 | repository git-repo 172 | branch master 173 | end match 174 | 175 | match /project-a/branches/([^/]+)/ 176 | repository git-repo 177 | branch \1 178 | end match 179 | 180 | match /project-a/(branches/)?$ 181 | action recurse 182 | end match 183 | ") 184 | 185 | assert_equal "$(git -C git-repo show master:.gitignore)" "$(cat <<-EOF 186 | /ignore-a 187 | /ignore-b 188 | ignore-c 189 | EOF 190 | )" 191 | assert_equal "$(git -C git-repo show branch-a:.gitignore)" "$(cat <<-EOF 192 | /ignore-a 193 | /ignore-b 194 | ignore-c 195 | EOF 196 | )" 197 | } 198 | 199 | @test 'svn-ignore translation should be done transitively when copying a directory' { 200 | svn mkdir --parents dir-a/subdir-a 201 | svn commit -m 'add dir-a/subdir-a' 202 | svn propset svn:ignore $'ignore-a\nignore-b' dir-a/subdir-a 203 | svn commit -m 'ignore ignore-a and ignore-b on dir-a/subdir-a' 204 | svn propset svn:global-ignores 'ignore-c' dir-a/subdir-a 205 | svn commit -m 'ignore ignore-c on dir-a/subdir-a and descendents' 206 | svn copy dir-a dir-b 207 | svn commit -m 'copy dir-a to dir-b' 208 | 209 | cd "$TEST_TEMP_DIR" 210 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 211 | create repository git-repo 212 | end repository 213 | 214 | match / 215 | repository git-repo 216 | branch master 217 | end match 218 | ") 219 | 220 | assert_equal "$(git -C git-repo show master:dir-a/subdir-a/.gitignore)" "$(cat <<-EOF 221 | /ignore-a 222 | /ignore-b 223 | ignore-c 224 | EOF 225 | )" 226 | assert_equal "$(git -C git-repo show master:dir-b/subdir-a/.gitignore)" "$(cat <<-EOF 227 | /ignore-a 228 | /ignore-b 229 | ignore-c 230 | EOF 231 | )" 232 | } 233 | 234 | @test 'svn-ignore translation should be done transitively when copying a directory (nested)' { 235 | svn mkdir project-a 236 | cd project-a 237 | svn mkdir --parents dir-a/subdir-a 238 | svn commit -m 'add dir-a/subdir-a' 239 | svn propset svn:ignore $'ignore-a\nignore-b' dir-a/subdir-a 240 | svn commit -m 'ignore ignore-a and ignore-b on dir-a/subdir-a' 241 | svn propset svn:global-ignores 'ignore-c' dir-a/subdir-a 242 | svn commit -m 'ignore ignore-c on dir-a/subdir-a and descendents' 243 | svn copy dir-a dir-b 244 | svn commit -m 'copy dir-a to dir-b' 245 | 246 | cd "$TEST_TEMP_DIR" 247 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 248 | create repository git-repo 249 | end repository 250 | 251 | match /project-a/ 252 | repository git-repo 253 | branch master 254 | end match 255 | ") 256 | 257 | assert_equal "$(git -C git-repo show master:dir-a/subdir-a/.gitignore)" "$(cat <<-EOF 258 | /ignore-a 259 | /ignore-b 260 | ignore-c 261 | EOF 262 | )" 263 | assert_equal "$(git -C git-repo show master:dir-b/subdir-a/.gitignore)" "$(cat <<-EOF 264 | /ignore-a 265 | /ignore-b 266 | ignore-c 267 | EOF 268 | )" 269 | } 270 | 271 | @test 'svn-ignore parameter should not cause added directories to be dumped multiple times' { 272 | svn mkdir dir-a 273 | echo content-a >dir-a/file-a 274 | svn add dir-a/file-a 275 | svn commit -m 'add dir-a/file-a' 276 | 277 | cd "$TEST_TEMP_DIR" 278 | svn2git "$SVN_REPO" --svn-ignore --create-dump --rules <(echo " 279 | create repository git-repo 280 | end repository 281 | 282 | match / 283 | repository git-repo 284 | branch master 285 | end match 286 | ") 287 | 288 | assert [ "$(grep -c '^M .* dir-a/file-a$' git-repo.fi)" -eq 1 ] 289 | } 290 | 291 | @test 'svn-ignore parameter should not cause added directories to be dumped multiple times (nested)' { 292 | svn mkdir project-a 293 | cd project-a 294 | svn mkdir dir-a 295 | echo content-a >dir-a/file-a 296 | svn add dir-a/file-a 297 | svn commit -m 'add dir-a/file-a' 298 | 299 | cd "$TEST_TEMP_DIR" 300 | svn2git "$SVN_REPO" --svn-ignore --create-dump --rules <(echo " 301 | create repository git-repo 302 | end repository 303 | 304 | match /project-a/ 305 | repository git-repo 306 | branch master 307 | end match 308 | ") 309 | 310 | assert [ "$(grep -c '^M .* dir-a/file-a$' git-repo.fi)" -eq 1 ] 311 | } 312 | 313 | @test 'svn-ignore translation should not delete unrelated files' { 314 | svn mkdir dir-a 315 | echo content-a >dir-a/file-a 316 | svn add dir-a/file-a 317 | svn commit -m 'add dir-a/file-a' 318 | svn update 319 | svn propset svn:ignore 'ignore-a' dir-a 320 | svn commit -m 'ignore ignore-a on dir-a' 321 | 322 | cd "$TEST_TEMP_DIR" 323 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 324 | create repository git-repo 325 | end repository 326 | 327 | match / 328 | repository git-repo 329 | branch master 330 | end match 331 | ") 332 | 333 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 334 | assert git -C git-repo show master:dir-a/file-a 335 | } 336 | 337 | @test 'svn-ignore translation should not delete unrelated files (nested)' { 338 | svn mkdir project-a 339 | cd project-a 340 | svn mkdir dir-a 341 | echo content-a >dir-a/file-a 342 | svn add dir-a/file-a 343 | svn commit -m 'add dir-a/file-a' 344 | svn update 345 | svn propset svn:ignore 'ignore-a' dir-a 346 | svn commit -m 'ignore ignore-a on dir-a' 347 | 348 | cd "$TEST_TEMP_DIR" 349 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 350 | create repository git-repo 351 | end repository 352 | 353 | match /project-a/ 354 | repository git-repo 355 | branch master 356 | end match 357 | ") 358 | 359 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 360 | assert git -C git-repo show master:dir-a/file-a 361 | } 362 | 363 | @test 'svn-ignore translation should be done properly on the root directory' { 364 | svn propset svn:ignore $'ignore-a\nignore-b' . 365 | svn commit -m 'ignore ignore-a and ignore-b on root' 366 | svn propset svn:global-ignores 'ignore-c' . 367 | svn commit -m 'ignore ignore-c on root and descendents' 368 | 369 | cd "$TEST_TEMP_DIR" 370 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 371 | create repository git-repo 372 | end repository 373 | 374 | match / 375 | repository git-repo 376 | branch master 377 | end match 378 | ") 379 | 380 | assert_equal "$(git -C git-repo show master:.gitignore)" "$(cat <<-EOF 381 | /ignore-a 382 | /ignore-b 383 | ignore-c 384 | EOF 385 | )" 386 | } 387 | 388 | @test 'svn-ignore translation should be done properly on the root directory (nested)' { 389 | svn mkdir project-a 390 | cd project-a 391 | svn propset svn:ignore $'ignore-a\nignore-b' . 392 | svn commit -m 'ignore ignore-a and ignore-b on root' 393 | svn propset svn:global-ignores 'ignore-c' . 394 | svn commit -m 'ignore ignore-c on root and descendents' 395 | 396 | cd "$TEST_TEMP_DIR" 397 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 398 | create repository git-repo 399 | end repository 400 | 401 | match /project-a/ 402 | repository git-repo 403 | branch master 404 | end match 405 | ") 406 | 407 | assert_equal "$(git -C git-repo show master:.gitignore)" "$(cat <<-EOF 408 | /ignore-a 409 | /ignore-b 410 | ignore-c 411 | EOF 412 | )" 413 | } 414 | 415 | @test 'gitignore file should be removed if all svn-ignores are removed' { 416 | svn mkdir dir-a 417 | svn propset svn:ignore 'ignore-a' dir-a 418 | svn commit -m 'add dir-a' 419 | svn propset svn:ignore '' dir-a 420 | svn commit -m 'unignore ignore-a on dir-a' 421 | 422 | cd "$TEST_TEMP_DIR" 423 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 424 | create repository git-repo 425 | end repository 426 | 427 | match / 428 | repository git-repo 429 | branch master 430 | end match 431 | ") 432 | 433 | refute git -C git-repo show master:dir-a/.gitignore 434 | } 435 | 436 | @test 'gitignore file should be removed if all svn-ignores are removed (nested)' { 437 | svn mkdir project-a 438 | cd project-a 439 | svn mkdir dir-a 440 | svn propset svn:ignore 'ignore-a' dir-a 441 | svn commit -m 'add dir-a' 442 | svn propset svn:ignore '' dir-a 443 | svn commit -m 'unignore ignore-a on dir-a' 444 | 445 | cd "$TEST_TEMP_DIR" 446 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 447 | create repository git-repo 448 | end repository 449 | 450 | match /project-a/ 451 | repository git-repo 452 | branch master 453 | end match 454 | ") 455 | 456 | refute git -C git-repo show master:dir-a/.gitignore 457 | } 458 | 459 | @test 'gitignore file should be removed if svn-ignore property is deleted' { 460 | svn mkdir dir-a 461 | svn propset svn:ignore 'ignore-a' dir-a 462 | svn commit -m 'add dir-a' 463 | svn propdel svn:ignore dir-a 464 | svn commit -m 'unignore ignore-a on dir-a' 465 | 466 | cd "$TEST_TEMP_DIR" 467 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 468 | create repository git-repo 469 | end repository 470 | 471 | match / 472 | repository git-repo 473 | branch master 474 | end match 475 | ") 476 | 477 | refute git -C git-repo show master:dir-a/.gitignore 478 | } 479 | 480 | @test 'gitignore file should be removed if svn-ignore property is deleted (nested)' { 481 | svn mkdir project-a 482 | cd project-a 483 | svn mkdir dir-a 484 | svn propset svn:ignore 'ignore-a' dir-a 485 | svn commit -m 'add dir-a' 486 | svn propdel svn:ignore dir-a 487 | svn commit -m 'unignore ignore-a on dir-a' 488 | 489 | cd "$TEST_TEMP_DIR" 490 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 491 | create repository git-repo 492 | end repository 493 | 494 | match /project-a/ 495 | repository git-repo 496 | branch master 497 | end match 498 | ") 499 | 500 | refute git -C git-repo show master:dir-a/.gitignore 501 | } 502 | 503 | @test 'gitignore file should be removed if all svn-global-ignores are removed' { 504 | svn mkdir dir-a 505 | svn propset svn:global-ignores 'ignore-a' dir-a 506 | svn commit -m 'add dir-a' 507 | svn propset svn:global-ignores '' dir-a 508 | svn commit -m 'unignore ignore-a on dir-a and descendents' 509 | 510 | cd "$TEST_TEMP_DIR" 511 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 512 | create repository git-repo 513 | end repository 514 | 515 | match / 516 | repository git-repo 517 | branch master 518 | end match 519 | ") 520 | 521 | refute git -C git-repo show master:dir-a/.gitignore 522 | } 523 | 524 | @test 'gitignore file should be removed if all svn-global-ignores are removed (nested)' { 525 | svn mkdir project-a 526 | cd project-a 527 | svn mkdir dir-a 528 | svn propset svn:global-ignores 'ignore-a' dir-a 529 | svn commit -m 'add dir-a' 530 | svn propset svn:global-ignores '' dir-a 531 | svn commit -m 'unignore ignore-a on dir-a and descendents' 532 | 533 | cd "$TEST_TEMP_DIR" 534 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 535 | create repository git-repo 536 | end repository 537 | 538 | match /project-a/ 539 | repository git-repo 540 | branch master 541 | end match 542 | ") 543 | 544 | refute git -C git-repo show master:dir-a/.gitignore 545 | } 546 | 547 | @test 'gitignore file should be removed if global-ignores property is deleted' { 548 | svn mkdir dir-a 549 | svn propset svn:global-ignores 'ignore-a' dir-a 550 | svn commit -m 'add dir-a' 551 | svn propdel svn:global-ignores dir-a 552 | svn commit -m 'unignore ignore-a on dir-a and descendents' 553 | 554 | cd "$TEST_TEMP_DIR" 555 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 556 | create repository git-repo 557 | end repository 558 | 559 | match / 560 | repository git-repo 561 | branch master 562 | end match 563 | ") 564 | 565 | refute git -C git-repo show master:dir-a/.gitignore 566 | } 567 | 568 | @test 'gitignore file should be removed if global-ignores property is deleted (nested)' { 569 | svn mkdir project-a 570 | cd project-a 571 | svn mkdir dir-a 572 | svn propset svn:global-ignores 'ignore-a' dir-a 573 | svn commit -m 'add dir-a' 574 | svn propdel svn:global-ignores dir-a 575 | svn commit -m 'unignore ignore-a on dir-a and descendents' 576 | 577 | cd "$TEST_TEMP_DIR" 578 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 579 | create repository git-repo 580 | end repository 581 | 582 | match /project-a/ 583 | repository git-repo 584 | branch master 585 | end match 586 | ") 587 | 588 | refute git -C git-repo show master:dir-a/.gitignore 589 | } 590 | 591 | @test 'gitignore file should not be removed if global-ignores property is deleted but svn-ignore property is still present' { 592 | svn mkdir dir-a 593 | svn propset svn:ignore 'ignore-a' dir-a 594 | svn propset svn:global-ignores 'ignore-b' dir-a 595 | svn commit -m 'add dir-a' 596 | svn propdel svn:global-ignores dir-a 597 | svn commit -m 'unignore ignore-b on dir-a and descendents' 598 | 599 | cd "$TEST_TEMP_DIR" 600 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 601 | create repository git-repo 602 | end repository 603 | 604 | match / 605 | repository git-repo 606 | branch master 607 | end match 608 | ") 609 | 610 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 611 | } 612 | 613 | @test 'gitignore file should not be removed if global-ignores property is deleted but svn-ignore property is still present (nested)' { 614 | svn mkdir project-a 615 | cd project-a 616 | svn mkdir dir-a 617 | svn propset svn:ignore 'ignore-a' dir-a 618 | svn propset svn:global-ignores 'ignore-b' dir-a 619 | svn commit -m 'add dir-a' 620 | svn propdel svn:global-ignores dir-a 621 | svn commit -m 'unignore ignore-b on dir-a and descendents' 622 | 623 | cd "$TEST_TEMP_DIR" 624 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 625 | create repository git-repo 626 | end repository 627 | 628 | match /project-a/ 629 | repository git-repo 630 | branch master 631 | end match 632 | ") 633 | 634 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a' 635 | } 636 | 637 | @test 'gitignore file should not be removed if svn-ignore property is deleted but global-ignores property is still present' { 638 | svn mkdir dir-a 639 | svn propset svn:ignore 'ignore-a' dir-a 640 | svn propset svn:global-ignores 'ignore-b' dir-a 641 | svn commit -m 'add dir-a' 642 | svn propdel svn:ignore dir-a 643 | svn commit -m 'unignore ignore-a on dir-a' 644 | 645 | cd "$TEST_TEMP_DIR" 646 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 647 | create repository git-repo 648 | end repository 649 | 650 | match / 651 | repository git-repo 652 | branch master 653 | end match 654 | ") 655 | 656 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" 'ignore-b' 657 | } 658 | 659 | @test 'gitignore file should not be removed if svn-ignore property is deleted but global-ignores property is still present (nested)' { 660 | svn mkdir project-a 661 | cd project-a 662 | svn mkdir dir-a 663 | svn propset svn:ignore 'ignore-a' dir-a 664 | svn propset svn:global-ignores 'ignore-b' dir-a 665 | svn commit -m 'add dir-a' 666 | svn propdel svn:ignore dir-a 667 | svn commit -m 'unignore ignore-a on dir-a' 668 | 669 | cd "$TEST_TEMP_DIR" 670 | svn2git "$SVN_REPO" --svn-ignore --rules <(echo " 671 | create repository git-repo 672 | end repository 673 | 674 | match /project-a/ 675 | repository git-repo 676 | branch master 677 | end match 678 | ") 679 | 680 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" 'ignore-b' 681 | } 682 | 683 | @test 'gitignore file should remain empty if svn-ignore property is deleted but empty-dirs is used' { 684 | svn mkdir dir-a 685 | svn propset svn:ignore 'ignore-a' dir-a 686 | svn commit -m 'add dir-a' 687 | svn propdel svn:ignore dir-a 688 | svn commit -m 'unignore ignore-a on dir-a' 689 | 690 | cd "$TEST_TEMP_DIR" 691 | svn2git "$SVN_REPO" --svn-ignore --empty-dirs --rules <(echo " 692 | create repository git-repo 693 | end repository 694 | 695 | match / 696 | repository git-repo 697 | branch master 698 | end match 699 | ") 700 | 701 | assert git -C git-repo show master:dir-a/.gitignore 702 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 703 | } 704 | 705 | @test 'gitignore file should remain empty if svn-ignore property is deleted but empty-dirs is used (nested)' { 706 | svn mkdir project-a 707 | cd project-a 708 | svn mkdir dir-a 709 | svn propset svn:ignore 'ignore-a' dir-a 710 | svn commit -m 'add dir-a' 711 | svn propdel svn:ignore dir-a 712 | svn commit -m 'unignore ignore-a on dir-a' 713 | 714 | cd "$TEST_TEMP_DIR" 715 | svn2git "$SVN_REPO" --svn-ignore --empty-dirs --rules <(echo " 716 | create repository git-repo 717 | end repository 718 | 719 | match /project-a/ 720 | repository git-repo 721 | branch master 722 | end match 723 | ") 724 | 725 | assert git -C git-repo show master:dir-a/.gitignore 726 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 727 | } 728 | 729 | @test 'gitignore file should remain empty if global-ignores property is deleted but empty-dirs is used' { 730 | svn mkdir dir-a 731 | svn propset svn:global-ignores 'ignore-a' dir-a 732 | svn commit -m 'add dir-a' 733 | svn propdel svn:global-ignores dir-a 734 | svn commit -m 'unignore ignore-a on dir-a and descendents' 735 | 736 | cd "$TEST_TEMP_DIR" 737 | svn2git "$SVN_REPO" --svn-ignore --empty-dirs --rules <(echo " 738 | create repository git-repo 739 | end repository 740 | 741 | match / 742 | repository git-repo 743 | branch master 744 | end match 745 | ") 746 | 747 | assert git -C git-repo show master:dir-a/.gitignore 748 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 749 | } 750 | 751 | @test 'gitignore file should remain empty if global-ignores property is deleted but empty-dirs is used (nested)' { 752 | svn mkdir project-a 753 | cd project-a 754 | svn mkdir dir-a 755 | svn propset svn:global-ignores 'ignore-a' dir-a 756 | svn commit -m 'add dir-a' 757 | svn propdel svn:global-ignores dir-a 758 | svn commit -m 'unignore ignore-a on dir-a and descendents' 759 | 760 | cd "$TEST_TEMP_DIR" 761 | svn2git "$SVN_REPO" --svn-ignore --empty-dirs --rules <(echo " 762 | create repository git-repo 763 | end repository 764 | 765 | match /project-a/ 766 | repository git-repo 767 | branch master 768 | end match 769 | ") 770 | 771 | assert git -C git-repo show master:dir-a/.gitignore 772 | assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '' 773 | } 774 | --------------------------------------------------------------------------------