pax_global_header00006660000000000000000000000064137042654510014521gustar00rootroot0000000000000052 comment=00619c9315af6b7dab30ac7474fad917a815f591 patchutils-0.4.2/000077500000000000000000000000001370426545100137045ustar00rootroot00000000000000patchutils-0.4.2/.gitattributes000066400000000000000000000000401370426545100165710ustar00rootroot00000000000000ChangeLog merge=merge-changelog patchutils-0.4.2/.gitignore000066400000000000000000000013171370426545100156760ustar00rootroot00000000000000/Makefile.in /Makefile /configure /config.status /config.log /config.h* /autom4te.cache /aclocal.m4 /missing /compile /depcomp /install-sh /mkinstalldirs /INSTALL /stamp-h1 .deps .dirstamp # Compiled objects *.o src/combinediff src/filterdiff src/flipdiff src/grepdiff src/interdiff src/lsdiff src/rediff src/patchview # These are generated from *.in files /patchutils.spec /scripts/dehtmldiff /scripts/editdiff /scripts/espdiff /scripts/fixcvsdiff /scripts/recountdiff /scripts/splitdiff /scripts/unwrapdiff # These are generated from the XML file. doc/*.1 # Tests /test-arena /test-driver /test-suite.log /tests/*/run-test.log /tests/*/run-test.trs # Backup files *.bak *~ *.swp # Tarballs patchutils-*.tar.?z* patchutils-0.4.2/.travis.yml000066400000000000000000000001511370426545100160120ustar00rootroot00000000000000language: c compiler: gcc os: linux script: ./bootstrap && ./configure && make distcheck patchutils-0.4.2/AUTHORS000066400000000000000000000004151370426545100147540ustar00rootroot00000000000000Tim Waugh - Maintainer, main author. Marko Kreen - Merged interdiff and extractdiff packages to create original patchutils package. Matthias Hanisch - Major interdiff speed-ups, combinediff implementation. patchutils-0.4.2/BUGS000066400000000000000000000001171370426545100143660ustar00rootroot00000000000000Bugs: If you find a bug, please send me a minimal test case demonstrating it. patchutils-0.4.2/COPYING000066400000000000000000000432541370426545100147470ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. patchutils-0.4.2/ChangeLog000066400000000000000000000000001370426545100154440ustar00rootroot00000000000000patchutils-0.4.2/Makefile.am000066400000000000000000000171021370426545100157410ustar00rootroot00000000000000DISTCLEANFILES = src/stamp-h[0-9]* src/config.h bin_PROGRAMS = src/interdiff src/filterdiff src/rediff bin_SCRIPTS = \ scripts/fixcvsdiff \ scripts/splitdiff \ scripts/editdiff \ scripts/recountdiff \ scripts/unwrapdiff \ scripts/dehtmldiff \ scripts/espdiff dist_bin_SCRIPTS = \ patchview/gitdiff \ patchview/gitdiffview \ patchview/svndiff \ patchview/svndiffview AM_CFLAGS = -I$(srcdir)/src src_interdiff_SOURCES = src/interdiff.c src/util.c src/util.h src/diff.c \ src/diff.h src/myerror.c src_filterdiff_SOURCES = src/filterdiff.c src/util.c src/util.h src/diff.c \ src/diff.h src/myerror.c src_rediff_SOURCES = src/rediff.c src/util.c src/util.h src/diff.c src/diff.h \ src/myerror.c src_interdiff_LDADD = @LIBOBJS@ src_filterdiff_LDADD = @LIBOBJS@ src_rediff_LDADD = @LIBOBJS@ if HAVE_XMLTO # The man pages are generated from DocBook XML. interdiff_manpage = doc/interdiff.1 other_manpages = doc/filterdiff.1 doc/fixcvsdiff.1 doc/rediff.1 \ doc/editdiff.1 doc/combinediff.1 doc/lsdiff.1 doc/splitdiff.1 \ doc/grepdiff.1 doc/recountdiff.1 doc/unwrapdiff.1 doc/dehtmldiff.1 \ doc/flipdiff.1 doc/espdiff.1 doc/patchview.1 man_MANS = $(interdiff_manpage) $(other_manpages) $(other_manpages): $(interdiff_manpage) $(interdiff_manpage): doc/patchutils.xml $(XMLTO) man -o doc $< endif # Special rules for combinediff, flipdiff, lsdiff, grepdiff and patchview, which are # just symlinks. src/combinediff$(EXEEXT): src/interdiff$(EXEEXT) ln -sf $(notdir $<) $@ src/flipdiff$(EXEEXT): src/interdiff$(EXEEXT) ln -sf $(notdir $<) $@ src/lsdiff$(EXEEXT): src/filterdiff$(EXEEXT) ln -sf $(notdir $<) $@ src/grepdiff$(EXEEXT): src/filterdiff$(EXEEXT) ln -sf $(notdir $<) $@ src/patchview$(EXEEXT): src/filterdiff$(EXEEXT) ln -sf $(notdir $<) $@ install-exec-hook: ln -sf "`echo interdiff|sed '$(transform)'`" $(DESTDIR)$(bindir)/"`echo combinediff|sed '$(transform)'`" ln -sf "`echo interdiff|sed '$(transform)'`" $(DESTDIR)$(bindir)/"`echo flipdiff|sed '$(transform)'`" ln -sf "`echo filterdiff|sed '$(transform)'`" $(DESTDIR)$(bindir)/"`echo lsdiff|sed '$(transform)'`" ln -sf "`echo filterdiff|sed '$(transform)'`" $(DESTDIR)$(bindir)/"`echo grepdiff|sed '$(transform)'`" ln -sf "`echo filterdiff|sed '$(transform)'`" $(DESTDIR)$(bindir)/"`echo patchview|sed '$(transform)'`" uninstall-hook: rm -f $(DESTDIR)$(bindir)/"`echo combinediff|sed '$(transform)'`" rm -f $(DESTDIR)$(bindir)/"`echo flipdiff|sed '$(transform)'`" rm -f $(DESTDIR)$(bindir)/"`echo lsdiff|sed '$(transform)'`" rm -f $(DESTDIR)$(bindir)/"`echo grepdiff|sed '$(transform)'`" rm -f $(DESTDIR)$(bindir)/"`echo patchview|sed '$(transform)'`" CLEANFILES=src/combinediff src/flipdiff src/lsdiff src/grepdiff src/patchview MAINTAINERCLEANFILES=$(man_MANS) # Regression tests. TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \ ARENA=$(top_builddir)/test-arena \ DIFF=$(DIFF) PATCH=$(PATCH) TESTS = tests/newline1/run-test \ tests/newline2/run-test \ tests/newline3/run-test \ tests/newline4/run-test \ tests/newline5/run-test \ tests/newline6/run-test \ tests/create1/run-test \ tests/broken1/run-test \ tests/revert1/run-test \ tests/revert2/run-test \ tests/dashes/run-test \ tests/dashes1/run-test \ tests/dashes2/run-test \ tests/dashes3/run-test \ tests/dashes4/run-test \ tests/linux-2.4.0-test-pre-style/run-test \ tests/linux-2.2.17-pre4-5/run-test \ tests/linux-2.4.13-ac6-7/run-test \ tests/apply1/run-test \ tests/copy1/run-test \ tests/edit1/run-test \ tests/edit2/run-test \ tests/edit3/run-test \ tests/edit4/run-test \ tests/edit5/run-test \ tests/edit6/run-test \ tests/edit7/run-test \ tests/edit8/run-test \ tests/edit9/run-test \ tests/edit10/run-test \ tests/combine1/run-test \ tests/combine2/run-test \ tests/combine3/run-test \ tests/gendiff1/run-test \ tests/gendiff2/run-test \ tests/comma/run-test \ tests/addhunk1/run-test \ tests/addhunk2/run-test \ tests/addhunk3/run-test \ tests/delhunk1/run-test \ tests/delhunk2/run-test \ tests/delhunk3/run-test \ tests/delhunk4/run-test \ tests/delhunk5/run-test \ tests/delhunk6/run-test \ tests/trimcontext1/run-test \ tests/trimlast1/run-test \ tests/trimlast2/run-test \ tests/nodate/run-test \ tests/lsdiff1/run-test \ tests/lsdiff2/run-test \ tests/lsdiff3/run-test \ tests/lsdiff4/run-test \ tests/lsdiff5/run-test \ tests/lsdiff6/run-test \ tests/lsdiff7/run-test \ tests/lsdiff8/run-test \ tests/lsdiff9/run-test \ tests/lsdiff10/run-test \ tests/lsdiff11/run-test \ tests/lsdiff12/run-test \ tests/lsdiff13/run-test \ tests/lsdiff14/run-test \ tests/lsdiff15/run-test \ tests/patchview1/run-test \ tests/patchview2/run-test \ tests/fuzz1/run-test \ tests/U0/run-test \ tests/U3/run-test \ tests/U5/run-test \ tests/grepdiff1/run-test \ tests/grepdiff2/run-test \ tests/grepdiff3/run-test \ tests/grepdiff4/run-test \ tests/grepdiff5/run-test \ tests/grepdiff6/run-test \ tests/grepdiff7/run-test \ tests/grepdiff8/run-test \ tests/grepdiff9/run-test \ tests/number1/run-test \ tests/number2/run-test \ tests/number3/run-test \ tests/nondiff/run-test \ tests/nondiff1/run-test \ tests/lscontext1/run-test \ tests/lscontext2/run-test \ tests/lscontext3/run-test \ tests/filterb/run-test \ tests/filterp/run-test \ tests/select1/run-test \ tests/select2/run-test \ tests/select3/run-test \ tests/select4/run-test \ tests/select5/run-test \ tests/select6/run-test \ tests/select7/run-test \ tests/select8/run-test \ tests/select9/run-test \ tests/select10/run-test \ tests/select11/run-test \ tests/preserve1/run-test \ tests/rediff1/run-test \ tests/rediff2/run-test \ tests/rediff3/run-test \ tests/recount1/run-test \ tests/recount2/run-test \ tests/recount3/run-test \ tests/recount4/run-test \ tests/recount5/run-test \ tests/recount6/run-test \ tests/recount7/run-test \ tests/unwrapdiff1/run-test \ tests/overstrip/run-test \ tests/context1/run-test \ tests/flip1/run-test \ tests/flip2/run-test \ tests/flip3/run-test \ tests/flip4/run-test \ tests/flip5/run-test \ tests/flip6/run-test \ tests/flip7/run-test \ tests/flip8/run-test \ tests/flip9/run-test \ tests/flip10/run-test \ tests/flip11/run-test \ tests/flip12/run-test \ tests/flip13/run-test \ tests/flip14/run-test \ tests/flip15/run-test \ tests/flip16/run-test \ tests/flip17/run-test \ tests/flip18/run-test \ tests/flip19/run-test \ tests/unline1/run-test \ tests/nul0/run-test \ tests/nul1/run-test \ tests/nul2/run-test \ tests/nul3/run-test \ tests/convert1/run-test \ tests/convert2/run-test \ tests/clean1/run-test \ tests/clean2/run-test \ tests/stdin/run-test \ tests/splitdiffD/run-test \ tests/fullheader1/run-test \ tests/fullheader2/run-test \ tests/fullheader3/run-test \ tests/fullheader4/run-test \ tests/whitespace/run-test # These ones don't work yet. # Feel free to send me patches. :-) XFAIL_TESTS = \ tests/delhunk5/run-test \ tests/delhunk6/run-test test-perms: src/combinediff$(EXEEXT) src/flipdiff$(EXEEXT) \ src/lsdiff$(EXEEXT) src/grepdiff$(EXEEXT) src/patchview$(EXEEXT) \ scripts/splitdiff for script in $(bin_SCRIPTS); do \ if [ -f $(top_builddir)/$$script ]; then \ chmod a+x $(top_builddir)/$$script; \ else \ chmod a+x $(top_srcdir)/$$script; \ fi \ done for test in $(TESTS); do \ chmod a+x $(top_srcdir)/$$test; \ done $(TESTS): test-perms distclean-local: -rm -rf $(top_builddir)/test-arena EXTRA_DIST = $(man_MANS) \ tests/common.sh tests/soak-test \ $(TESTS) $(XFAIL_TESTS) \ BUGS COPYING TODO ChangeLog \ bootstrap \ patchutils.spec \ doc/patchutils.xml \ src/getopt.h \ scripts/move-to-front tag: cvs tag -c `echo V@VERSION@ | tr . _` patchutils-0.4.2/NEWS000066400000000000000000000022041370426545100144010ustar00rootroot00000000000000Patchutils news --------------- 0.3.4 (stable) Some fixes for filterdiff and rediff. The splitdiff utility now has an option to write output to a subdirectory. Ranges can now be prefixed by a modifier ('x') to exclude spans instead of include them. Extended headers produced by git are now handled by filterdiff and interdiff. 0.3.3 (stable) Context output format for "no newline" lines has been fixed. The splitdiff utility now has an option to disable ".patch" filename extensions. Some fixes for bugs spotted by Coverity. Interdiff can now use "-" (stdin) for one of the inputs. 0.3.2 (stable) Interdiff had previously been putting absolute filenames in the input to the patch program. It now avoids doing this. Editdiff no longer runs rediff when no changes were made in the editor. The correct exit status is now set when the decompress option fails. A temporary file leak has been fixed. The documentation has been updated. 0.3.0 (stable) The lsdiff -H option is now the default, and new options have been added to filterdiff for reading inclusion/exclusion patterns from files, and for removing non-diff lines. patchutils-0.4.2/NEWS.0.2.x000066400000000000000000000104011370426545100151430ustar00rootroot00000000000000Patchutils news --------------- 0.2.31 (stable) Several small bugs were fixed. 0.2.30 (stable) Some minor parsing bugs were fixed, the documentation was clarified, and a new option was added to lsdiff/filterdiff for selecting patches based on the order in which they appear. 0.2.29 (stable) Several small bugs were fixed. 0.2.28 (stable) Some format conversion bugs were fixed. 0.2.27 (stable) An option was added to lsdiff to treating empty files as absent. The filterdiff and interdiff utilities now handle patches containing embedded null characters. The dehtmldiff utility was improved slightly. 0.2.26 (stable) Some build fixes were made. 0.2.25 (stable) A new filterdiff option for displaying patch filenames. A new splitdiff option to make it behave more like diffsplit. Other minor bugfixes. 0.2.24 (stable) A new filterdiff option for removing timestamps. New grepdiff options -E and -f. Minor bugfixes. 0.2.23 (stable) Minor bugfixes. 0.2.22 (stable) Several small bugs were fixed. A new option was added to splitdiff to split out every file-level patch, and a new option was added to grepdiff to display matching hunks. 0.2.21 (stable) Several bugs were fixed in flipdiff and dehtmldiff. 0.2.20 (stable) A new tool was added for exchanging the order of two patches. 0.2.19 (stable) Several bug fixes were made, and a new program was added for extracting a diff from an HTML page. 0.2.18 (stable) Support for ISO 8601 timezones. 0.2.17 (stable) Support for conversion between unified and context formats was added. 0.2.16 (stable) A new option (--annotate) was added to filterdiff, and interdiff can now strip context lines from patches. 0.2.15 (stable) The recountdiff and unwrapdiff tools were added for fixing broken diffs. 0.2.14 (stable) Hunk-level filtering was added to filterdiff. 0.2.13 (stable) In this release, some minor bugs were fixed, a new option (--no-revert-omitted) was added to interdiff, and two new options (--strip and --addprefix) were added to filterdiff, lsdiff, and grepdiff. 0.2.12 (stable) Several small issues were addressed. 0.2.11 (stable) In this release, filterdiff, lsdiff and grepdiff now understand context diff format, and several rediff bugs were fixed. 0.2.10 (stable) The last of the known interdiff bugs are now fixed. 0.2.9 (stable) A small bug concerning new files in 'cvs diff' output was fixed. 0.2.8 (stable) Interdiff and filterdiff were fixed to handle filenames with spaces in them. A new tool, grepdiff, was added. 0.2.7 (stable) A new option for showing added and removed files was added to lsdiff, and some portability fixes were made. 0.2.6 (stable) A bug concerning zero-context patches was fixed, and the man pages are now automatically generated from DocBook XML. 0.2.5 (stable) Some silly bugs in lsdiff and combinediff were fixed. 0.2.4 (stable) Support for patches created using interdiff and combinediff. 0.2.3 (stable) Small enhancements for rediff and two new tools (lsdiff and splitdiff) were added. 0.2.2 (stable) A new tool called combinediff has been added, and the test suite has been enhanced. 0.2.1 (stable) Substantial speed improvements for interdiff and a new tool (rediff) for correcting hand-edited patches were added. 0.2.0 (stable) There is now an option for ignoring whitespace in interdiff. 0.1.5 (devel) A tiny perl script for fixing cvs diff results and minor clean-ups added. 0.1.4 (devel) Some code cleanups. 0.1.3 (devel) Support for decompressing patches (by popular demand). 0.1.2 (devel) Minor build fixes. 0.1.1 (devel) Interdiff and extractdiff have been merged into patchutils, which now uses autoconf. 0.1.0 (devel) There are new commandline options for controlling the amount of context displayed. Interdiff news -------------- 0.0.10 (stable) A corner case and a silly bug have been fixed. 0.0.9 (stable) Handling of non-seekable streams. 0.0.8 (stable) Some parameter parsing bugs have been fixed. Leading './' pathname components are ignored for filename comparison. 0.0.7 (stable) A new -p option, similar to patch(1), and numerous bugfixes. 0.0.5 (stable) Support for patches created using gendiff. 0.0.4 (stable) Another corner case has been fixed, and some test cases added. patchutils-0.4.2/README000066400000000000000000000027321370426545100145700ustar00rootroot00000000000000This is patchutils, a collection of tools that operate on patch files. Interdiff generates an incremental patch from two patches against a common source. For example, if you have applied a pre-patch to a source tree, and wish to apply another pre-patch (which is against the same original source tree), you can use interdiff to generate the patch that you need to apply. You can also use this to review changes between two pre-patches. Combinediff generates a single patch from two incremental patches, allowing you to merge patches together. The resulting patch file only alters each file once. Filterdiff will select the portions of a patch file that apply to files matching (or, alternatively, not matching) a shell wildcard. Fixcvsdiff is for correcting the output of ‘cvs diff’. Rediff corrects hand-edited patches, by comparing the original patch with the modified one and adjusting the offsets and counts. Lsdiff displays a short listing of affected files in a patch file, along with (optionally) the line numbers of the start of each patch. Splitdiff separates out patches from a patch file so that each new patch file only alters any given file once. In this way, a file containing several incremental patches can be split into individual incremental patches. Grepdiff displays a list of the files modified by a patch where the patch contains a given regular expression. Recountdiff fixes up counts and offsets in a unified diff. Unwrapdiff fixes word-wrapped unified diffs. patchutils-0.4.2/TODO000066400000000000000000000010041370426545100143670ustar00rootroot00000000000000Things to do: - tidy up the code. rediff.c has some nice routines that should be moved to diff.c. More use of assert(). - interdiff: rewrite output_patch1_only in terms of calls to output_delta with a file handle open to /dev/null. - Strip trailing CRs if necessary, like patch does. - Handle RFC934 encapsulation, like patch does. - Make interdiff support -I (?? don't remember what this is about). - Teach rediff how to handle multiple added hunks. - Add an option to make splitdiff separate out each hunk. patchutils-0.4.2/bootstrap000077500000000000000000000007741370426545100156570ustar00rootroot00000000000000#! /bin/sh echo "Deleting all autogenerated stuff..." rm -f *.o *.so config.sub config.guess config.cache rm -f config.log config.h config.status config.h.in rm -f Makefile configure builtin/*.o pgcrypto.sql rm -f Makefile.in aclocal.m4 confdefs.h ltconfig ltmain.sh rm -f install-sh mkinstalldirs missing stamp* rm -f interdiff filterdiff combinediff rm -f compile depcomp rm -f *~ rm -rf autom4te.cache/ rm -f INSTALL rm -f test-driver autoreconf --install --verbose echo "Now you may run ./configure" patchutils-0.4.2/configure.ac000066400000000000000000000056151370426545100162010ustar00rootroot00000000000000dnl Process this file with autoconf to produce a configure script. AC_INIT([patchutils],[0.4.2]) AC_CONFIG_SRCDIR(patchutils.spec.in) AC_CONFIG_HEADERS(config.h) AM_INIT_AUTOMAKE([dist-xz dist-bzip2 subdir-objects 1.6]) dnl Checks for programs. AC_PROG_CC AM_PROG_CC_C_O AC_PROG_CPP AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET AC_PROG_RANLIB AC_PATH_PROG([XMLTO], [xmlto]) AM_CONDITIONAL(HAVE_XMLTO, test x$XMLTO != x) if test x$XMLTO = x; then AC_MSG_WARN([xmlto not available so not building docs]) fi dnl Checks for perl, for the scripts AC_PATH_PROGS(PERL, perl perl5) dnl Find a default editor AC_CHECK_PROGS(DEFAULT_EDITOR, sensible-editor editor vim vi, vi) CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" if test x"$GCC" = xyes; then CFLAGS="$CFLAGS -Wall" fi dnl Checks for libraries. dnl Checks for header files. AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_CHECK_HEADERS(sys/types.h unistd.h error.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_TYPE_PID_T AC_TYPE_SIZE_T dnl Checks for library functions. AC_FUNC_ALLOCA AC_FUNC_FNMATCH AC_CHECK_FUNCS(strcspn strspn strtoul getline error) AC_CONFIG_LIBOBJ_DIR([src]) dnl Check for long getopt AC_CHECK_FUNCS(getopt_long , , [ AC_LIBOBJ([getopt]) AC_LIBOBJ([getopt1]) ]) dnl Check pcre2 availability AC_MSG_CHECKING([whether PCRE2 support is requested]) AC_ARG_WITH([pcre2], [AS_HELP_STRING([--with-pcre2], [use pcre2 regex library @<:@default=check@:>@])], [], [with_pcre2=check]) LIBPCRE2= AS_IF([test "x$with_pcre2" != xno], [ AC_MSG_RESULT($with_pcre2) AC_CHECK_HEADERS([pcre2posix.h], [], [LIBPCRE2=_missing_header]) AC_CHECK_LIB([pcre2-posix${LIBPCRE2}], [regexec], [], [if test "x$with_pcre2" != xcheck; then AC_MSG_FAILURE( [--with-pcre2 was given, but test for pcre2-posix failed]) fi] ) ], AC_MSG_RESULT(no) ) dnl Check diff/patch programs AC_MSG_CHECKING(for diff program) DIFF=diff AC_ARG_WITH(diff, [ --with-diff=DIFF name of the diff program], DIFF=$withval) AC_MSG_RESULT($DIFF) PATCH=patch AC_MSG_CHECKING(for patch program) AC_ARG_WITH(patch, [ --with-patch=PATCH name of the patch program], PATCH=$withval) AC_MSG_RESULT($PATCH) AC_MSG_CHECKING(whether patch works) pver=`$PATCH -v 2>&1` if echo "$pver" | grep -q "version 2.0" > /dev/null 2>&1; then AC_MSG_ERROR([no Sorry, you have version 2.0 of the patch program, which is not supported by interdiff. Please upgrade. ]) fi AC_MSG_RESULT(yes) AC_DEFINE_UNQUOTED(PATCH, "$PATCH", How patch(1) is called) AC_DEFINE_UNQUOTED(DIFF, "$DIFF", How diff(1) is called) AC_CONFIG_FILES([ Makefile scripts/splitdiff scripts/editdiff scripts/fixcvsdiff scripts/recountdiff scripts/unwrapdiff scripts/dehtmldiff scripts/espdiff patchutils.spec ]) AC_OUTPUT patchutils-0.4.2/doc/000077500000000000000000000000001370426545100144515ustar00rootroot00000000000000patchutils-0.4.2/doc/patchutils.xml000066400000000000000000002736441370426545100173730ustar00rootroot00000000000000 Patchutils Tim Waugh
twaugh@redhat.com
Package maintainer
Man pages patchutils 23 June 2009 Michael K. Johnson
johnsonm@redhat.com
Original man page contributor
interdiff 1 interdiff show differences between two diff files interdiff -p n --strip-match=n -U n --unified=n -d PAT --drop-context=PAT -q --quiet -z --decompress -b --ignore-space-change -B --ignore-blank-lines -i --ignore-case -w --ignore-all-space --interpolate --combine --flip --no-revert-omitted diff1 diff2 interdiff --help --version Description interdiff creates a unified format diff that expresses the difference between two diffs. The diffs must both be relative to the same files. For best results, the diffs must have at least three lines of context. To reverse a patch, use /dev/null for diff2. To reduce the amount of context in a patch, use: Since interdiff doesn't have the advantage of being able to look at the files that are to be modified, it has stricter requirements on the input format than patch 1 does. The output of GNU diff will be okay, even with extensions, but if you intend to use a hand-edited patch it might be wise to clean up the offsets and counts using recountdiff 1 first. Note, however, that the two patches must both be relative to the versions of the same original set of files. The diffs may be in context format. The output, however, will be in unified format. Options Ignored, for compatibility with older versions of interdiff. This option will go away soon. n, When comparing filenames, ignore the first n pathname components from both patches. (This is similar to the option to GNU patch 1 .) , Quieter output. Don't emit rationale lines at the beginning of each patch. n, Attempt to display n lines of context (requires at least n lines of context in both input files). (This is similar to the option to GNU diff 1 .) PATTERN, Don't display any context on files that match the shell wildcard PATTERN. This option can be given multiple times. Note that the interpretation of the shell wildcard pattern does not count slash characters or periods as special (in other words, no flags are given to fnmatch). This is so that */basename-type patterns can be given without limiting the number of pathname components. , Consider upper- and lower-case to be the same. , Ignore whitespace changes in patches. , Ignore changes in the amount of whitespace. , Ignore changes whose lines are all blank. , Decompress files with extensions .gz and .bz2. Run as interdiff. This is the default. Run as combinediff. See combinediff 1 for more information about how the behaviour is altered in this mode. (For interpolation mode only) When a file is changed by the first patch but not by the second, don't revert that change. Display a short usage message. Display the version number of interdiff. Examples Basic usage: Reversing a patch: Reversing part of a patch (and ignoring the rest): Bugs There are currently no known bugs in interdiff; but there are some caveats. If you find a bug, please report it (along with a minimal test case) to Tim Waugh twaugh@redhat.com. There are some sets of patches in which there is just not enough information to produce a proper interdiff. In this case, the strategy employed is to revert the original patch and apply the new patch. This, unfortunately, means that interdiffs are not guaranteed to be reversible. See also combinediff 1
patchutils 23 Jan 2009 combinediff 1 combinediff create a cumulative unified patch from two incremental patches combinediff -p n --strip-match=n -U n --unified=n -d PAT --drop-context=PAT -q --quiet -z --decompress -b --ignore-space-change -B --ignore-blank-lines -i --ignore-case -w --ignore-all-space --interpolate --combine diff1 diff2 combinediff --help --version Description combinediff creates a unified diff that expresses the sum of two diffs. The diff files must be listed in the order that they are to be applied. For best results, the diffs must have at least three lines of context. Since combinediff doesn't have the advantage of being able to look at the files that are to be modified, it has stricter requirements on the input format than patch 1 does. The output of GNU diff will be okay, even with extensions, but if you intend to use a hand-edited patch it might be wise to clean up the offsets and counts using recountdiff 1 first. Note, however, that the two patches must be in strict incremental order. In other words, the second patch must be relative to the state of the original set of files after the first patch was applied. The diffs may be in context format. The output, however, will be in unified format. Options n, When comparing filenames, ignore the first n pathname components from both patches. (This is similar to the option to GNU patch 1 .) , Quieter output. Don't emit rationale lines at the beginning of each patch. n, Attempt to display n lines of context (requires at least n lines of context in both input files). (This is similar to the option to GNU diff 1 .) pattern, Don't display any context on files that match the shell wildcard pattern. This option can be given multiple times. Note that the interpretation of the shell wildcard pattern does not count slash characters or periods as special (in other words, no flags are given to fnmatch). This is so that */basename-type patterns can be given without limiting the number of pathname components. , Consider upper- and lower-case to be the same. , Ignore whitespace changes in patches. , Ignore changes in the amount of whitespace. , Ignore changes whose lines are all blank. , Decompress files with extensions .gz and .bz2. Run as interdiff. See interdiff 1 for more information about how the behaviour is altered in this mode. Run as combinediff. This is the default. Display a short usage message. Display the version number of combinediff. Bugs The option is a bit erratic: it can control the amount of context displayed for files that are modified in both patches, but not for files that only appear in one patch (which appear with the same amount of context in the output as in the input). See also interdiff 1 patchutils 23 Jan 2009 filterdiff 1 filterdiff extract or exclude diffs from a diff file filterdiff -i PATTERN --include=PATTERN -I FILE --include-from-file=FILE -p n --strip-match=n --strip=n --addprefix=PREFIX --addoldprefix=PREFIX --addnewprefix=PREFIX -x PATTERN --exclude=PATTERN -X FILE --exclude-from-file=FILE -v --verbose --clean -z --decompress -# RANGE --hunks=RANGE --lines=RANGE -FRANGE --files=RANGE --annotate --format=FORMAT --as-numbered-lines=WHEN --remove-timestamps file filterdiff --help --version --list --grep ... Description You can use filterdiff to obtain a patch that applies to files matching the shell wildcard PATTERN from a larger collection of patches. For example, to see the patches in patch-2.4.3.gz that apply to all files called lp.c: filterdiff -z -i '*/lp.c' patch-2.4.3.gz If neither nor options are given, is assumed. This way filterdiff can be used to clean up an existing diff file, removing redundant lines from the beginning (eg. the text from the mail body) or between the chunks (eg. in CVS diffs). To extract pure patch data, use a command like this: filterdiff message-with-diff-in-the-body > patch Note that the interpretation of the shell wildcard pattern does not count slash characters or periods as special (in other words, no flags are given to fnmatch). This is so that */basename-type patterns can be given without limiting the number of pathname components. You can use both unified and context format diffs with this program. Options PATTERN, Include only files matching PATTERN. All other lines in the input are suppressed. FILE, Include only files matching any pattern listed in FILE, one pattern per line. All other lines in the input are suppressed. PATTERN, Exclude files matching PATTERN. All other lines in the input are displayed. FILE, Exclude files matching any pattern listed in FILE, one pattern per line. All other lines in the input are displayed. n, When matching, ignore the first n components of the pathname. RANGE, =RANGE Only include hunks within the specified RANGE. Hunks are numbered from 1, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. =RANGE Only include hunks that contain lines from the original file that lie within the specified RANGE. Lines are numbered from 1, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. =RANGE, =RANGE Only include files indicated by the specified RANGE. Files are numbered from 1 in the order they appear in the patch input, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. Annotate each hunk with the filename and hunk number. =unified|context Use specified output format. =n Remove the first n components of pathnames in the output. =PREFIX Prefix pathnames in the output by PREFIX. This will override any individual settings specified with the or options. =PREFIX Prefix pathnames for old or original files in the output by PREFIX. =PREFIX Prefix pathnames for updated or new files in the output by PREFIX. =before|after Instead of a patch fragment, display the lines of the selected hunks with the line number of the file before (or after) the patch is applied, followed by a TAB character and a colon, at the beginning of each line. Each hunk except the first will have a line consisting of ... before it. Do not include file timestamps in the output. , Always show non-diff lines in the output. By default, non-diff lines are only shown when excluding a filename pattern. Always remove all non-diff lines from the output. Even when excluding a filename pattern. , Decompress files with extensions .gz and .bz2. Display a short usage message. Display the version number of filterdiff. Behave like lsdiff 1 instead. Behave like grepdiff 1 instead. Examples To see all patch hunks that affect the first five lines of a C file: To see the first hunk of each file patch, use: To see patches modifying a ChangeLog file in a subdirectory, use: To see the complete patches for each patch that modifies line 1 of the original file, use: To see all but the first hunk of a particular patch, you might use: If you have a very specific list of hunks in a patch that you want to see, list them: To see the lines of the files that would be patched as they will appear after the patch is applied, use: You can see the same context before the patch is applied with: Filterdiff can also be used to convert between unified and context format diffs: See also lsdiff 1 , grepdiff 1 , patchview 1 patchutils 7 Dec 2001 Amir Karger
karger@post.harvard.edu
Author of the original perl script and man page
John Levon
moz@compsoc.man.ac.uk
Author of the original perl script and man page
fixcvsdiff 1 fixcvsdiff fix problematic diff files fixcvsdiff -p -b file Description fixcvsdiff modifies diff files created from the cvs diff command, where files have been added or removed. CVS tends to create diff files that patch 1 mis-interprets. The diff file must retain the lines beginning with Index: in order for the correction to work. Options Keep a .bak backup file. Print out the cvs add and cvs remove commands that must be made after applying the diff, but before running cvs commit. See also diff 1 , patch 1 , cvs 1
patchutils 23 Jan 2009 lsdiff 1 lsdiff show which files are modified by a patch lsdiff -n --line-number -p n --strip-match=n --strip=n --addprefix=PREFIX -s --status -E --empty-files-as-removed -i PATTERN --include=PATTERN -x PATTERN --exclude=PATTERN -z --decompress -# RANGE --hunks=RANGE --lines=RANGE -FRANGE --files=RANGE -H --with-filename -h --no-filename -v --verbose file lsdiff --help --version --filter ... --grep ... Description List the files modified by a patch. You can use both unified and context format diffs with this program. Options , Display the line number that each patch begins at. If verbose output is requested (using ), each hunk of each patch is listed as well. For each file that is modified, a line is generated containing the line number of the beginning of the patch, followed by a Tab character, followed by the name of the file that is modified. If is given once, following each of these lines will be one line for each hunk, consisting of a Tab character, the line number that the hunk begins at, another Tab character, the string Hunk #, and the hunk number (starting at 1). If the is given twice in conjunction with (i.e. ), the format is slightly different: hunk-level descriptive text is shown after each hunk number, and the option is enabled. , File numbers are listed, beginning at 1, before each filename. RANGE, =RANGE Only list hunks within the specified RANGE. Hunks are numbered from 1, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. =RANGE Only list hunks that contain lines from the original file that lie within the specified RANGE. Lines are numbered from 1, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. =RANGE, =RANGE Only list files indicated by the specified RANGE. Files are numbered from 1 in the order they appear in the patch input, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. n, When matching, ignore the first n components of the pathname. =n Remove the first n components of the pathname before displaying it. =PREFIX Prefix the pathname with PREFIX before displaying it. , Show file additions, modifications and removals. A file addition is indicated by a +, a removal by a -, and a modification by a !. , Treat empty files as absent for the purpose of displaying file additions, modifications and removals. PATTERN, Include only files matching PATTERN. PATTERN, Exclude files matching PATTERN. , Decompress files with extensions .gz and .bz2. , Print the name of the patch file containing each patch. , Suppress the name of the patch file containing each patch. , Verbose output. Display a short usage message. Display the version number of lsdiff. Behave like filterdiff 1 instead. Behave like grepdiff 1 instead. See also filterdiff 1 , grepdiff 1 , patchview 1 Examples To sort the order of touched files in a patch, you can use: To show only added files in a patch: To show the headers of all file hunks: patchutils 02 Jul 2020 patchview 1 patchview Without options, show numbered files modified by the patch. With options, behave as filterdiff. patchview -n --line-number -p n --strip-match=n --strip=n --addprefix=PREFIX -s --status -E --empty-files-as-removed -i PATTERN --include=PATTERN -x PATTERN --exclude=PATTERN -z --decompress -# RANGE --hunks=RANGE --lines=RANGE -FRANGE --files=RANGE -H --with-filename -h --no-filename -v --verbose file patchview --help --version --filter ... --grep ... Description So what is patchview? It is a wrapper of filterdiff for use with numbered files. patchview (without args) is equivalent to: lsdiff --number patchview -F2- (or with any other args) is equivalent to: filterdiff -F2- (or whatever arguments are supplied) There are two scripts for working with git (gitdiff and gitdiffview) and two for svn (svndiff and svndiffview). svndiff gitdiff (without args) will give the list of files modified svndiff -F1 gitdiff -F1 will show the patch of file #1 svndiffview gitdiffview pipe all patches through filterdiff to vim - -R (in read-only mode, easy to quit), showing complete patch with color. svndiffview -F2 gitdiffview -F2 (or any other args) will pipe patch of file #2 to vim - -R Options , Display the line number that each patch begins at. If verbose output is requested (using ), each hunk of each patch is listed as well. For each file that is modified, a line is generated containing the line number of the beginning of the patch, followed by a Tab character, followed by the name of the file that is modified. If is given once, following each of these lines will be one line for each hunk, consisting of a Tab character, the line number that the hunk begins at, another Tab character, the string Hunk #, and the hunk number (starting at 1). If the is given twice in conjunction with (i.e. ), the format is slightly different: hunk-level descriptive text is shown after each hunk number, and the option is enabled. , File numbers are listed, beginning at 1, before each filename. RANGE, =RANGE Only list hunks within the specified RANGE. Hunks are numbered from 1, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. =RANGE Only list hunks that contain lines from the original file that lie within the specified RANGE. Lines are numbered from 1, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. =RANGE, =RANGE Only list files indicated by the specified RANGE. Files are numbered from 1 in the order they appear in the patch input, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. n, When matching, ignore the first n components of the pathname. =n Remove the first n components of the pathname before displaying it. =PREFIX Prefix the pathname with PREFIX before displaying it. , Show file additions, modifications and removals. A file addition is indicated by a +, a removal by a -, and a modification by a !. , Treat empty files as absent for the purpose of displaying file additions, modifications and removals. PATTERN, Include only files matching PATTERN. PATTERN, Exclude files matching PATTERN. , Decompress files with extensions .gz and .bz2. , Print the name of the patch file containing each patch. , Suppress the name of the patch file containing each patch. , Verbose output. Display a short usage message. Display the version number of patchview. Behave like filterdiff 1 instead. Behave like grepdiff 1 instead. See also lsdiff 1 , filterdiff 1 , grepdiff 1 Examples We can make the following one-line script with the name difftotrunk.sh, to view the differences of two directories or svn repos (trunk and .) ./difftotrunk.sh , will show all different files and his number. ./difftotrunk.sh -F3,4 , will show the differences of files #3 and #4 only. ./difftotrunk.sh -F3 -#1 , will show only hunk #1 of file #3. ./difftotrunk.sh -F3 -#x1 , will show the differences of files #3 without hunk #1 (x means that exclude). patchutils 4 Nov 2014 splitdiff 1 splitdiff separate out incremental patches splitdiff -a -d -D dir -p n -E file splitdiff --help --version Description If you have a patch file composed of several incremental patches, you can use splitdiff to separate them out. You may want to do this in preparation for re-combining them with combinediff 1. The effect of running splitdiff is to separate its input into a set of output files, with no output file patching the same file more than once. Options Split out every single file-level patch. Create file names such as a_b.c.patch for a patch that modifies a/b.c. dir Write output files into subdirectory dir. Implies . n Strip the first n components of the pathname to aid comparisons. Don't use .patch filename extension when writing output files. Display a short usage message. Display the version number of splitdiff. See also combinediff 1 , lsdiff 1 patchutils 13 May 2002 rediff 1 rediff editdiff fix offsets and counts of a hand-edited diff rediff ORIGINAL EDITED rediff EDITED rediff --help --version editdiff FILE editdiff --help --version Description You can use rediff to correct a hand-edited unified diff. Take a copy of the diff you want to edit, and edit it without changing any offsets or counts (the lines that begin @@). Then run rediff, telling it the name of the original diff file and the name of the one you have edited, and it will output the edited diff file but with corrected offsets and counts. A small script, editdiff, is provided for editing a diff file in-place. The types of changes that are currently handled are: Modifying the text of any file content line (of course). Adding new line insertions or deletions. Adding, changing or removing context lines. Lines at the context horizon are dealt with by adjusting the offset and/or count. Adding a single hunk (@@-prefixed section). Removing multiple hunk (@@-prefixed sections). Alternatively, if only one argument is provided, it is taken to be the edited file and the counts and offsets are adjusted as appropriate. Some assumptions are made when used in this mode. See recountdiff 1 for more information. Options Display a short usage message. Display the version number of rediff. See also interdiff 1 , recountdiff 1 patchutils 10 Feb 2011 grepdiff 1 grepdiff show files modified by a diff containing a regex grepdiff -n --line-number -N --number-files -p n --strip-match=n --strip=n --addprefix=PREFIX --addoldprefix=PREFIX --addnewprefix=PREFIX -s --status -i PATTERN --include=PATTERN -I FILE --include-from-file=FILE -x PATTERN --exclude=PATTERN -X FILE --exclude-from-file=FILE -# RANGE --hunks=RANGE --lines=RANGE -FRANGE --files=RANGE --annotate --as-numbered-lines=WHEN --format=FORMAT --remove-timestamps -v --verbose -z --decompress -E --extended-regexp -H --with-filename -h --no-filename --output-matching=WHAT --only-match=WHAT REGEX -f FILE file grepdiff --help --version --list --filter ... Description For each file modified by a patch, if the patch hunk contains the REGEX then the file's name is printed. The regular expression is treated as POSIX Basic Regular Expression syntax, unless the option is given in which case POSIX Extended Regular Expression syntax is used. For example, to see the patches in my.patch which contain the regular expression pf_gfp_mask, use: You can use both unified and context format diffs with this program. Options , Display the line number that each patch begins at. If verbose output is requested, each matching hunk is listed as well. For a description of the output format see lsdiff 1 . , File numbers are listed, beginning at 1, before each filename. n, When matching, ignore the first n components of the pathname. =n Remove the first n components of the pathname before displaying it. =PREFIX Prefix the pathname with PREFIX before displaying it. This will override any individual settings specified with the or options. =PREFIX Prefix pathnames for old or original files in the output by PREFIX. =PREFIX Prefix pathnames for updated or new files in the output by PREFIX. Show file additions, modifications and removals. A file addition is indicated by a +, a removal by a -, and a modification by a !. PATTERN, Include only files matching PATTERN. FILE, Include only files matching any pattern listed in FILE, one pattern per line. All other lines in the input are suppressed. PATTERN Exclude files matching PATTERN. FILE, Exclude files matching any pattern listed in FILE, one pattern per line. All other lines in the input are displayed. RANGE, =RANGE Only include hunks within the specified RANGE. Hunks are numbered from 1, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. =RANGE Only list hunks that contain lines from the original file that lie within the specified RANGE. Lines are numbered from 1, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. =RANGE, =RANGE Only list files indicated by the specified RANGE. Files are numbered from 1 in the order they appear in the patch input, and the range is a comma-separated list of numbers or first-last spans, optionally preceded by a modifier 'x' which inverts the entire range; either the first or the last in the span may be omitted to indicate no limit in that direction. Annotate each hunk with the filename and hunk number. =before|after Instead of a patch fragment, display the lines of the selected hunks with the line number of the file before (or after) the patch is applied, followed by a TAB character and a colon, at the beginning of each line. Each hunk except the first will have a line consisting of ... before it. =unified|context Use specified output format. Do not include file timestamps in the output. , Decompress files with extensions .gz and .bz2. , Use POSIX Extended Regular Expression syntax. , Print the name of the patch file containing each match. , Suppress the name of the patch file containing each match. FILE, Read regular expressions from FILE, one per line. =hunk|file Display the matching hunk-level or file-level diffs. =rem|removals|add|additions|mod|modifications|all Limit regex matching to removals, additions, modifications or the whole hunk. Display a short usage message. Display the version number of grepdiff. Behave like filterdiff 1 instead. Behave like lsdiff 1 instead. See also filterdiff 1 , lsdiff 1 , patchview 1 patchutils 5 July 2002 recountdiff 1 recountdiff recompute patch counts and offsets recountdiff file recountdiff --help --version Description recountdiff recomputes the counts and offsets in unified context diffs. It does this in two passes: first the counts are corrected by inspection of the actual patch lines, and then the offsets are adjusted according to the computed counts. The corrected diff is sent to standard output. Options Display a short usage message. Display the version number of recountdiff. Limitations There are some things that cannot be dealt with. If you have removed the first context line in a hunk, for example, there is no way for recountdiff to know that. For more precise fixing up, use rediff 1 , which uses the original and modified diffs. See also rediff 1 patchutils 17 January 2003 unwrapdiff 1 unwrapdiff demangle word-wrapped patches unwrapdiff -v file unwrapdiff --help --version Description unwrapdiff demangles patches that have been word-wrapped, in an attempt to make them useful. The corrected diff is sent to standard output. Note that you will probably need to use the option when applying the patch, in order to ignore any whitespace differences there may be. Options Verbose operation. A list of lines that are modified in a way that might be wrong is sent to stderr. Display a short usage message. Display the version number of unwrapdiff. Limitations Some heuristics are used to decide whether use a space to recombine a wrapped line, or just join them together. Currently this is done by comparing with last three characters of a line with the first two characters of its continuation, and using a space if any of them are different. The patch needs to have been valid before being word-wrapped. The last line of a hunk is nearly always ambiguous. If the next line begins @@, Index: , diff  or ---  then it is taken to be complete; otherwise it is unwrapped using the next line. patchutils 17 January 2003 dehtmldiff 1 dehtmldiff get usable diff from an HTML page dehtmldiff file dehtmldiff --help --version Description dehtmldiff creates usable diff files from HTML pages. This is useful in the scenario where a patch has been posted to a mailing list viewable via a web page. The corrected diff is sent to standard output. Note that you will probably need to use the option when applying the patch, in order to ignore any whitespace differences there may be. Options Display a short usage message. Display the version number of dehtmldiff. Limitations The way this command works is fairly primitive; it boils down to some simple text replacements, followed by an unwrapdiff pass. As a result, all of the limitations that apply to unwrapdiff also apply to dehtmldiff. patchutils 23 January 2009 flipdiff 1 flipdiff exchange the order of two incremental patches flipdiff -p n --strip-match=n -U n --unified=n -d PAT --drop-context=PAT -q --quiet -z --decompress -b --ignore-space-change -B --ignore-blank-lines -i --ignore-case -w --ignore-all-space --in-place diff1 diff2 flipdiff --help --version Description flipdiff exchanges the order of two patch files that apply one after the other. The patches must be clean: the context lines must match and there should be no mis-matched offsets. The swapped patches are sent to standard output, with a marker line (=== 8< === cut here === 8< ===) between them, unless the option is passed. In that case, the output is written back to the original input files. Options n, When comparing filenames, ignore the first n pathname components from both patches. (This is similar to the option to GNU patch 1 .) , Quieter output. Don't emit rationale lines at the beginning of each patch. n, Attempt to display n lines of context (requires at least n lines of context in both input files). (This is similar to the option to GNU diff 1 .) pattern, Don't display any context on files that match the shell wildcard pattern. This option can be given multiple times. Note that the interpretation of the shell wildcard pattern does not count slash characters or periods as special (in other words, no flags are given to fnmatch). This is so that */basename-type patterns can be given without limiting the number of pathname components. , Consider upper- and lower-case to be the same. , Ignore whitespace changes in patches. , Ignore changes in the amount of whitespace. , Ignore changes whose lines are all blank. , Decompress files with extensions .gz and .bz2. Write output to the original input files. Display a short usage message. Display the version number of flipdiff. Limitations This is only been very lightly tested, and may not even work. Using is not recommended at the moment. There are some cases in which it is not possible to meaningfully flip patches without understanding the semantics of the content. This program only uses complete lines that appear at some stage during the application of the two patches, and never composes a line from parts. Because of this, it is generally a good idea to read through the output to check that it makes sense. patchutils 5 March 2003 Mike Harris
mharris@redhat.com
Conceptual designer
espdiff 1 espdiff apply the appropriate transformation to a set of patches espdiff --deep-brainwave-mode --recurse --compare file espdiff --help --version Description espdiff applies the appropriate transformation to a patch or set of patches, depending on what you intend to accomplish. The input patches must be clean: in other words they must apply without fuzz or offsets in whichever order they are meant to be applied. The exception is if you intend espdiff to clean them for you (good luck). You may find it useful to cross your fingers while the program performs its task, or to screw your eyes tight shut while imagining it doing the right thing. Options Probes your brain deeply in a manner that takes longer, but produces better extra sensory results. Recurses neural pathways throughout all parts of the brain, in some cases determining code changes you might make far off in the future. You may feel a gentle tickling sensation when using this option. Allows the program to scan the current directory examining existing patches to determine areas of code you are likely to change again, and concentrating on these areas more closely. Display a short usage message. Display the version number of espdiff. Limitations Do not use this program while sleep-walking, or before your first cup of coffee. There are some cases in which it is not possible to determine what the intention of the user is. In these cases, you should construct the output you desire using an editor, and send the input files together with the desired output file to Tim Waugh twaugh@redhat.com asking for a new diff tool.
patchutils-0.4.2/patchutils.spec.in000066400000000000000000000025551370426545100173540ustar00rootroot00000000000000Summary: A collection of programs for manipulating patch files. Name: @PACKAGE@ Version: @VERSION@ Release: 0.1 License: GPL Group: Applications/System URL: http://cyberelk.net/tim/patchutils/ Source0: http://cyberelk.net/tim/data/patchutils/stable/%{name}-%{version}.tar.bz2 BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot Obsoletes: interdiff Provides: interdiff %description This is a collection of programs that can manipulate patch files in useful ways such as interpolating between two pre-patches, combining two incremental patches, fixing line numbers in hand-edited patches, and simply listing the files modified by a patch. %prep %setup -q %build %configure make make check %install rm -rf %{buildroot} %makeinstall %clean rm -rf %{buildroot} %files %defattr(-,root,root) %doc AUTHORS ChangeLog README COPYING BUGS NEWS %{_bindir}/* %{_mandir}/*/* %changelog * Tue Jan 6 2004 Tim Waugh - Ship AUTHORS and ChangeLog as well. * Wed Sep 3 2003 Tim Waugh - Remove buildroot before installing. * Fri May 10 2002 Tim Waugh - The archive is now distributed in .tar.bz2 format. * Tue Apr 23 2002 Tim Waugh - Run tests after build step. * Mon Mar 4 2002 Tim Waugh - Obsolete (and provide) interdiff. * Tue Nov 27 2001 Tim Waugh - Initial spec file. patchutils-0.4.2/patchview/000077500000000000000000000000001370426545100156765ustar00rootroot00000000000000patchutils-0.4.2/patchview/README.patchview000066400000000000000000000025271370426545100205550ustar00rootroot00000000000000So what is patchview? It is a wrapper of filterdiff for use with numbered files. $ patchview (without args) is equivalent to: lsdiff --number $ patchview -F2- (or with any other args) is equivalent to: filterdiff -F2- (or whatever arguments are supplied) There are two scripts for working with git (gitdiff and gitdiffview) and two for svn (svndiff and svndiffview). $ svndiff $ gitdiff (without args) will give the list of files modified $ svndiff -F1 $ gitdiff -F1 will show the patch of file #1 $ svndiffview $ gitdiffview pipe all patches through filterdiff to `vim - -R` (in read-only mode, easy to quit), showing complete patch with color. $ svndiffview -F2 $ gitdiffview -F2 (or any other args) will pipe patch of file #2 to `vim - -R` Example: We can make the following one-line script with the name difftotrunk.sh, to view the differences of two directories or svn repos (trunk and .) diff ../trunk . -ru -x .svn | patchview "$@" $ ./difftotrunk.sh , will show all different files and his number. $ ./difftotrunk.sh -F3,4 , will show the differences of files #3 and #4 only. $ ./difftotrunk.sh -F3 -#1, will show only hunk #1 of file #3. $ ./difftotrunk.sh -F3 -#x1, will show the differences of files #3 without hunk #1 (x means that exclude). patchutils-0.4.2/patchview/gitdiff000077500000000000000000000033441370426545100172440ustar00rootroot00000000000000#!/usr/bin/python3 # -*- coding: utf-8 -*- # # Copyright (C) 2015-2019 Sérgio Basto # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # import os import sys import argparse from subprocess import Popen, PIPE enviro = os.environ workdir = '.' parser = argparse.ArgumentParser() parser.add_argument('-v', '--debug', help='writes the commands that will be executed', action='store_true') parser.add_argument('git_args', nargs='*', default=[]) parser.add_argument('patchview_args', nargs=argparse.REMAINDER) args, unknown = parser.parse_known_args() largs = vars(args).get("git_args") rargs = vars(args).get("patchview_args") if args.debug: print("%s | %s" % (" ".join(['git', 'diff'] + largs), " ".join(['patchview'] + rargs + unknown))) p1 = Popen(['git', 'diff'] + largs, stdout=PIPE, env=enviro, cwd=workdir) p2 = Popen(['patchview'] + rargs + unknown, stdin=p1.stdout, stdout=PIPE, env=enviro, cwd=workdir) p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. sys.stdout.buffer.write(p2.communicate()[0]) patchutils-0.4.2/patchview/gitdiffview000077500000000000000000000014561370426545100201410ustar00rootroot00000000000000#!/bin/sh # # Copyright (C) 2014-2019 Sérgio Basto # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # gitdiff --filter "$@" | vim -R - patchutils-0.4.2/patchview/svndiff000077500000000000000000000014471370426545100172710ustar00rootroot00000000000000#!/bin/sh # # Copyright (C) 2014-2019 Sérgio Basto # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # svn diff | patchview "$@" patchutils-0.4.2/patchview/svndiffview000077500000000000000000000014561370426545100201640ustar00rootroot00000000000000#!/bin/sh # # Copyright (C) 2014-2019 Sérgio Basto # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # svndiff --filter "$@" | vim -R - patchutils-0.4.2/scripts/000077500000000000000000000000001370426545100153735ustar00rootroot00000000000000patchutils-0.4.2/scripts/dehtmldiff.in000077500000000000000000000025171370426545100200410ustar00rootroot00000000000000#!/bin/sh # # dehtmldiff - fix up HTMLified diff # Copyright (C) 2003 Tim Waugh # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. version() { echo "dehtmldiff - patchutils version @VERSION@" } usage() { echo "usage: dehtmldiff [FILES...]" } while [ "$#" -gt 0 ] do case "$1" in --help) usage exit 0 ;; --version) version exit 0 ;; --) shift break ;; *) break ;; esac done sed -e ' s/<[^>]*>//g s/>/>/g s/</ "/dev/stderr"; print > "/dev/stderr"; exit 1 } { print }' | \ sed -e 's/&/\&/g' | unwrapdiff patchutils-0.4.2/scripts/editdiff.in000066400000000000000000000040251370426545100175020ustar00rootroot00000000000000#!/bin/bash # # editdiff - simple wrapper around rediff # Copyright (C) 2001-2002, 2011 Tim Waugh # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. version() { echo "editdiff - patchutils version @VERSION@" } usage() { echo "usage: editdiff FILE" } while [ "$#" -gt 0 ] do case "$1" in --help) usage exit 0 ;; --version) version exit 0 ;; --) shift || { usage; exit 1; } if [ -z "$FILE" ] then FILE="$1" fi shift [ "$#" -gt 0 ] && { usage; exit 1; } ;; *) if [ -z "$FILE" ] then FILE="$1" fi shift ;; esac done [ "$#" -gt 0 ] && { usage; exit 1; } [ -n "$FILE" ] || { usage; exit 1; } TMPD="$(mktemp -d /tmp/editdiff.XXXXXX)" || \ { echo >&2 "Failed to create temporary directory"; exit 1; } trap 'rm -rf "${TMPD}"' EXIT NAME="$(basename "${FILE}")" filterdiff -v --format=unified <"${FILE}" >"${TMPD}/${NAME}.orig" || exit 1 cp "${TMPD}/${NAME}.orig" "${TMPD}/${NAME}" || exit 1 ${EDITOR:-${VISUAL:-@DEFAULT_EDITOR@}} "${TMPD}/${NAME}" || \ { echo >&2 "Editor exited with non-zero exit status"; exit 1; } cmp -s "${TMPD}/${NAME}" "${TMPD}/${NAME}.orig" && \ { echo >&2 "No changes" ; exit 0; } mv "${FILE}" "${FILE}.orig" rediff "${TMPD}/${NAME}.orig" "${TMPD}/${NAME}" > "${FILE}" || \ { cat "${TMPD}/${NAME}" > "${FILE}"; \ echo 1>&2 "rediff failed." echo 1>&2 "Unedited patch is in ${FILE}.orig, edited patch is in ${FILE}"; exit 1; } patchutils-0.4.2/scripts/espdiff.in000066400000000000000000000030431370426545100173430ustar00rootroot00000000000000#!/bin/bash # # espdiff - do whatever it was you wanted # Copyright (C) 2003 Tim Waugh # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. version() { echo "espdiff - patchutils version @VERSION@" } usage() { echo "usage: espdiff [OPTION...] [FILE...]" } deep_brainwave=0 recurse=0 compare=0 while [ "$#" -gt 0 ] do case "$1" in --help) usage exit 0 ;; --version) version exit 0 ;; --deep-brainwave-mode) deep_brainwave=1 shift ;; --recurse) recurse=1 shift ;; --compare) compare=1 shift ;; --) shift break ;; *) break ;; esac done for each in "$@" do error=$(cat "$each" 2>&1 >/dev/null) if [ $? -ne 0 ] then echo >&2 "espdiff${error#cat}" exit 1 fi done delay=3 if [ "$deep_brainwave" -ne 0 ] then delay=$(($delay * 2)) fi read -t $delay -p 'Please concentrate... ' || echo echo 'No brainwave activity detected. Aborting.' exit 1 patchutils-0.4.2/scripts/fixcvsdiff.in000077500000000000000000000035071370426545100200660ustar00rootroot00000000000000#!@PERL@ -w # # Fixes cvs diffs so that the Index: and "---" and "+++" are in sync, # including diffs containing added or removed files, so that they patch # correctly with patch(1). # # usage: fixcvsdiff [-p] [-b] [files to fix] # # -p prints the cvs commands that will be needed when applying # the patch. # # -b keeps a .bak backup file # # Based on code by Amir Karger # # Modified by John Levon and # Ville Skyttä . # # Contributed under the terms of the GNU GPL v2 or later: # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. use Getopt::Std; our ($opt_b,$opt_p); $add = 0; getopts('pb'); if (defined($opt_b)) { $^I = '.bak'; } else { $^I = ''; } while (<>) { # get the diff fragment filename if (/^Index: (.*)/) { $Filename = $1; } if (!defined($Filename)) { print; next; } # tack the filename on the end of lines like this: # diff [options] -r?.? -r?.? s/^diff(.*) -r(\S*)$/diff$1 -r$2 $Filename/; # Allow spaces in file names; the filename ends at the first TAB. if (/^(---|\+\+\+) ([^\t]+)\t/) { my ($pre, $currfile) = ($1, $2); if ($currfile =~ m|^/dev/null|) { my $action; if ($pre eq '---') { $action = 'add'; $add = 1; } else { $action = 'remove'; } if (defined($opt_p)) { print STDOUT "cvs $action $Filename\n"; } } if ($add == 1 && $pre eq '+++' && $currfile =~ m|[^/]*|) { $add = 0; } # Replace all "(---|+++) foo" lines with the correct filename. if ($currfile ne $Filename) { # Don't use $pre here, just for safety with '+' ... s/^(---|\+\+\+) [^\t]+/$1 $Filename/; } } print; } patchutils-0.4.2/scripts/move-to-front000077500000000000000000000006711370426545100200410ustar00rootroot00000000000000#!/bin/bash if [ "$#" -eq 0 ] || [ "x$1" == "x--help" ] then echo "usage: move-to-front [PATCHES..] PATCH" exit 0 fi # Dry-run. eval "patch2=\${$#}" i=$(($# - 1)) while [ $i -gt 0 ] do eval "patch1=\${$i}" flipdiff $patch1 $patch2 >/dev/null || exit $? i=$(($i - 1)) done # Do it for real. i=$(($# - 1)) while [ $i -gt 0 ] do eval "patch1=\${$i}" (set -x; flipdiff --in-place $patch1 $patch2) || exit $? i=$(($i - 1)) done patchutils-0.4.2/scripts/recountdiff.in000077500000000000000000000065661370426545100202530ustar00rootroot00000000000000#!@PERL@ # -*- perl -*- # # recountdiff - recompute patch counts and offsets # Copyright (C) 2002 Tim Waugh # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use Getopt::Std; getopts('-:', \%opts); if ($opts{'-'} && $opts{'-'} eq 'version') { print "recountdiff - patchutils version @VERSION@\n"; exit 0; } if ($opts{'-'} && $opts{'-'} eq 'help') { print "usage: recountdiff [FILE...]\n"; exit 0; } @line=<>; # First pass: fix up the counts. $i=-1; $state=0; $chunk_start = 0; $orig=0; $new=0; $orig_offset=0; $new_offset=0; $misc=""; @off_lines = (); while ($i < $#line) { $i++; $_=$line[$i]; if ($state == 0) { # Looking for the start of a file change. unless(/^--- /) { next; } $state++; } elsif ($state == 1) { # Should be '+++ ...'. unless (/^\+\+\+ /) { if (/^--- /) { $state = 1; } else { $state = 0; } next; } $state++; } elsif ($state == 2) { # Start of chunk. Should be '@@ ...' unless (/^@@ -(\d+),?(\d+)? \+(\d+),?(\d+)? @@(.*)$/) { if (/^--- /) { $state = 1; } else { $state = 0; } next; } ($orig_offset,$new_offset,$misc) = ($1,$3,$5); $orig_offset++ if defined($2) and $2 == 0; $new_offset++ if defined($4) and $4 == 0; $state++; $orig=0; $new=0; $chunk_start = $i + 1; } elsif ($state == 3) { # Counting lines. my $spit = 0; if (/^\s/ or /^$/) { $orig++; $new++; } elsif (/^\+/) { $new++; } elsif (/^-/) { # Look out for new file changes. if (/^--- /) { if ($i+2 <= $#line) { if ($line[$i+2] =~ /^@/) { $spit = 1; } } } else { $orig++; } } elsif (/^\\/) { } else { $spit = 1; } $spit = 1 if ($i == $#line); if ($spit) { # Spit them out. $chunk_start--; $orig_offset-- if ($orig == 0); $new_offset-- if ($new == 0); $line[$chunk_start] = "@@ -$orig_offset"; $line[$chunk_start] .= ",$orig" if ($orig != 1); $line[$chunk_start] .= " +$new_offset"; $line[$chunk_start] .= ",$new" if ($new != 1); $line[$chunk_start] .= " @@" . "$misc\n"; push (@off_lines, $chunk_start); if (/^@/) { $state = 2; $i--; } else { $state = 0; $i--; push (@off_lines, -1) } } } } # Second pass: fix up the offsets. $offset = 0; foreach (@off_lines) { if ($_ == -1) { $offset = 0; next; } $line[$_] =~ /^@@ -(\d+),?(\d+)? \+(\d+),?(\d+)? @@(.*)$/; ($ooff,$oc,$nc,$misc) = ($1,$2,$4,$5); $oc = 1 unless defined($oc); $nc = 1 unless defined($nc); $noff = $ooff + $offset; $noff++ if ($oc == 0); $noff-- if ($nc == 0); $line[$_] = "@@ -$ooff"; $line[$_] .= ",$oc" if ($oc != 1); $line[$_] .= " +$noff"; $line[$_] .= ",$nc" if ($nc != 1); $line[$_] .= " @@" . "$misc\n"; $offset += $nc - $oc; } print @line; patchutils-0.4.2/scripts/splitdiff.in000077500000000000000000000066061370426545100177220ustar00rootroot00000000000000#!@PERL@ # # splitdiff - split up a diff made of incremental patches # Copyright (C) 2001, 2002, 2003, 2011 Tim Waugh # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use Getopt::Std; getopts('p:v-:D:adE', \%opts); if ($opts{'-'} && $opts{'-'} eq 'version') { print "splitdiff - patchutils version @VERSION@\n"; exit 0; } if ($opts{'-'} && $opts{'-'} eq 'help') { print "usage: splitdiff [OPTIONS] FILE\n"; print "OPTIONS are:\n"; print " -a split out every single file-level patch\n"; print " -p N pathname components to ignore\n"; print " -d use output filenames like a_b.c.patch for a/b.c\n"; print " -D dir create patches in subdirectory dir (implies -d)\n"; print " -E don't use .patch filename extension\n"; exit 0; } # Read in the input. open(IN, "<$ARGV[0]") || die "Can't open input file\n"; @input=; close(IN); $part = 1; my %written = (); sub process { print "Lines $_[0] to $_[1]\n" if ($opts{v}); if ($opts{d} || $opts{D}) { $out = $_[2]; $out =~ s,/,_,g; if ($opts{D}) { $out = sprintf("%s/%s", $opts{D}, $out); } } else { $out = sprintf ("%s.part%03d", $ARGV[0], $part); } if ($opts{D} && ! -e $opts{D}) { mkdir $opts{D} || die "Can't create output directory\n"; } unless ($opts{E}) { $out = sprintf("%s.patch", $out); } if ($written{$_[2]}) { $mode = '>>' } else { $mode = '>' } $written{$_[2]} = $_[2]; open(OUT, $mode, $out) or die "Can't open output file\n"; for $i ($_[0] .. $_[1]) { unless (($i == $_[1]) && ($input[$i - 1] =~ /^diff\s+\S+/)) { print OUT $input[$i - 1]; } } close(OUT); print "Wrote ".$mode.$out."\n"; $part++; } if($#ARGV != 0) { die "usage: splitdiff DIFF\n"; } $getlist = '${LSDIFF-lsdiff} -n '; $getlist .= '--strip='.$opts{p}.' ' if ($opts{p}); $getlist .= $ARGV[0]; # Yuck. How do you do this properly in perl? open(LIST, '-|', $getlist) or die "Can't run lsdiff"; @list = ; close LIST; my %seen = (); my @this = (); my $ready = 0; my $linenum; my $file; for (@list) { /\s*(\d+)\s*(.*)$/; ($linenum, $file) = ($1, $2); if ($ready == 1) { process ($firstline, $linenum - 1, $prevfile); $ready = 0; } $prevfile = $file; push @this, [ $linenum, $file ]; if ($opts{'a'} || $seen{$file}) { $firstline = $this[0]->[0]; $ready = 1; if ($opts{v}) { for (@this) { print $_->[0].": ".$_->[1]."\n"; } print "\n"; } @this = (); } $seen{$file} = $file; } if ($ready == 1) { process ($firstline, $linenum - 1, $file) if $linenum > $firstline; process ($linenum, $#input + 1, $file); } if ($part == 1) { print "Input contained no duplicate files; nothing to do\n"; } patchutils-0.4.2/scripts/unwrapdiff.in000077500000000000000000000134651370426545100201040ustar00rootroot00000000000000#!@PERL@ # -*- perl -*- # # unwrapdiff - demangle word-wrapped patches # Copyright (C) 2002 Tim Waugh # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Set non-zero if unwrapdiff doesn't work. It won't fix it, but at least # it'll say more. $debug = 0; $verbose = 0; use Getopt::Std; getopts('v-:', \%opts); if ($opts{'-'} && $opts{'-'} eq 'version') { print "unwrapdiff - patchutils version @VERSION@\n"; exit 0; } if ($opts{'-'} && $opts{'-'} eq 'help') { print "usage: unwrapdiff [OPTIONS] [FILE...]\n"; print "OPTIONS are:\n"; print " -v verbose output (to stderr)\n"; exit 0; } if ($opts{'v'}) { $verbose = 1; } @line=<>; $hazard = 0; $joined = 0; $i=-1; $state=0; $chunk_start = 0; $orig=0; $new=0; $orig_offset=0; $new_offset=0; $misc=""; @blankline = (); while ($i < $#line) { $i++; $_=$line[$i]; if ($state == 0) { # Looking for the start of a file change. unless(/^--- /) { next; } $state++; } elsif ($state == 1) { # Should be '+++ ...'. unless (/^\+\+\+ /) { if (/^--- /) { $state = 1; } elsif ($i + 1 < $#line && $line[$i + 1] =~ /^\+\+\+ /) { chomp($line[$i - 1]); $line[$i - 1] .= " " . $line[$i]; splice (@line, $i, 1); $joined++; $i--; $state = 1; } else { $state = 0; } next; } $state++; } elsif ($state == 2) { # Start of chunk. Should be '@@ ...' unless (/^@@ -(\d+),?(\d+)? \+(\d+),?(\d+)? @@(.*)$/) { if (/^--- /) { $state = 1; } elsif ($i + 1 < $#line && $line[$i + 1] =~ /^@@ /) { chomp($line[$i - 1]); $line[$i - 1] .= " " . $line[$i]; splice (@line, $i, 1); $joined++; $i--; $state = 2; } else { $state = 0; } next; } ($orig_offset,$orig,$new_offset,$new,$misc) = ($1,$2,$3,$4,$5); $state++; $orig = 1 unless defined($2); $new = 1 unless defined($4); $chunk_start = $i + 1; print STDERR "# State 2, $orig, $new\n" if $debug; } elsif ($state == 3) { # Counting lines. if (/^ /) { $orig--; $new--; } elsif (/^\+/) { $new--; } elsif (/^-/) { $orig--; } elsif (/^\\/) { } elsif (/^$/) { # This blank line might be meant to represent ' ', or # it might be superfluous altogether. Try ' ' first, # and if that doesn't work we can start deleting the lines # that were originally blank until the counts work. print STDERR "#Blank line $i\n" if $debug; push (@blankline, $i); $line[$i] = " \n"; $i--; next; } elsif (/^@/) { print STDERR "unwrapdiff: patch may be damaged near line " . ($i + $joined) . ".\n"; $hazard = 1; $i--; $state = 2; @blankline = (); } elsif ($chunk_start < $i) { $i--; chomp($line[$i]); print STDERR "Constructed line $i from:\n" . "$line[$i]\n$line[$i + 1]" if $debug || $verbose; # Decide whether there was a space in the line # before it was wrapped. We have to use # heuristics for this. $space = " "; $_ = $line[$i]; if (/(.)\1\1$/ && $line[$i + 1] =~ /^\Q$1$1\E/) { $space = ""; } $line[$i] .= $space . $line[$i + 1]; splice (@line, $i + 1, 1); $joined++; print STDERR "to make:\n$line[$i]" if $debug || $verbose; } if ($orig < 1 && $new < 1) { if ($orig != 0 || $new != 0) { # The numbers don't add up. if ($#blankline >= 0) { # Let's see if we can fix it by deleting lines that # were originally blank. # Remove the last line. print STDERR "# Removed $blankline[$#blankline] to fix counts\n" if $debug; splice (@line, $blankline[$#blankline], 1); splice (@blankline, $#blankline, 1); $joined++; # for line number reporting # Make all the others blank again. foreach $l (@blankline) { $line[$l] = ""; } $i = $chunk_start - 2; $state = 2; print STDERR "# Reset to $i\n" if $debug; # Re-read this hunk from the beginning again. next; } print STDERR "unwrapdiff: patch may be damaged near line " . ($i + $joined) . ".\n"; $hazard = 1; } # Check to see if the last line of this hunk seems to # be wrapped or not. If this is the last line, or the # next line starts with '--- ' or 'diff ' or 'Index: ' # then it's probably not wrapped. Otherwise it might # well be. else { unless ($i == $#line || $line[$i + 1] =~ /^@@/ || $line[$i + 1] =~ /^--- / || $line[$i + 1] =~ /^diff / || $line[$i + 1] =~ /^Index: /) { chomp($line[$i]); print STDERR "Constructed line $i from:\n" . "$line[$i]\n$line[$i + 1]" if $debug || $verbose; # Decide whether there was a space in the line # before it was wrapped. We have to use # heuristics for this. $space = " "; $_ = $line[$i]; if (/\*\*\*\*\*$/) { $space = ""; } $line[$i] .= $space . $line[$i + 1]; splice (@line, $i + 1, 1); $joined++; print STDERR "to make:\n$line[$i]" if $debug || $verbose; # But only handle one line of wrapped text in this case. } } $state = 2; @blankline = (); } } } if ($orig != 0 || $new != 0) { print STDERR "unwrapdiff: patch may be damaged.\n"; $hazard = 1; } print @line; exit ($hazard); patchutils-0.4.2/src/000077500000000000000000000000001370426545100144735ustar00rootroot00000000000000patchutils-0.4.2/src/diff.c000066400000000000000000000573551370426545100155660ustar00rootroot00000000000000/* * diff.c - diff specific util functions * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009, 2011, 2013 Tim Waugh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #ifdef HAVE_ERROR_H # include #endif /* HAVE_ERROR_H */ #include #include #include #include #ifdef HAVE_SYS_TYPES_H # include #endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ #include "diff.h" #include "util.h" int num_pathname_components (const char *x) { int num = 0; while ((x = strchr (x, '/')) != NULL) { while (*x == '/') x++; num++; } return num; } /* * Find the best name from a list. * * Of the names with the fewest path name components, select the * one with the shortest base name. Of any remaining candidates, * select the one with the shortest name. * */ char *best_name (int n, char **names) { int *pathname_components; int *basename_length; int *is_dev_null; int best_pn, best_bn, best_n, best = 0; /* shut gcc up */ int i; pathname_components = xmalloc (sizeof (int) * n); basename_length = xmalloc (sizeof (int) * n); is_dev_null = xmalloc (sizeof (int) * n); best_pn = -1; for (i = 0; i < n; i++) { is_dev_null[i] = !strcmp (names[i], "/dev/null"); if (is_dev_null[i]) continue; pathname_components[i] = num_pathname_components (names[i]); if ((best_pn == -1) || (pathname_components[i] < best_pn)) best_pn = pathname_components[i]; } best_bn = -1; for (i = 0; i < n; i++) { char *p; if (is_dev_null[i]) continue; if (pathname_components[i] != best_pn) continue; p = strrchr (names[i], '/'); if (p) p++; else p = names[i]; basename_length[i] = strlen (p); if ((best_bn == -1) || (basename_length[i] < best_bn)) best_bn = basename_length[i]; } best_n = -1; for (i = 0; i < n; i++) { int len; if (is_dev_null[i]) continue; if (pathname_components[i] != best_pn) continue; if (basename_length[i] != best_bn) continue; len = strlen (names[i]); if ((best_n == -1) || (len < best_n)) { best_n = len; best = i; } } free (pathname_components); free (basename_length); free (is_dev_null); return names[best]; } const char *stripped (const char *name, int num_components) { const char *basename; int i = 0; if (!strcmp (name, "/dev/null")) return name; basename = strrchr (name, '/'); if (!basename) basename = name; else basename++; while (i < num_components && (name = strchr (name, '/')) != NULL) { while (*name == '/') name++; i++; } return name ? name : basename; } unsigned long calculate_num_lines (const char *atatline, char which) { char *p = strchr (atatline, which); if (!p) return 1; while (*p && *p != ',' && *p != ' ') p++; if (!*p || *p == ' ') return 1; return strtoul (p + 1, NULL, 10); } unsigned long orig_num_lines (const char *atatline) { return calculate_num_lines (atatline, '-'); } unsigned long new_num_lines (const char *atatline) { return calculate_num_lines (atatline, '+'); } /* Parse an @@ line. */ int read_atatline (const char *atatline, unsigned long *orig_offset, unsigned long *orig_count, unsigned long *new_offset, unsigned long *new_count) { char *endptr; unsigned long res; char *p; if (orig_offset) { p = strchr (atatline, '-'); if (!p) return 1; p++; res = strtoul (p, &endptr, 10); if (p == endptr) return 1; *orig_offset = res; } if (orig_count) *orig_count = orig_num_lines (atatline); if (new_offset) { p = strchr (atatline, '+'); if (!p) return 1; p++; res = strtoul (p, &endptr, 10); if (p == endptr) return 1; *new_offset = res; } if (new_count) *new_count = new_num_lines (atatline); return 0; } static void copy_context_hunks (char **line, size_t *linelen, ssize_t *got, unsigned long *linenum) { for (;;) { unsigned long unchanged = 0; unsigned long line_start, line_end, line_count; char *n, *end; int i; for (i = 0; i < 2; i++) { int first = 1; *got = getline (line, linelen, stdin); if (*got == -1) return; ++*linenum; if (!i && !strncmp (*line, "***************", 15)) { /* Some diffs seem to have this for * every set of changes. SuSV2 says * not to, but the GNU diff info page * disagrees. */ i--; continue; } if (strncmp (*line, i ? "--- " : "*** ", 4)) return; do_line_counts: n = *line + 4; line_start = strtoul (n, &end, 10); if (n == end) return; if (*end == ',') { n = end + 1; line_end = strtoul (n, &end, 10); if (n == end) return; if (line_start > line_end) return; line_count = line_end - line_start + 1; } else { line_end = line_start; line_count = line_start ? 1 : 0; } fwrite (*line, (size_t) *got, 1, stdout); if (i && line_count == unchanged) break; while (line_count--) { *got = getline (line, linelen, stdin); if (*got == -1) return; ++*linenum; if (!i && first) { first = 0; if (!strncmp (*line, "--- ", 4)) { /* From lines were omitted. */ i++; goto do_line_counts; } } fwrite (*line, (size_t) *got, 1, stdout); if (**line == ' ') unchanged++; } } } } static void convert_unified_hunks_to_context (char **line, size_t *linelen, ssize_t *got, unsigned long *linenum) { unsigned long orig_offset, orig_count = 0, new_offset, new_count = 0; char **orig_line = NULL, **new_line = NULL; char **orig_what = NULL, **new_what = NULL; char **whats = NULL; unsigned int n_whats = 0; unsigned long orig_linenum, new_linenum; const char *no_newline_str = "\\ No newline at end of file\n"; char *misc = NULL; if (feof (stdin)) goto eof; if ((*got = getline (line, linelen, stdin)) == -1) goto eof; ++*linenum; for (;;) { char *last_orig = NULL; char *last_new = NULL; char *what = NULL; int newline = 1; int can_omit_from = 1, can_omit_to = 1; unsigned long i; misc = NULL; if (read_atatline (*line, &orig_offset, &orig_count, &new_offset, &new_count)) return; misc = strchr (*line + 2, '@'); misc += 2; misc = xstrdup (misc); /* Read in the change lines. */ orig_line = xmalloc (sizeof (char *) * orig_count); new_line = xmalloc (sizeof (char *) * new_count); orig_what = xmalloc (sizeof (char *) * orig_count); new_what = xmalloc (sizeof (char *) * new_count); whats = xmalloc (sizeof (char *) * (orig_count + new_count)); orig_linenum = new_linenum = 0; while ((orig_linenum < orig_count) || (new_linenum < new_count) || newline) { int get_out = 0; if ((*got = getline (line, linelen, stdin)) == -1) /* Should write out everything to date? */ break; ++*linenum; if (orig_linenum >= orig_count && new_linenum >= new_count && **line != '\\') break; switch (**line) { case ' ': if (orig_linenum == orig_count) /* We've already seen all the orig * lines we were expecting. */ error (EXIT_FAILURE, 0, "Garbled input at line %lu", *linenum); if (new_linenum == new_count) /* We've already seen all the new * lines we were expecting. */ error (EXIT_FAILURE, 0, "Garbled input at line %lu", *linenum); what = NULL; orig_what[orig_linenum] = " "; new_what[new_linenum] = " "; orig_line[orig_linenum] = xstrdup (*line + 1); new_line[new_linenum] = xstrdup (*line + 1); last_orig = orig_line[orig_linenum++]; last_new = new_line[new_linenum++]; break; case '-': if (orig_linenum == orig_count) /* We've already seen all the orig * lines we were expecting. */ error (EXIT_FAILURE, 0, "Garbled input at line %lu", *linenum); if (what) { if (*what != '-') *what = '!'; } else { what = xmalloc (sizeof (char)); *what = '-'; whats[n_whats++] = what; } orig_what[orig_linenum] = what; orig_line[orig_linenum] = xstrdup (*line + 1); last_orig = orig_line[orig_linenum++]; last_new = NULL; can_omit_from = 0; break; case '+': if (new_linenum == new_count) /* We've already seen all the new * lines we were expecting. */ error (EXIT_FAILURE, 0, "Garbled input at line %lu", *linenum); if (what) { if (*what != '+') *what = '!'; } else { what = xmalloc (sizeof (char)); *what = '+'; whats[n_whats++] = what; } new_what[new_linenum] = what; new_line[new_linenum] = xstrdup (*line + 1); last_orig = NULL; last_new = new_line[new_linenum++]; can_omit_to = 0; break; case '\\': if (last_orig) last_orig[strlen(last_orig)-1] = '\0'; if (last_new) last_new[strlen(last_new)-1] = '\0'; last_orig = last_new = NULL; newline = 0; break; default: get_out = 1; } if (get_out) break; } if ((orig_linenum < orig_count) || (new_linenum < new_count)) error (EXIT_FAILURE, 0, "Garbled input at line %lu", *linenum); printf ("*** %lu", orig_offset); if (orig_count) printf (",%lu", orig_offset + orig_count - 1); printf (" ****%s", misc); if (!can_omit_from) for (i = 0; i < orig_count; i++) { char *l = orig_line[i]; printf ("%c %s", *orig_what[i], l); if (l[strlen (l) - 1] != '\n') printf ("\n%s", no_newline_str); } printf ("--- %lu", new_offset); if (new_count) printf (",%lu", new_offset + new_count - 1); puts (" ----"); if (!can_omit_to) for (i = 0; i < new_count; i++) { char *l = new_line[i]; printf ("%c %s", *new_what[i], l); if (l[strlen (l) - 1] != '\n') printf ("\n%s", no_newline_str); } eof: for (i = 0; i < orig_count; i++) free (orig_line[i]); for (i = 0; i < new_count; i++) free (new_line[i]); for (i = 0; i < n_whats; i++) free (whats[i]); free (orig_line); free (new_line); free (orig_what); free (new_what); free (whats); free (misc); orig_count = new_count = n_whats = 0; orig_line = new_line = NULL; orig_what = new_what = NULL; whats = NULL; misc = NULL; if (feof (stdin)) return; } } /* Read diff on stdin, write context format version on stdout. * Note: stdin may already be in context format. */ static void do_convert_to_context (void) { char *line = NULL; size_t linelen = 0; unsigned long linenum = 0; ssize_t got = getline (&line, &linelen, stdin); if (got == -1) return; linenum++; for (;;) { int is_context = 0; for (;;) { if (feof (stdin)) goto eof; if (!strncmp (line, "--- ", 4)) { is_context = 0; break; } if (!strncmp (line, "*** ", 4)) { is_context = 1; break; } fwrite (line, (size_t) got, 1, stdout); got = getline (&line, &linelen, stdin); if (got == -1) goto eof; linenum++; } if (is_context) { fwrite (line, (size_t) got, 1, stdout); got = getline (&line, &linelen, stdin); if (got == -1) goto eof; linenum++; if (strncmp (line, "--- ", 4)) continue; fwrite (line, (size_t) got, 1, stdout); got = getline (&line, &linelen, stdin); if (got == -1) goto eof; linenum++; if (strncmp (line, "***************", 15)) continue; fwrite (line, (size_t) got, 1, stdout); copy_context_hunks (&line, &linelen, &got, &linenum); } else { printf ("*** %s", line + 4); got = getline (&line, &linelen, stdin); if (got == -1) goto eof; linenum++; if (strncmp (line, "+++ ", 4)) continue; printf ("--- "); fwrite (line + 4, (size_t) got - 4, 1, stdout); puts ("***************"); convert_unified_hunks_to_context (&line, &linelen, &got, &linenum); } } eof: if (line) free (line); return; } static void copy_unified_hunks (char **line, size_t *linelen, ssize_t *got, unsigned long *linenum) { unsigned long orig_count = 0, new_count = 0; unsigned long orig_offset, new_offset; for (;;) { if (feof (stdin)) return; *got = getline (line, linelen, stdin); if (*got == -1) return; ++*linenum; if (!orig_count && !new_count && **line != '\\') { if (strncmp (*line, "@@ ", 3)) break; if (read_atatline (*line, &orig_offset, &orig_count, &new_offset, &new_count)) error (EXIT_FAILURE, 0, "line %lu not understood: %s", *linenum, *line); fwrite (*line, (size_t) *got, 1, stdout); continue; } if (orig_count && **line != '+') orig_count--; if (new_count && **line != '-') new_count--; fwrite (*line, (size_t) *got, 1, stdout); } } static void convert_context_hunks_to_unified (char **line, size_t *linelen, ssize_t *got, unsigned long *linenum) { int happy = 1; while (happy) { size_t i; char *misc = NULL; unsigned long unchanged = 0; unsigned long line_start[2], line_end, line_count[2]; char *n, *end; char **lines[2]; size_t *linelengths[2]; size_t n_lines[2]; size_t at[2]; n_lines[0] = n_lines[1] = 0; linelengths[0] = linelengths[1] = NULL; lines[0] = lines[1] = NULL; for (i = 0; i < 2; i++) { int first = 1; unsigned long lnum; if (feof (stdin)) goto eof; *got = getline (line, linelen, stdin); if (*got == -1) goto eof; ++*linenum; if (!i && !misc && !strncmp (*line, "***************", 15)) { char *m = *line + 15; if (strcmp (m, "\n")) misc = xstrdup (m); i--; continue; } if (strncmp (*line, i ? "--- " : "*** ", 4)) goto unhappy; do_line_counts: n = *line + 4; line_start[i] = strtoul (n, &end, 10); if (n == end) goto unhappy; if (*end == ',') { n = end + 1; line_end = strtoul (n, &end, 10); if (n == end) goto unhappy; if (line_start[i] > line_end) goto unhappy; line_count[i] = line_end - line_start[i] + 1; } else { line_end = line_start[i]; line_count[i] = line_start[i] ? 1 : 0; } n = strstr (n, i ? "----" : "****"); if (!misc) misc = xstrdup (n + 4); if (i && line_count[i] == unchanged) break; n_lines[i] = line_count[i]; lines[i] = xmalloc (sizeof (char *) * line_count[i]); linelengths[i] = xmalloc (sizeof (size_t) * line_count[i]); memset (lines[i], 0, sizeof (char *) * line_count[i]); for (lnum = 0; lnum < line_count[i]; lnum++) { *got = getline (line, linelen, stdin); if (*got == -1) goto eof; ++*linenum; if (!i && first) { first = 0; if (!strncmp (*line, "--- ", 4)) { /* From lines were omitted. */ n_lines[i] = 0; i++; goto do_line_counts; } } lines[i][lnum] = xmalloc ((size_t) *got + 1); memcpy (lines[i][lnum], *line, (size_t) *got); lines[i][lnum][*got] = '\0'; linelengths[i][lnum] = (size_t) *got; if (**line == ' ') unchanged++; } } printf ("@@ -%lu", line_start[0]); if (line_count[0] != 1) printf (",%lu", line_count[0]); printf (" +%lu", line_start[1]); if (line_count[1] != 1) printf (",%lu", line_count[1]); printf (" @@%s", misc); /* There MUST be an easier way than this!! */ at[0] = at[1] = 0; while (at[0] < n_lines[0] || at[1] < n_lines[1]) { char *l[2] = { NULL, NULL }; size_t llen[2]; llen[0] = llen[1] = 0; if (lines[0] && at[0] < n_lines[0]) { l[0] = lines[0][at[0]]; llen[0] = linelengths[0][at[0]]; } if (lines[1] && at[1] < n_lines[1]) { l[1] = lines[1][at[1]]; llen[1] = linelengths[1][at[1]]; } if (l[0] && *l[0] == ' ' && l[1] && *l[1] == ' ') { fwrite (l[0] + 1, llen[0] - 1, 1, stdout); at[0]++; at[1]++; } else if (l[0] && *l[0] == ' ' && !l[1]) { fwrite (l[0] + 1, llen[0] - 1, 1, stdout); at[0]++; } else if (l[0] && *l[0] == '-') { putchar ('-'); fwrite (l[0] + 2, llen[0] - 2, 1, stdout); at[0]++; } else if (l[1] && *l[1] == '+') { putchar ('+'); fwrite (l[1] + 2, llen[1] - 2, 1, stdout); at[1]++; } else if (l[0] && *l[0] == '!' && l[1] && *l[1] == '!') { while (at[0] < n_lines[0] && *lines[0][at[0]] == '!') { putchar ('-'); fwrite (lines[0][at[0]] + 2, linelengths[0][at[0]] - 2, 1, stdout); at[0]++; } while (at[1] < n_lines[1] && *lines[1][at[1]] == '!') { putchar ('+'); fwrite (lines[1][at[1]] + 2, linelengths[1][at[1]] - 2, 1, stdout); at[1]++; } } else if (l[0] && *l[0] == '!') { putchar ('-'); fwrite (l[0] + 2, llen[0] - 2, 1, stdout); at[0]++; } else if (l[1] && *l[1] == '!') { putchar ('+'); fwrite (l[1] + 2, llen[1] - 2, 1, stdout); at[1]++; } else if (l[0] && *l[0] == '\\') { fwrite (l[0], llen[0], 1, stdout); putchar ('\n'); at[0]++; } else if (l[1] && *l[1] == '\\') { fwrite (l[1], llen[1], 1, stdout); putchar ('\n'); at[1]++; } else if (!l[0]) { putchar (*l[1]); fwrite (l[1] + 2, llen[1] - 2, 1, stdout); at[1]++; } else { printf ("Don't know how to handle this:\n" "1: %s2: %s", l[0], l[1]); exit (1); } } eof: free (misc); for (i = 0; i < n_lines[0]; i++) free (lines[0][i]); for (i = 0; i < n_lines[1]; i++) free (lines[1][i]); free (lines[0]); free (linelengths[0]); free (lines[1]); free (linelengths[1]); if (feof (stdin)) return; continue; unhappy: happy = 0; goto eof; } } /* Read diff on stdin, write unified format version on stdout. * Note: stdin may already be in unified format. */ static void do_convert_to_unified (void) { char *line = NULL; size_t linelen = 0; unsigned long linenum = 0; ssize_t got = getline (&line, &linelen, stdin); if (got == -1) return; linenum++; for (;;) { int is_context = 0; for (;;) { if (feof (stdin)) goto eof; if (!strncmp (line, "--- ", 4)) { is_context = 0; break; } if (!strncmp (line, "*** ", 4)) { is_context = 1; break; } fwrite (line, (size_t) got, 1, stdout); got = getline (&line, &linelen, stdin); if (got == -1) goto eof; linenum++; } if (is_context) { printf ("--- %s", line + 4); got = getline (&line, &linelen, stdin); if (got == -1) goto eof; linenum++; if (strncmp (line, "--- ", 4)) continue; printf ("+++ "); fwrite (line + 4, (size_t) got - 4, 1, stdout); convert_context_hunks_to_unified (&line, &linelen, &got, &linenum); } else { fwrite (line, (size_t) got, 1, stdout); got = getline (&line, &linelen, stdin); if (got == -1) goto eof; linenum++; if (strncmp (line, "+++ ", 4)) continue; fwrite (line, (size_t) got, 1, stdout); copy_unified_hunks (&line, &linelen, &got, &linenum); } } eof: if (line) free (line); return; } static FILE *do_convert (FILE *f, const char *mode, int seekable, void (*fn) (void)) { int fildes[2]; int fd = fileno (f); FILE *ret; fflush (NULL); if (strchr (mode, 'r')) { if (strchr (mode, 'w') || strchr (mode, '+')) /* Can't do bidirectional conversions. */ return NULL; /* Read from f (which may be in unified format), and * return a FILE* that gives context format when * read. */ if (pipe (fildes)) error (EXIT_FAILURE, errno, "pipe failed"); switch (fork ()) { case -1: error (EXIT_FAILURE, errno, "fork failed"); default: /* Parent. */ close (fildes[1]); ret = fdopen (fildes[0], mode); if (!ret) error (EXIT_FAILURE, errno, "fdopen failed"); if (seekable) { FILE *tmp = xtmpfile (); while (!feof (ret)) { int c = fgetc (ret); if (c == EOF) break; fputc (c, tmp); } fclose (ret); rewind (tmp); return tmp; } return ret; case 0: /* Child. */ #ifdef PROFILE { extern void _start (void), etext (void); monstartup ((u_long) &_start, (u_long) &etext); } #endif #ifdef DEBUG sleep (10); #endif /* DEBUG */ close (fildes[0]); if (fd != STDIN_FILENO) { dup2 (fd, STDIN_FILENO); fclose (f); } if (fildes[1] != STDOUT_FILENO) dup2 (fildes[1], STDOUT_FILENO); (*fn) (); exit (0); } } else if (strchr (mode, 'w')) { if (strchr (mode, 'r') || strchr (mode, '+')) /* Can't do bidirectional conversions. */ return NULL; /* Return a FILE* that, when written in unified * format, sends cnotext format to f. */ if (pipe (fildes)) error (EXIT_FAILURE, errno, "pipe failed"); switch (fork ()) { case -1: error (EXIT_FAILURE, errno, "fork failed"); default: /* Parent. */ close (fildes[1]); return fdopen (fildes[1], mode); case 0: /* Child. */ #ifdef PROFILE { extern void _start (void), etext (void); monstartup ((u_long) &_start, (u_long) &etext); } #endif close (fildes[0]); if (fildes[0] != STDIN_FILENO) dup2 (fildes[0], STDIN_FILENO); if (fd != STDOUT_FILENO) { dup2 (fd, STDOUT_FILENO); fclose (f); } (*fn) (); exit (0); } } return NULL; } FILE *convert_to_context (FILE *f, const char *mode, int seekable) { return do_convert (f, mode, seekable, do_convert_to_context); } FILE *convert_to_unified (FILE *f, const char *mode, int seekable) { return do_convert (f, mode, seekable, do_convert_to_unified); } static int read_timezone (const char *tz) { int zone = -1; char *endptr; tz += strspn (tz, " "); zone = strtol (tz, &endptr, 10); if (tz == endptr) zone = -1; return zone; } int read_timestamp (const char *timestamp, struct tm *result, long *zone) { char *end; struct tm tm_t; long zone_t; if (!result) result = &tm_t; if (!zone) zone = &zone_t; timestamp += strspn (timestamp, " \t"); /* First try ISO 8601-style timestamp */ end = strptime (timestamp, "%Y-%m-%d %H:%M:%S", result); if (end) { /* Skip nanoseconds. */ if (*end == '.') { end++; end += strspn (end, "0123456789"); } *zone = read_timezone (end); } else { /* If that fails try a traditional format */ if ((end = strptime (timestamp, "%a %b %e %T %Y", result))) *zone = read_timezone (end); else if ((end = strptime (timestamp, "%b %Y %H:%M:%S", result))) *zone = read_timezone (end); else return 1; } return 0; } char * filename_from_header (const char *header) { int first_space = strcspn (header, " \t\n"); int h = first_space; while (header[h] == ' ') { int i; i = strspn (header + h, " \t"); if (!header[h + i]) break; if (!read_timestamp (header + h + i, NULL, NULL)) break; h += i + 1; h += strcspn (header + h, " \t\n"); } if (header[h] == '\n' && h > first_space) /* If we couldn't see a date we recognized, but did see at least one space, split at the first. */ h = first_space; return xstrndup (header, h); } patchutils-0.4.2/src/diff.h000066400000000000000000000036731370426545100155650ustar00rootroot00000000000000/* * diff.h - diff specific util functions - header * Copyright (C) 2001, 2002, 2003 Tim Waugh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #include int num_pathname_components (const char *x); /* * Find the best name from a list. * * Of the names with the fewest path name components, select the * one with the shortest base name. * */ char *best_name (int n, char **names); /* * Strip a pathname by a specified number of components. */ const char *stripped (const char *name, int num_components); unsigned long calculate_num_lines (const char *atatline, char which); unsigned long orig_num_lines (const char *atatline); unsigned long new_num_lines (const char *atatline); int read_atatline (const char *atatline, unsigned long *orig_offset, unsigned long *orig_count, unsigned long *new_offset, unsigned long *new_count); /* Conversion between formats. */ FILE *convert_to_context (FILE *destination, const char *mode, int seekable); FILE *convert_to_unified (FILE *destination, const char *mode, int seekable); /* Filename/timestamp separation. */ int read_timestamp (const char *timestamp, struct tm *result /* may be NULL */, long *zone /* may be NULL */); char *filename_from_header (const char *header); patchutils-0.4.2/src/filterdiff.c000066400000000000000000001277511370426545100167720ustar00rootroot00000000000000/* * filterdiff - extract (or exclude) a diff from a diff file * lsdiff - show which files are modified by a patch * grepdiff - show files modified by a patch containing a regexp * Copyright (C) 2001, 2002, 2003, 2004, 2008, 2009, 2011, 2013, 2014 Tim Waugh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #ifdef HAVE_ERROR_H # include #endif /* HAVE_ERROR_H */ #ifdef HAVE_SYS_TYPES_H # include // for ssize_t #endif /* HAVE_SYS_TYPES_H */ #include #include #include #ifdef HAVE_PCRE2POSIX_H # include #else # include #endif #include #include #include #include #include #include "util.h" #include "diff.h" struct range { struct range *next; unsigned long start; unsigned long end; }; enum line_numbering { None = 0, Before, After }; enum { output_none = 0, output_hunk, output_file } output_matching = output_none; enum { only_match_all = 0, only_match_rem, only_match_add, only_match_mod /* bitwise rem | add */ } only_matching = only_match_all; static struct patlist *pat_include = NULL; static struct patlist *pat_exclude = NULL; static struct range *hunks = NULL; static struct range *lines = NULL; static struct range *files = NULL; static enum line_numbering number_lines = None; static int number_files = 0; static int files_exclude = 0; static int lines_exclude = 0; static int hunks_exclude = 0; static int unzip = 0; static enum { mode_filter, mode_list, mode_grep, } mode; static regex_t *regex = NULL; static size_t num_regex = 0; static int clean_comments = 0; static int numbering = 0; static int annotating = 0; static int ignore_components = 0; static int strip_components = 0; static const char *prefix_to_add = NULL; static const char *old_prefix_to_add = NULL; static const char *new_prefix_to_add = NULL; static int show_status = 0; static int verbose = 0; static int removing_timestamp = 0; static int egrepping = 0; static int print_patchnames = -1; static int empty_files_as_absent = 0; static unsigned long filecount=0; static int regexecs (regex_t *regex, size_t num_regex, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags) { size_t i; int ret = REG_NOMATCH; for (i = 0; i < num_regex; i++) if (!(ret = regexec (®ex[i], string, nmatch, pmatch, eflags))) break; return ret; } static int file_exists (const char *name, const char *timestamp) { struct tm t; long zone = -1; if (!strcmp (name, "/dev/null")) return 0; if (read_timestamp (timestamp, &t, &zone)) return 1; /* If the time is less that fifteen hours either side of the * start of 1970, and it's an exact multiple of 15 minutes, it's * very likely to be the result of ctime(&zero). */ if (t.tm_sec == 0 && ((t.tm_year == 69 && t.tm_mon == 11 && t.tm_mday == 31 && t.tm_hour >= 9) || (t.tm_year == 70 && t.tm_mon == 0 && t.tm_mday == 1 && t.tm_hour <= 15)) && (t.tm_min % 15) == 0) { if (zone != -1) { /* Extra checking, since we know the timezone. */ long offset = 0; if (t.tm_year == 69) { offset = 100 * (t.tm_hour - 24); if (t.tm_min) offset += 100 + t.tm_min - 60; } else { offset = 100 * t.tm_hour; offset += t.tm_min; } if (offset != zone) return 1; } return 0; } /* Otherwise, it's a real file timestamp. */ return 1; } static int output_header_line (const char *line) { char *fn; if (strncmp (line, "diff", 4) == 0 && isspace (line[4])) { size_t args = 0; const char *end = line + 5, *begin = end, *ws = end; printf ("%.5s", line); while (*end != 0) { if (isspace (*begin)) begin = end; if (isspace (*end)) { if (*begin == '-') { if (isspace (begin[1])) ++args; printf ("%.*s", (int)(end - ws), ws); } else { printf ("%.*s", (int)(begin - ws), ws); if (args == 0 && old_prefix_to_add) fputs (old_prefix_to_add, stdout); if (args == 1 && new_prefix_to_add) fputs (new_prefix_to_add, stdout); ++args; fn = xstrndup (begin, end - begin); fputs (stripped (fn, strip_components), stdout); free (fn); } ws = begin = end; } ++end; } printf ("%.*s", (int)(end - ws), ws); } else if (strncmp (line, "---", 3) == 0 || strncmp (line, "+++", 3) == 0) { int h = strcspn (line + 4, "\t\n"); fwrite (line, 1, 4, stdout); if (prefix_to_add) fputs (prefix_to_add, stdout); else { if (old_prefix_to_add && strncmp (line, "---", 3) == 0) fputs (old_prefix_to_add, stdout); if (new_prefix_to_add && strncmp (line, "+++", 3) == 0) fputs (new_prefix_to_add, stdout); } fn = xstrndup (line + 4, h); fputs (stripped (fn, strip_components), stdout); if (removing_timestamp) putchar ('\n'); else fputs (line + 4 + h, stdout); free (fn); } else fputs (line, stdout); return 0; } static int file_matches (void) { int f = 0; struct range *r; // See if the file range list includes this file. -1UL is a // wildcard. for (r = files; r; r = r->next) if ((r->start == -1UL || r->start <= filecount) && (r->end == -1UL || filecount <= r->end)) { f = 1; break; } if (files && !f && !files_exclude) return 0; if (files && f && files_exclude) return 0; return 1; } static void display_filename (unsigned long linenum, char status, const char *filename, const char *patchname) { if (mode == mode_list && !file_matches ()) /* This is lsdiff --files=... and this file is not to be * listed. */ return; if (print_patchnames) printf ("%s:", patchname); if (numbering) printf ("%lu\t", linenum); if (number_files) printf ("File #%-3lu\t", filecount); if (show_status) printf ("%c ", status); if (prefix_to_add) fputs (prefix_to_add, stdout); puts (stripped (filename, strip_components)); } static int hunk_matches (unsigned long orig_offset, unsigned long orig_count, unsigned long hunknum) { int h = 0, l = 0; struct range *r; /* The hunk can't match if the containing file doesn't. */ if (!file_matches ()) return 0; // For the purposes of matching, zero lines at offset n counts // as line n. if (!orig_count) orig_count = 1; // See if the hunk range list includes this hunk. -1UL is a // wildcard. for (r = hunks; r; r = r->next) if ((r->start == -1UL || r->start <= hunknum) && (r->end == -1UL || hunknum <= r->end)) { h = 1; break; } // See if the lines range list includes this hunk. -1UL is a // wildcard. for (r = lines; r; r = r->next) if ((r->start == -1UL || r->start < (orig_offset + orig_count)) && (r->end == -1UL || r->end >= orig_offset)) { l = 1; break; } if (hunks && !h && !hunks_exclude) return 0; if (hunks && h && hunks_exclude) return 0; if (lines && !l && !lines_exclude) return 0; if (lines && l && lines_exclude) return 0; return 1; } static int do_unified (FILE *f, char **header, unsigned int num_headers, int match, char **line, size_t *linelen, unsigned long *linenum, unsigned long start_linenum, char status, const char *bestname, const char *patchname, int *orig_file_exists, int *new_file_exists) { /* Skip hunk. */ unsigned long orig_count = 0, new_count = 0; unsigned long orig_offset, new_offset; unsigned long hunknum = 0; unsigned long track_linenum = 0; int header_displayed = 0; int hunk_match = match; long munge_offset = 0; int displayed_filename = 0; unsigned long last_hunkmatch = 0; unsigned long hunk_linenum = *linenum; FILE *match_tmpf = NULL; int grepmatch = 0; long delayed_munge = 0; int ret = 0; int orig_is_empty = 1, new_is_empty = 1; /* assume until otherwise */ if (output_matching == output_file) match_tmpf = xtmpfile (); for (;;) { ssize_t got = getline (line, linelen, f); if (got == -1) { ret = EOF; goto out; } ++*linenum; if (!orig_count && !new_count && **line != '\\') { char *trailing; if (strncmp (*line, "@@ ", 3)) break; /* Next chunk. */ hunknum++; hunk_linenum = *linenum; if (output_matching == output_hunk && !grepmatch) // We are missing this hunk out, but // we need to remember how many lines // it would have added or removed. munge_offset += delayed_munge; if (output_matching != output_file) grepmatch = 0; if (output_matching == output_hunk) { if (match_tmpf) fclose (match_tmpf); match_tmpf = xtmpfile (); } if (read_atatline (*line, &orig_offset, &orig_count, &new_offset, &new_count)) error (EXIT_FAILURE, 0, "line not understood: %s", *line); if (orig_count) orig_is_empty = 0; if (new_count) new_is_empty = 0; // Decide if this hunk matches. if (match) hunk_match = hunk_matches (orig_offset, orig_count, hunknum); else hunk_match = 0; trailing = strchr (*line, '+'); trailing += strcspn (trailing, " \n"); if (*trailing == ' ') trailing++; trailing += strspn (trailing, "@"); if (hunk_match && numbering && verbose && mode != mode_grep) { if (print_patchnames) printf ("%s-", patchname); printf ("\t%lu\tHunk #%lu", hunk_linenum, hunknum); if (verbose > 1) { char *p = trailing; if (*p != '\n') p++; printf ("\t%s", p); } else putchar ('\n'); } if (hunk_match && (mode == mode_filter || output_matching != output_none)) { int first_hunk = !header_displayed; FILE *output_to = stdout; if (mode == mode_grep) { delayed_munge = orig_count - new_count; if (!grepmatch) output_to = match_tmpf; } if (!header_displayed && mode != mode_grep) { // Display the header. unsigned int i; for (i = 0; i < num_headers - 2; i++) output_header_line (header[i]); if (number_lines != After) output_header_line (header[num_headers - 2]); if (number_lines != Before) output_header_line (header[num_headers - 1]); header_displayed = 1; } switch (number_lines) { case None: // Display the offsets and // counts, adjusting for any // hunks we've previously // missed out. fprintf (output_to, "@@ -%lu", orig_offset); if (orig_count != 1) fprintf (output_to, ",%lu", orig_count); fprintf (output_to, " +%lu", new_offset + munge_offset); if (new_count != 1) fprintf (output_to, ",%lu", new_count); fprintf (output_to, " @@"); if (annotating) fprintf (output_to, " Hunk #%lu, %s", hunknum, bestname); if (clean_comments) fputs ("\n", output_to); else { int idx = trailing - *line; fwrite (trailing, (size_t) got-idx, 1, output_to); } break; case Before: // Note the initial line number track_linenum = orig_offset; if (!first_hunk || (output_matching == output_file && hunknum > 1)) fputs ("...\n", output_to); break; case After: // Note the initial line number track_linenum = (new_offset + munge_offset); if (!first_hunk || (output_matching == output_file && hunknum > 1)) fputs ("...\n", output_to); break; } } else if (mode == mode_filter) // We are missing this hunk out, but // we need to remember how many lines // it would have added or removed. munge_offset += orig_count - new_count; continue; } if (**line != '\\') { if (orig_count && **line != '+') orig_count--; if (new_count && **line != '-') new_count--; } if (hunk_match && mode == mode_grep && (only_matching == only_match_all || (**line == '-' && only_matching & only_match_rem) || (**line == '+' && only_matching & only_match_add) ) && !regexecs (regex, num_regex, *line + 1, 0, NULL, 0)) { if (output_matching == output_none) { if (!displayed_filename) { displayed_filename = 1; display_filename (start_linenum, status, bestname, patchname); } if (numbering && verbose && hunknum > last_hunkmatch) { last_hunkmatch = hunknum; if (print_patchnames) printf ("%s-", patchname); printf ("\t%lu\tHunk #%lu\n", hunk_linenum, hunknum); } } else { if (match_tmpf) { if (!header_displayed) { unsigned int i; for (i = 0; i < num_headers - 2; i++) output_header_line (header[i]); if (number_lines != After) output_header_line (header[num_headers - 2]); if (number_lines != Before) output_header_line (header[num_headers - 1]); header_displayed = 1; } rewind (match_tmpf); while (!feof (match_tmpf)) { int ch = fgetc (match_tmpf); if (ch == EOF) break; putchar (ch); } fclose (match_tmpf); match_tmpf = NULL; } grepmatch = 1; } } if (hunk_match && (mode == mode_filter || output_matching != output_none)) { FILE *output_to = stdout; if (mode == mode_grep && !grepmatch) output_to = match_tmpf; if (number_lines == None) // Just display each line. fwrite (*line, (size_t) got, 1, output_to); else if ((number_lines == Before && **line != '+') || (number_lines == After && **line != '-')) { // Numbered line. const char *rest = *line; if (rest[0] != '\n') // Handle whitespace damage rest++; fprintf (output_to, "%lu\t:%s", track_linenum++, rest); } } } out: if (match_tmpf) fclose (match_tmpf); if (empty_files_as_absent) { if (orig_file_exists != NULL && orig_is_empty) *orig_file_exists = 0; if (new_file_exists != NULL && new_is_empty) *new_file_exists = 0; } return ret; } static int do_context (FILE *f, char **header, unsigned int num_headers, int match, char **line, size_t *linelen, unsigned long *linenum, unsigned long start_linenum, char status, const char *bestname, const char *patchname, int *orig_file_exists, int *new_file_exists) { /* Skip before and after segments. */ unsigned long line_start, line_end, line_count; unsigned long hunknum = 0; unsigned long track_linenum = 0; unsigned long changed[2]; long munge_offset = 0; int header_displayed = 0; char *n, *end; int i; int hunk_match = 0; int displayed_filename = 0; unsigned long last_hunkmatch = 0; unsigned long hunk_linenum = *linenum; FILE *match_tmpf = NULL; int grepmatch = 0; int ret = 0; unsigned long unchanged; int first_hunk = 0; int orig_is_empty = 1, new_is_empty = 1; /* assume until otherwise */ size_t got = 0; /* Context diff hunks are like this: * * *************** [GNU diff can put stuff here] * *** start[,end] **** [we sometimes put stuff here] * from lines... (omitted if there are only insertions) *[*************** [GNU diff can put stuff here]] * --- start[,end] ---- * to lines... (omitted if there are only deletions) *[*** start[,end] **** * ...] * * Both from and to lines may end with: * \ No newline at end of file */ if (getline (line, linelen, f) == -1) return EOF; ++*linenum; if (strncmp (*line, "***************", 15)) return 1; if (getline (line, linelen, f) == -1) return EOF; ++*linenum; if (output_matching == output_file) match_tmpf = xtmpfile (); next_hunk: unchanged = 0; changed[0] = changed[1] = 0; // for munge calculation for (i = 0; i < 2; i++) { int first = 1; if (i == 0) first_hunk = !header_displayed; if (!i && !strncmp (*line, "***************", 15)) { /* Some diffs seem to have this for every * set of changes. SuSV2 says not to, * but the GNU diff info page disagrees. */ i--; if (getline (line, linelen, f) == -1) { ret = EOF; goto out; } ++*linenum; continue; } if (strncmp (*line, i ? "--- " : "*** ", 4)) { ret = 1; goto out; } if (!i) { hunknum++; hunk_linenum = *linenum; if (output_matching != output_file) grepmatch = 0; if (output_matching == output_hunk) { if (match_tmpf) fclose (match_tmpf); match_tmpf = xtmpfile (); } } do_line_counts: n = *line + 4; line_start = strtoul (n, &end, 10); if (n == end) { ret = 1; goto out; } if (*end == ',') { n = end + 1; line_end = strtoul (n, &end, 10); if (n == end) { ret = 1; goto out; } if (line_start > line_end) { ret = 1; goto out; } line_count = line_end - line_start + 1; } else { line_end = line_start; line_count = line_start ? 1 : 0; } n = strchr (n, '*'); if (n) n += 4; if (!i) { if (match) hunk_match = hunk_matches (line_start, line_count, hunknum); else hunk_match = 0; if (hunk_match && numbering && verbose && mode != mode_grep) { if (print_patchnames) printf ("%s-", patchname); printf ("\t%lu\tHunk #%lu\n", hunk_linenum, hunknum); } } if (hunk_match && (mode == mode_filter || output_matching != output_none)) { FILE *output_to= stdout; if (mode == mode_grep && !grepmatch) output_to = match_tmpf; // Display the line counts. if (!header_displayed && mode == mode_filter) { unsigned int i; for (i = 0; i < num_headers - 2; i++) output_header_line (header[i]); if (number_lines != After) output_header_line (header[num_headers - 2]); if (number_lines != Before) output_header_line (header[num_headers - 1]); header_displayed = 1; } if (number_lines == None) switch (i) { case 0: fputs ("***************\n", output_to); fprintf (output_to, "*** %lu", line_start); if (line_end != line_start) fprintf (output_to, ",%lu", line_end); fputs (" ****", output_to); if (annotating) fprintf (output_to, " Hunk #%lu, %s\n", hunknum, bestname); else if (n) fputs (n, output_to); else fputc ('\n', output_to); break; case 1: fprintf (output_to, "--- %lu", line_start + munge_offset); if (line_end != line_start) fprintf (output_to, ",%lu", line_end + munge_offset); fputs (" ----\n", output_to); break; } switch (number_lines) { case None: break; case Before: if (i != 0) break; // Note the initial line number. track_linenum = line_start; if (!first_hunk || (output_matching == output_file && hunknum > 1)) fputs ("...\n", output_to); break; case After: if (i != 1) break; track_linenum = line_start + munge_offset; if (!first_hunk || (output_matching == output_file && hunknum > 1)) fputs ("...\n", output_to); break; } } got = getline (line, linelen, f); if (got == -1) { ret = EOF; goto out; } ++*linenum; if (i && line_count == unchanged) break; while ((line_count == 0 && **line == '\\') || line_count--) { if (hunk_match && mode == mode_grep && (only_matching == only_match_all || (**line != ' ' && i == 0 && only_matching & only_match_rem) || (**line != ' ' && i == 1 && only_matching & only_match_add) ) && !regexecs (regex, num_regex, *line + 2, 0, NULL, 0)) { if (output_matching == output_none) { if (!displayed_filename) { displayed_filename = 1; display_filename(start_linenum, status, bestname, patchname); } if (numbering && verbose && hunknum > last_hunkmatch) { last_hunkmatch = hunknum; if (print_patchnames) printf ("%s-", patchname); printf ("\t%lu\tHunk #%lu\n", hunk_linenum, hunknum); } } else { if (!header_displayed) { unsigned int i; for (i = 0; i < num_headers - 2; i++) output_header_line (header[i]); if (number_lines != After) output_header_line (header[num_headers - 2]); if (number_lines != Before) output_header_line (header[num_headers - 1]); header_displayed = 1; } if (match_tmpf) { rewind (match_tmpf); while (!feof (match_tmpf)) { int ch; ch = fgetc(match_tmpf); if (ch == EOF) break; putchar (ch); } fclose (match_tmpf); match_tmpf = NULL; } grepmatch = 1; } } if (!i && first) { first = 0; if (!strncmp (*line, "--- ", 4)) { /* From lines were * omitted. */ i++; goto do_line_counts; } } if (**line == ' ') unchanged++; if (empty_files_as_absent) switch (**line) { case ' ': case '!': new_is_empty = orig_is_empty = 0; break; case '+': new_is_empty = 0; break; case '-': orig_is_empty = 0; break; } if (hunk_match && (mode == mode_filter || output_matching != output_none)) { FILE *output_to = stdout; if (mode == mode_grep && !grepmatch) output_to = match_tmpf; if (number_lines == None) fwrite (*line, (size_t) got, 1, output_to); else if ((number_lines == Before && !i) || (number_lines == After && i)) { fprintf (output_to, "%lu\t:", track_linenum++); fwrite (2 + *line, (size_t) got - 2, 1, output_to); } } if ((mode == mode_filter && !hunk_match) || output_matching == output_hunk) switch (**line) { case '!': case '\\': changed[i]++; break; case '+': changed[1]++; break; case '-': changed[0]++; break; } got = getline (line, linelen, f); if (got == -1) { ret = EOF; goto out; } ++*linenum; } } if (output_matching != output_hunk || !grepmatch) munge_offset += changed[0] - changed[1]; goto next_hunk; out: if (match_tmpf) fclose (match_tmpf); if (empty_files_as_absent) { if (orig_file_exists != NULL && orig_is_empty) *orig_file_exists = 0; if (new_file_exists != NULL && new_is_empty) *new_file_exists = 0; } return ret; } #define MAX_HEADERS 6 static int filterdiff (FILE *f, const char *patchname) { static unsigned long linenum = 1; char *names[2]; char *header[MAX_HEADERS + 2] = { NULL, NULL }; unsigned int num_headers = 0; char *line = NULL; size_t linelen = 0; char *p; const char *p_stripped; int match; int i; if (getline (&line, &linelen, f) == -1) return 0; for (;;) { char status = '!'; unsigned long start_linenum; int orig_file_exists, new_file_exists; int is_context = -1; int result; int (*do_diff) (FILE *, char **, unsigned int, int, char **, size_t *, unsigned long *, unsigned long, char, const char *, const char *, int *, int *); orig_file_exists = 0; // shut gcc up // Search for start of patch ("diff ", or "--- " for // unified diff, "*** " for context). for (;;) { if (!strncmp (line, "diff ", 5)) break; if (!strncmp (line, "--- ", 4)) { is_context = 0; break; } if (!strncmp (line, "*** ", 4)) { is_context = 1; break; } /* Show non-diff lines if excluding, or if * in verbose mode, and if --clean isn't specified. */ if (mode == mode_filter && (pat_exclude || verbose) && !clean_comments) fputs (line, stdout); if (getline (&line, &linelen, f) == -1) goto eof; linenum++; } start_linenum = linenum; header[0] = xstrdup (line); num_headers = 1; if (is_context == -1) { int valid_extended = 1; for (;;) { if (getline (&line, &linelen, f) == -1) goto eof; linenum++; if (!strncmp (line, "diff ", 5)) { header[num_headers++] = xstrdup (line); break; } if (!strncmp (line, "--- ", 4)) is_context = 0; else if (!strncmp (line, "*** ", 4)) is_context = 1; else if (strncmp (line, "old mode ", 9) && strncmp (line, "new mode ", 9) && strncmp (line, "deleted file mode ", 18) && strncmp (line, "new file mode ", 15) && strncmp (line, "copy from ", 10) && strncmp (line, "copy to ", 8) && strncmp (line, "rename from ", 12) && strncmp (line, "rename to ", 10) && strncmp (line, "similarity index ", 17) && strncmp (line, "dissimilarity index ", 20) && strncmp (line, "index ", 6)) valid_extended = 0; if (!valid_extended) break; /* Drop excess header lines */ if (num_headers > MAX_HEADERS ) free (header[--num_headers]); header[num_headers++] = xstrdup (line); if (is_context != -1) break; } if (!valid_extended) goto flush_continue; } if (is_context == -1) { /* We don't yet do anything with diffs with * zero hunks. */ unsigned int i = 0; flush_continue: if (mode == mode_filter && (pat_exclude || verbose) && !clean_comments) { for (i = 0; i < num_headers; i++) fputs (header[i], stdout); } for (i = 0; i < num_headers; i++) { free (header[i]); header[i] = NULL; } num_headers = 0; continue; } names[0] = filename_from_header (line + 4); if (mode != mode_filter && show_status) orig_file_exists = file_exists (names[0], line + 4 + strlen (names[0])); if (getline (&line, &linelen, f) == -1) { /* Show non-diff lines if excluding, or if * in verbose mode, and if --clean isn't specified. */ if (mode == mode_filter && (pat_exclude || verbose) && !clean_comments) fputs (header[0], stdout); free (names[0]); goto eof; } linenum++; if (strncmp (line, is_context ? "--- " : "+++ ", 4)) { /* Show non-diff lines if excluding, or if * in verbose mode, and if --clean isn't specified. */ free (names[0]); goto flush_continue; } filecount++; header[num_headers++] = xstrdup (line); names[1] = filename_from_header (line + 4); if (mode != mode_filter && show_status) new_file_exists = file_exists (names[1], line + 4 + strlen (names[1])); // Decide whether this matches this pattern. p = best_name (2, names); p_stripped = stripped (p, ignore_components); match = !patlist_match(pat_exclude, p_stripped); if (match && pat_include != NULL) match = patlist_match(pat_include, p_stripped); // print if it matches. if (match && !show_status && mode == mode_list) display_filename (start_linenum, status, p, patchname); if (is_context) do_diff = do_context; else do_diff = do_unified; result = do_diff (f, header, num_headers, match, &line, &linelen, &linenum, start_linenum, status, p, patchname, &orig_file_exists, &new_file_exists); // print if it matches. if (match && show_status && mode == mode_list) { if (!orig_file_exists) status = '+'; else if (!new_file_exists) status = '-'; display_filename (start_linenum, status, p, patchname); } switch (result) { case EOF: free (names[0]); free (names[1]); goto eof; case 1: goto next_diff; } next_diff: for (i = 0; i < 2; i++) free (names[i]); for (i = 0; i < num_headers; i++) { free (header[i]); header[i] = NULL; } num_headers = 0; } eof: for (i = 0; i < num_headers; i++) if (header[i]) free (header[i]); if (line) free (line); return 0; } const char * syntax_str = "Options:\n" " -x PAT, --exclude=PAT\n" " exclude files matching PAT\n" " -X FILE, --exclude-from-file=FILE\n" " exclude files that match any pattern in FILE\n" " -i PAT, --include=PAT\n" " include only files matching PAT\n" " -I FILE, --include-from-file=FILE\n" " include only files that match any pattern in FILE\n" " -# H, --hunks=H\n" " include only hunks in range H, if range begins with x show all excluding range H\n" " --lines=L include only hunks with (original) lines in range L, if range begins with x show all excluding range L\n" " -F F, --files=F\n" " include only files in range F, if range begins with x show all excluding range F\n" " --annotate (filterdiff, patchview, grepdiff)\n" " annotate each hunk with the filename and hunk number (filterdiff, patchview, grepdiff)\n" " --as-numbered-lines=before|after (filterdiff, patchview, grepdiff)\n" " display lines as they would look before, or after, the (filterdiff, patchview, grepdiff)\n" " patch is applied (filterdiff, patchview, grepdiff)\n" " --format=context|unified (filterdiff, patchview, grepdiff)\n" " set output format (filterdiff, patchview, grepdiff)\n" " --output-matching=hunk|file (grepdiff)\n" " show matching hunks or file-level diffs (grepdiff)\n" " --only-match=rem|removals|add|additions|mod|modifications|all (grepdiff)\n" " regex will only match removals, additions, modifications or (grepdiff)\n" " the whole hunk (grepdiff)\n" " --remove-timestamps (filterdiff, patchview, grepdiff)\n" " don't show timestamps from output (filterdiff, patchview, grepdiff)\n" " --clean (filterdiff)\n" " remove all comments (non-diff lines) from output (filterdiff)\n" " -z, --decompress\n" " decompress .gz and .bz2 files\n" " -n, --line-number (lsdiff, grepdiff)\n" " show line numbers (lsdiff, grepdiff)\n" " -N, --number-files (lsdiff, grepdiff)\n" " show file numbers, for use with filterdiff's --files option (lsdiff, grepdiff)\n" " -H, --with-filename (lsdiff, grepdiff)\n" " show patch file names (lsdiff, grepdiff)\n" " -h, --no-filename (lsdiff, grepdiff)\n" " suppress patch file names (lsdiff, grepdiff)\n" " -p N, --strip-match=N\n" " initial pathname components to ignore\n" " --strip=N initial pathname components to strip\n" " --addprefix=PREFIX\n" " prefix pathnames with PREFIX\n" " --addoldprefix=PREFIX\n" " prefix pathnames in old files with PREFIX\n" " --addnewprefix=PREFIX\n" " prefix pathnames in new files with PREFIX\n" " -s, --status (lsdiff)\n" " show file additions and removals (lsdiff)\n" " -v, --verbose\n" " verbose output -- use more than once for extra verbosity\n" " -E, --extended-regexp (grepdiff)\n" " use extended regexps, like egrep (grepdiff)\n" " -E, --empty-files-as-absent (lsdiff)\n" " treat empty files as absent (lsdiff)\n" " -f FILE, --file=FILE (grepdiff)\n" " read regular expressions from FILE (grepdiff)\n" " --filter run as 'filterdiff' (grepdiff, patchview, lsdiff)\n" " --list run as 'lsdiff' (filterdiff, patchview, grepdiff)\n" " --grep run as 'grepdiff' (filterdiff, patchview, lsdiff)\n" ; NORETURN static void syntax (int err) { char *s = xstrdup (syntax_str); const char *usage = "usage: %s [OPTION]... [files ...]\n"; char *p, *next; if (mode == mode_grep) usage = "usage: %s [OPTION]... REGEX [files ...]\n"; fprintf (err ? stderr : stdout, usage, progname); for (p = s; p && *p; p = next) { char *endp; next = strchr (p, '\n'); if (!next) break; endp = next; *next++ = '\0'; if (*--endp == ')') { char *begp = strrchr (p, '('); char *comma; if (!begp) break; *begp++ = '\0'; *endp = '\0'; do { comma = strchr (begp, ','); if (comma) *comma = '\0'; if (!strcmp (progname, begp)) { puts (p); break; } if (comma) begp = (comma + 1 + strspn (comma + 1, " ")); } while (comma); } else puts (p); } exit (err); } static void parse_range (struct range **r, const char *rstr) { unsigned long n; char *end; if (*rstr == '-') n = -1UL; else { n = strtoul (rstr, &end, 0); if (rstr == end) { if (*end) error (EXIT_FAILURE, 0, "not understood: '%s'", end); else error (EXIT_FAILURE, 0, "missing number in range list"); *r = NULL; return; } rstr = end; } *r = xmalloc (sizeof **r); (*r)->start = (*r)->end = n; (*r)->next = NULL; if (*rstr == '-') { rstr++; n = strtoul (rstr, &end, 0); if (rstr == end) n = -1UL; (*r)->end = n; rstr = end; if ((*r)->start != -1UL && (*r)->start > (*r)->end) error (EXIT_FAILURE, 0, "invalid range: %lu-%lu", (*r)->start, (*r)->end); } if (*rstr == ',') parse_range (&(*r)->next, rstr + 1); else if (*rstr != '\0') error (EXIT_FAILURE, 0, "not understood: '%s'", rstr); } static void set_list (void) { /* This is lsdiff. */ set_progname ("lsdiff"); mode = mode_list; } static void set_filter (void) { /* This is filterdiff. */ set_progname ("filterdiff"); mode = mode_filter; } static void set_view (void) { /* This is patchview. */ set_progname ("patchview"); mode = mode_filter; } static void set_grep (void) { /* This is grepdiff. */ set_progname ("grepdiff"); mode = mode_grep; } static void determine_mode_from_name (const char *argv0) { /* This is filterdiff, unless it is named 'lsdiff', 'grepdiff' or 'patchview'. */ const char *p = strrchr (argv0, '/'); if (!p++) p = argv0; if (strstr (p, "lsdiff")) set_list (); else if (strstr (p, "grepdiff")) set_grep (); else if (strstr (p, "patchview")) { set_view (); } else set_filter (); } static FILE *convert_format (FILE *f, char format) { switch (format) { default: break; case 'c': f = convert_to_context (f, "rb", 0); break; case 'u': f = convert_to_unified (f, "rb", 0); break; } return f; } static int read_regex_file (const char *file) { FILE *f = fopen (file, "r"); char *line = NULL; size_t linelen = 0; ssize_t got; int err; if (!f) error (EXIT_FAILURE, errno, "cannot open %s", file); while ((got = getline (&line, &linelen, f)) > 0) { if (line[--got] == '\n') line[got] = '\0'; regex = xrealloc (regex, ++num_regex * sizeof (regex[0])); err = regcomp (®ex[num_regex - 1], line, REG_NOSUB | egrepping); if (err) { char errstr[300]; regerror (err, ®ex[num_regex - 1], errstr, sizeof (errstr)); error (EXIT_FAILURE, 0, "%s", errstr); exit (1); } } free (line); return fclose (f); } int main (int argc, char *argv[]) { int i; FILE *f = stdin; char format = '\0'; int regex_file_specified = 0; int have_switches = 0; setlocale (LC_TIME, "C"); determine_mode_from_name (argv[0]); while (1) { static struct option long_options[] = { {"help", 0, 0, 1000 + 'H'}, {"version", 0, 0, 1000 + 'V'}, {"verbose", 0, 0, 'v'}, {"list", 0, 0, 'l'}, {"filter", 0, 0, 1000 + 'f'}, {"grep", 0, 0, 'g'}, {"strip", 1, 0, 1000 + 'S'}, {"addprefix", 1, 0, 1000 + 'A'}, {"addoldprefix", 1, 0, 1000 + 'O'}, {"addnewprefix", 1, 0, 1000 + 'N'}, {"hunks", 1, 0, '#'}, {"lines", 1, 0, 1000 + ':'}, {"files", 1, 0, 'F'}, {"as-numbered-lines", 1, 0, 1000 + 'L'}, {"annotate", 0, 0, 1000 + 'a'}, {"format", 1, 0, 1000 + 'F'}, {"output-matching", 1, 0, 1000 + 'o'}, {"only-match", 1, 0, 1000 + 'm'}, {"remove-timestamps", 0, 0, 1000 + 'r'}, {"with-filename", 0, 0, 'H'}, {"no-filename", 0, 0, 'h'}, {"empty-files-as-absent", 0, 0, 'E'}, {"number-files", 0, 0, 'N'}, {"clean", 0, 0, 1000 + 'c'}, {"strip-match", 1, 0, 'p'}, {"include", 1, 0, 'i'}, {"exclude", 1, 0, 'x'}, {"include-from-file", 1, 0, 'I'}, {"exclude-from-file", 1, 0, 'X'}, {"decompress", 0, 0, 'z'}, {"line-number", 0, 0, 'n'}, {"strip-match", 1, 0, 'p'}, {"status", 0, 0, 's'}, {"extended-regexp", 0, 0, 'E'}, {"empty-files-as-removed", 0, 0, 'E'}, {"file", 1, 0, 'f'}, {0, 0, 0, 0} }; char *end; int c = getopt_long (argc, argv, "vp:i:I:x:X:zns#:F:Ef:HhN", long_options, NULL); if (c == -1) break; have_switches = 1; switch (c) { case 'g': set_grep (); break; case 1000 + 'f': set_filter (); break; case 'l': set_list (); break; case 'E': if (mode == mode_grep) egrepping = REG_EXTENDED; else if (mode == mode_list) empty_files_as_absent = 1; else syntax (1); break; case 'f': if (mode == mode_grep) { regex_file_specified = 1; read_regex_file (optarg); } else syntax (1); break; case 1000 + 'V': printf("%s - patchutils version %s\n", progname, VERSION); exit(0); case 1000 + 'H': syntax (0); break; case 1000 + 'S': strip_components = strtoul (optarg, &end, 0); if (optarg == end) syntax (1); break; case 1000 + 'A': prefix_to_add = optarg; break; case 1000 + 'O': old_prefix_to_add = optarg; break; case 1000 + 'N': new_prefix_to_add = optarg; break; case 'p': ignore_components = strtoul (optarg, &end, 0); if (optarg == end) syntax (1); break; case 'x': patlist_add (&pat_exclude, optarg); break; case 'X': patlist_add_file (&pat_exclude, optarg); break; case 'i': patlist_add (&pat_include, optarg); break; case 'I': patlist_add_file (&pat_include, optarg); break; case 'z': unzip = 1; break; case 'n': numbering = 1; break; case 'N': number_files = 1; break; case 's': show_status = 1; break; case 'v': verbose++; if (numbering && verbose > 1) number_files = 1; break; case '#': if (hunks) syntax (1); if (*optarg == 'x') { hunks_exclude = 1; optarg = optarg + 1; } parse_range (&hunks, optarg); break; case 'H': if (mode == mode_list || mode == mode_grep) print_patchnames = 1; else syntax (1); break; case 'h': if (mode == mode_list || mode == mode_grep) print_patchnames = 0; else syntax (1); break; case 1000 + ':': if (lines) syntax (1); if (*optarg == 'x') { lines_exclude = 1; optarg = optarg + 1; } parse_range (&lines, optarg); break; case 'F': if (files) syntax (1); if (*optarg == 'x') { files_exclude = 1; optarg = optarg + 1; } parse_range (&files, optarg); break; case 1000 + 'L': if (!strcmp (optarg, "before")) number_lines = Before; else if (!strcmp (optarg, "after")) number_lines = After; else syntax (1); break; case 1000 + 'a': if (mode == mode_list) syntax (1); annotating = 1; break; case 1000 + 'F': if (!strcmp (optarg, "context") && !format) format = 'c'; else if (!strcmp (optarg, "unified") && !format) format = 'u'; else syntax (1); break; case 1000 + 'o': if (!strncmp (optarg, "hunk", 4)) output_matching = output_hunk; else if (!strncmp (optarg, "file", 4)) output_matching = output_file; else syntax (1); break; case 1000 + 'm': if (!strncmp (optarg, "all", 3)) only_matching = only_match_all; else if (!strncmp (optarg, "rem", 3) || !strncmp (optarg, "removals", 8)) only_matching = only_match_rem; else if (!strncmp (optarg, "add", 3) || !strncmp (optarg, "additions", 9)) only_matching = only_match_add; else if (!strncmp (optarg, "mod", 3) || !strncmp (optarg, "modifications", 13)) only_matching = only_match_mod; else syntax (1); break; case 1000 + 'r': removing_timestamp = 1; break; case 1000 + 'c': clean_comments = 1; break; default: syntax(1); } } if (have_switches == 0 && strcmp (progname, "patchview") == 0) { mode = mode_list; number_files = 1; } /* Preserve the old semantics of -p. */ if (mode != mode_filter && ignore_components && !strip_components && !pat_include && !pat_exclude) { fprintf (stderr, "-p given without -i or -x; guessing that you " "meant --strip instead.\n"); strip_components = ignore_components; ignore_components = 0; } if (mode != mode_grep && output_matching != output_none) error (EXIT_FAILURE, 0, "--output-matching only applies to " "grep mode"); if (mode != mode_grep && only_matching != only_match_all) error (EXIT_FAILURE, 0, "--only-match only applies to " "grep mode"); if (numbering && !(mode == mode_list || (mode == mode_grep && output_matching == output_none))) error (EXIT_FAILURE, 0, "-n only applies to list mode"); if (mode != mode_filter && output_matching == output_none && number_lines != None) error (EXIT_FAILURE, 0, "--as-numbered-lines is " "inappropriate in this context"); if (mode == mode_filter && verbose && clean_comments) error (EXIT_FAILURE, 0, "can't use --verbose and " "--clean options simultaneously"); if (mode == mode_grep && !regex_file_specified) { int err; if (optind == argc) syntax (1); regex = xrealloc (regex, ++num_regex * sizeof (regex[0])); err = regcomp (®ex[num_regex - 1], argv[optind++], REG_NOSUB | egrepping); if (err) { char errstr[300]; regerror (err, ®ex[num_regex - 1], errstr, sizeof (errstr)); error (EXIT_FAILURE, 0, "%s", errstr); exit (1); } } if (number_lines != None || output_matching != output_none) { if (print_patchnames == 1) error (EXIT_FAILURE, 0, "-H is inappropriate in this context"); } else if (print_patchnames == -1) { if ((mode == mode_list || mode == mode_grep) && optind + 1 < argc) print_patchnames = 1; else print_patchnames = 0; } if (optind == argc) { f = convert_format (stdin, format); filterdiff (f, "(standard input)"); fclose (f); } else { for (i = optind; i < argc; i++) { if (unzip) { f = xopen_unzip (argv[i], "rb"); } else { f = xopen(argv[i], "rbm"); } f = convert_format (f, format); filterdiff (f, argv[i]); fclose (f); } } return 0; } patchutils-0.4.2/src/getopt.c000066400000000000000000000727071370426545100161560ustar00rootroot00000000000000/* Getopt for GNU. NOTE: getopt is now part of the C library, so if you don't know what "Keep this file name-space clean" means, talk to drepper@gnu.org before changing it! Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* This tells Alpha OSF/1 not to define a getopt prototype in . Ditto for AIX 3.2 and . */ #ifndef _NO_PROTO # define _NO_PROTO #endif #ifdef HAVE_CONFIG_H # include #endif #if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ # ifndef const # define const # endif #endif #include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 # include # if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION # define ELIDE_CODE # endif #endif #ifndef ELIDE_CODE /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ /* Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting prototypes for getopt. */ # include # include #endif /* GNU C library. */ #ifdef VMS # include # if HAVE_STRING_H - 0 # include # endif #endif #ifndef _ /* This is for other GNU distributions with internationalized messages. */ # if defined HAVE_LIBINTL_H || defined _LIBC # include # ifndef _ # define _(msgid) gettext (msgid) # endif # else # define _(msgid) (msgid) # endif #endif /* This version of `getopt' appears to the caller like standard Unix `getopt' but it behaves differently for the user, since it allows the user to intersperse the options with the other arguments. As `getopt' works, it permutes the elements of ARGV so that, when it is done, all the options precede everything else. Thus all application programs are extended to handle flexible argument order. Setting the environment variable POSIXLY_CORRECT disables permutation. Then the behavior is completely standard. GNU application programs can use a third alternative mode in which they can distinguish the relative order of options and other arguments. */ #include "getopt.h" /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ char *optarg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller and for communication between successive calls to `getopt'. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the non-option elements that the caller should itself scan. Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ /* 1003.2 says this must be 1 before any call. */ int optind = 1; /* Formerly, initialization of getopt depended on optind==0, which causes problems with re-calling getopt as programs generally don't know that. */ int __getopt_initialized; /* The next char to be scanned in the option-element in which the last option character we returned was found. This allows us to pick up the scan where we left off. If this is zero, or a null string, it means resume the scan by advancing to the next ARGV-element. */ static char *nextchar; /* Callers store zero here to inhibit the error message for unrecognized options. */ int opterr = 1; /* Set to an option character which was unrecognized. This must be initialized on some systems to avoid linking in the system's own getopt implementation. */ int optopt = '?'; /* Describe how to deal with options that follow non-option ARGV-elements. If the caller did not specify anything, the default is REQUIRE_ORDER if the environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise. REQUIRE_ORDER means don't recognize them as options; stop option processing when the first non-option is seen. This is what Unix does. This mode of operation is selected by either setting the environment variable POSIXLY_CORRECT, or using `+' as the first character of the list of option characters. PERMUTE is the default. We permute the contents of ARGV as we scan, so that eventually all the non-options are at the end. This allows options to be given in any order, even with programs that were not written to expect this. RETURN_IN_ORDER is an option available to programs that were written to expect options and other ARGV-elements in any order and that care about the ordering of the two. We describe each non-option ARGV-element as if it were the argument of an option with character code 1. Using `-' as the first character of the list of option characters selects this mode of operation. The special argument `--' forces an end of option-scanning regardless of the value of `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause `getopt' to return -1 with `optind' != ARGC. */ static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; /* Value of POSIXLY_CORRECT environment variable. */ static char *posixly_correct; #ifdef __GNU_LIBRARY__ /* We want to avoid inclusion of string.h with non-GNU libraries because there are many ways it can cause trouble. On some systems, it contains special magic macros that don't work in GCC. */ # include # define my_index strchr #else # if HAVE_STRING_H # include # else # include # endif /* Avoid depending on library functions or files whose names are inconsistent. */ #ifndef getenv extern char *getenv (); #endif static char * my_index (str, chr) const char *str; int chr; { while (*str) { if (*str == chr) return (char *) str; str++; } return 0; } /* If using GCC, we can safely declare strlen this way. If not using GCC, it is ok not to declare it. */ #ifdef __GNUC__ /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. That was relevant to code that was here before. */ # if (!defined __STDC__ || !__STDC__) && !defined strlen /* gcc with -traditional declares the built-in strlen to return int, and has done so at least since version 2.4.5. -- rms. */ extern int strlen (const char *); # endif /* not __STDC__ */ #endif /* __GNUC__ */ #endif /* not __GNU_LIBRARY__ */ /* Handle permutation of arguments. */ /* Describe the part of ARGV that contains non-options that have been skipped. `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is the index after the last of them. */ static int first_nonopt; static int last_nonopt; #ifdef _LIBC /* Stored original parameters. XXX This is no good solution. We should rather copy the args so that we can compare them later. But we must not use malloc(3). */ extern int __libc_argc; extern char **__libc_argv; /* Bash 2.0 gives us an environment variable containing flags indicating ARGV elements that should not be considered arguments. */ # ifdef USE_NONOPTION_FLAGS /* Defined in getopt_init.c */ extern char *__getopt_nonoption_flags; static int nonoption_flags_max_len; static int nonoption_flags_len; # endif # ifdef USE_NONOPTION_FLAGS # define SWAP_FLAGS(ch1, ch2) \ if (nonoption_flags_len > 0) \ { \ char __tmp = __getopt_nonoption_flags[ch1]; \ __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ __getopt_nonoption_flags[ch2] = __tmp; \ } # else # define SWAP_FLAGS(ch1, ch2) # endif #else /* !_LIBC */ # define SWAP_FLAGS(ch1, ch2) #endif /* _LIBC */ /* Exchange two adjacent subsequences of ARGV. One subsequence is elements [first_nonopt,last_nonopt) which contains all the non-options that have been skipped so far. The other is elements [last_nonopt,optind), which contains all the options processed since those non-options were skipped. `first_nonopt' and `last_nonopt' are relocated so that they describe the new indices of the non-options in ARGV after they are moved. */ #if defined __STDC__ && __STDC__ static void exchange (char **); #endif static void exchange (argv) char **argv; { int bottom = first_nonopt; int middle = last_nonopt; int top = optind; char *tem; /* Exchange the shorter segment with the far end of the longer segment. That puts the shorter segment into the right place. It leaves the longer segment in the right place overall, but it consists of two parts that need to be swapped next. */ #if defined _LIBC && defined USE_NONOPTION_FLAGS /* First make sure the handling of the `__getopt_nonoption_flags' string can work normally. Our top argument must be in the range of the string. */ if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) { /* We must extend the array. The user plays games with us and presents new arguments. */ char *new_str = malloc (top + 1); if (new_str == NULL) nonoption_flags_len = nonoption_flags_max_len = 0; else { memset (__mempcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len), '\0', top + 1 - nonoption_flags_max_len); nonoption_flags_max_len = top + 1; __getopt_nonoption_flags = new_str; } } #endif while (top > middle && middle > bottom) { if (top - middle > middle - bottom) { /* Bottom segment is the short one. */ int len = middle - bottom; register int i; /* Swap it with the top part of the top segment. */ for (i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[top - (middle - bottom) + i]; argv[top - (middle - bottom) + i] = tem; SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); } /* Exclude the moved bottom segment from further swapping. */ top -= len; } else { /* Top segment is the short one. */ int len = top - middle; register int i; /* Swap it with the bottom part of the bottom segment. */ for (i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[middle + i]; argv[middle + i] = tem; SWAP_FLAGS (bottom + i, middle + i); } /* Exclude the moved top segment from further swapping. */ bottom += len; } } /* Update records for the slots the non-options now occupy. */ first_nonopt += (optind - last_nonopt); last_nonopt = optind; } /* Initialize the internal data when the first call is made. */ #if defined __STDC__ && __STDC__ static const char *_getopt_initialize (int, char *const *, const char *); #endif static const char * _getopt_initialize (argc, argv, optstring) int argc; char *const *argv; const char *optstring; { /* Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the sequence of previously skipped non-option ARGV-elements is empty. */ first_nonopt = last_nonopt = optind; nextchar = NULL; posixly_correct = getenv ("POSIXLY_CORRECT"); /* Determine how to handle the ordering of options and nonoptions. */ if (optstring[0] == '-') { ordering = RETURN_IN_ORDER; ++optstring; } else if (optstring[0] == '+') { ordering = REQUIRE_ORDER; ++optstring; } else if (posixly_correct != NULL) ordering = REQUIRE_ORDER; else ordering = PERMUTE; #if defined _LIBC && defined USE_NONOPTION_FLAGS if (posixly_correct == NULL && argc == __libc_argc && argv == __libc_argv) { if (nonoption_flags_max_len == 0) { if (__getopt_nonoption_flags == NULL || __getopt_nonoption_flags[0] == '\0') nonoption_flags_max_len = -1; else { const char *orig_str = __getopt_nonoption_flags; int len = nonoption_flags_max_len = strlen (orig_str); if (nonoption_flags_max_len < argc) nonoption_flags_max_len = argc; __getopt_nonoption_flags = (char *) malloc (nonoption_flags_max_len); if (__getopt_nonoption_flags == NULL) nonoption_flags_max_len = -1; else memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), '\0', nonoption_flags_max_len - len); } } nonoption_flags_len = nonoption_flags_max_len; } else nonoption_flags_len = 0; #endif return optstring; } /* Scan elements of ARGV (whose length is ARGC) for option characters given in OPTSTRING. If an element of ARGV starts with '-', and is not exactly "-" or "--", then it is an option element. The characters of this element (aside from the initial '-') are option characters. If `getopt' is called repeatedly, it returns successively each of the option characters from each of the option elements. If `getopt' finds another option character, it returns that character, updating `optind' and `nextchar' so that the next call to `getopt' can resume the scan with the following option character or ARGV-element. If there are no more option characters, `getopt' returns -1. Then `optind' is the index in ARGV of the first ARGV-element that is not an option. (The ARGV-elements have been permuted so that those that are not options now come last.) OPTSTRING is a string containing the legitimate option characters. If an option character is seen that is not listed in OPTSTRING, return '?' after printing an error message. If you set `opterr' to zero, the error message is suppressed but we still return '?'. If a char in OPTSTRING is followed by a colon, that means it wants an arg, so the following text in the same ARGV-element, or the text of the following ARGV-element, is returned in `optarg'. Two colons mean an option that wants an optional arg; if there is text in the current ARGV-element, it is returned in `optarg', otherwise `optarg' is set to zero. If OPTSTRING starts with `-' or `+', it requests different methods of handling the non-option ARGV-elements. See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. Long-named options begin with `--' instead of `-'. Their names may be abbreviated as long as the abbreviation is unique or is an exact match for some defined option. If they have an argument, it follows the option name in the same ARGV-element, separated from the option name by a `=', or else the in next ARGV-element. When `getopt' finds a long-named option, it returns 0 if that option's `flag' field is nonzero, the value of the option's `val' field if the `flag' field is zero. The elements of ARGV aren't really const, because we permute them. But we pretend they're const in the prototype to be compatible with other systems. LONGOPTS is a vector of `struct option' terminated by an element containing a name which is zero. LONGIND returns the index in LONGOPT of the long-named option found. It is only valid when a long-named option has been found by the most recent call. If LONG_ONLY is nonzero, '-' as well as '--' can introduce long-named options. */ int _getopt_internal (argc, argv, optstring, longopts, longind, long_only) int argc; char *const *argv; const char *optstring; const struct option *longopts; int *longind; int long_only; { int print_errors = opterr; if (optstring[0] == ':') print_errors = 0; if (argc < 1) return -1; optarg = NULL; if (optind == 0 || !__getopt_initialized) { if (optind == 0) optind = 1; /* Don't scan ARGV[0], the program name. */ optstring = _getopt_initialize (argc, argv, optstring); __getopt_initialized = 1; } /* Test whether ARGV[optind] points to a non-option argument. Either it does not have option syntax, or there is an environment flag from the shell indicating it is not an option. The later information is only used when the used in the GNU libc. */ #if defined _LIBC && defined USE_NONOPTION_FLAGS # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ || (optind < nonoption_flags_len \ && __getopt_nonoption_flags[optind] == '1')) #else # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') #endif if (nextchar == NULL || *nextchar == '\0') { /* Advance to the next ARGV-element. */ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been moved back by the user (who may also have changed the arguments). */ if (last_nonopt > optind) last_nonopt = optind; if (first_nonopt > optind) first_nonopt = optind; if (ordering == PERMUTE) { /* If we have just processed some options following some non-options, exchange them so that the options come first. */ if (first_nonopt != last_nonopt && last_nonopt != optind) exchange ((char **) argv); else if (last_nonopt != optind) first_nonopt = optind; /* Skip any additional non-options and extend the range of non-options previously skipped. */ while (optind < argc && NONOPTION_P) optind++; last_nonopt = optind; } /* The special ARGV-element `--' means premature end of options. Skip it like a null option, then exchange with previous non-options as if it were an option, then skip everything else like a non-option. */ if (optind != argc && !strcmp (argv[optind], "--")) { optind++; if (first_nonopt != last_nonopt && last_nonopt != optind) exchange ((char **) argv); else if (first_nonopt == last_nonopt) first_nonopt = optind; last_nonopt = argc; optind = argc; } /* If we have done all the ARGV-elements, stop the scan and back over any non-options that we skipped and permuted. */ if (optind == argc) { /* Set the next-arg-index to point at the non-options that we previously skipped, so the caller will digest them. */ if (first_nonopt != last_nonopt) optind = first_nonopt; return -1; } /* If we have come to a non-option and did not permute it, either stop the scan or describe it to the caller and pass it by. */ if (NONOPTION_P) { if (ordering == REQUIRE_ORDER) return -1; optarg = argv[optind++]; return 1; } /* We have found another option-ARGV-element. Skip the initial punctuation. */ nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-')); } /* Decode the current option-ARGV-element. */ /* Check whether the ARGV-element is a long option. If long_only and the ARGV-element has the form "-f", where f is a valid short option, don't consider it an abbreviated form of a long option that starts with f. Otherwise there would be no way to give the -f short option. On the other hand, if there's a long option "fubar" and the ARGV-element is "-fu", do consider that an abbreviation of the long option, just like "--fu", and not "-f" with arg "u". This distinction seems to be the most useful approach. */ if (longopts != NULL && (argv[optind][1] == '-' || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) { char *nameend; const struct option *p; const struct option *pfound = NULL; int exact = 0; int ambig = 0; int indfound = -1; int option_index; for (nameend = nextchar; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, nextchar, nameend - nextchar)) { if ((unsigned int) (nameend - nextchar) == (unsigned int) strlen (p->name)) { /* Exact match found. */ pfound = p; indfound = option_index; exact = 1; break; } else if (pfound == NULL) { /* First nonexact match found. */ pfound = p; indfound = option_index; } else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val) /* Second or later nonexact match found. */ ambig = 1; } if (ambig && !exact) { if (print_errors) fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen (nextchar); optind++; optopt = 0; return '?'; } if (pfound != NULL) { option_index = indfound; optind++; if (*nameend) { /* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */ if (pfound->has_arg) optarg = nameend + 1; else { if (print_errors) { if (argv[optind - 1][1] == '-') /* --option */ fprintf (stderr, _("%s: option `--%s' doesn't allow an argument\n"), argv[0], pfound->name); else /* +option or -option */ fprintf (stderr, _("%s: option `%c%s' doesn't allow an argument\n"), argv[0], argv[optind - 1][0], pfound->name); } nextchar += strlen (nextchar); optopt = pfound->val; return '?'; } } else if (pfound->has_arg == 1) { if (optind < argc) optarg = argv[optind++]; else { if (print_errors) fprintf (stderr, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); nextchar += strlen (nextchar); optopt = pfound->val; return optstring[0] == ':' ? ':' : '?'; } } nextchar += strlen (nextchar); if (longind != NULL) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; return 0; } return pfound->val; } /* Can't find it as a long option. If this is not getopt_long_only, or the option starts with '--' or is not a valid short option, then it's an error. Otherwise interpret it as a short option. */ if (!long_only || argv[optind][1] == '-' || my_index (optstring, *nextchar) == NULL) { if (print_errors) { if (argv[optind][1] == '-') /* --option */ fprintf (stderr, _("%s: unrecognized option `--%s'\n"), argv[0], nextchar); else /* +option or -option */ fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0], argv[optind][0], nextchar); } nextchar = (char *) ""; optind++; optopt = 0; return '?'; } } /* Look at and handle the next short option-character. */ { char c = *nextchar++; char *temp = my_index (optstring, c); /* Increment `optind' when we start to process its last character. */ if (*nextchar == '\0') ++optind; if (temp == NULL || c == ':') { if (print_errors) { if (posixly_correct) /* 1003.2 specifies the format of this message. */ fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); else fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); } optopt = c; return '?'; } /* Convenience. Treat POSIX -W foo same as long option --foo */ if (temp[0] == 'W' && temp[1] == ';') { char *nameend; const struct option *p; const struct option *pfound = NULL; int exact = 0; int ambig = 0; int indfound = 0; int option_index; /* This is an option that requires an argument. */ if (*nextchar != '\0') { optarg = nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ optind++; } else if (optind == argc) { if (print_errors) { /* 1003.2 specifies the format of this message. */ fprintf (stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); } optopt = c; if (optstring[0] == ':') c = ':'; else c = '?'; return c; } else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ optarg = argv[optind++]; /* optarg is now the argument, see if it's in the table of longopts. */ for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, nextchar, nameend - nextchar)) { if ((unsigned int) (nameend - nextchar) == strlen (p->name)) { /* Exact match found. */ pfound = p; indfound = option_index; exact = 1; break; } else if (pfound == NULL) { /* First nonexact match found. */ pfound = p; indfound = option_index; } else /* Second or later nonexact match found. */ ambig = 1; } if (ambig && !exact) { if (print_errors) fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen (nextchar); optind++; return '?'; } if (pfound != NULL) { option_index = indfound; if (*nameend) { /* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */ if (pfound->has_arg) optarg = nameend + 1; else { if (print_errors) fprintf (stderr, _("\ %s: option `-W %s' doesn't allow an argument\n"), argv[0], pfound->name); nextchar += strlen (nextchar); return '?'; } } else if (pfound->has_arg == 1) { if (optind < argc) optarg = argv[optind++]; else { if (print_errors) fprintf (stderr, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); nextchar += strlen (nextchar); return optstring[0] == ':' ? ':' : '?'; } } nextchar += strlen (nextchar); if (longind != NULL) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; return 0; } return pfound->val; } nextchar = NULL; return 'W'; /* Let the application handle it. */ } if (temp[1] == ':') { if (temp[2] == ':') { /* This is an option that accepts an argument optionally. */ if (*nextchar != '\0') { optarg = nextchar; optind++; } else optarg = NULL; nextchar = NULL; } else { /* This is an option that requires an argument. */ if (*nextchar != '\0') { optarg = nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ optind++; } else if (optind == argc) { if (print_errors) { /* 1003.2 specifies the format of this message. */ fprintf (stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); } optopt = c; if (optstring[0] == ':') c = ':'; else c = '?'; } else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ optarg = argv[optind++]; nextchar = NULL; } } return c; } } int getopt (argc, argv, optstring) int argc; char *const *argv; const char *optstring; { return _getopt_internal (argc, argv, optstring, (const struct option *) 0, (int *) 0, 0); } #endif /* Not ELIDE_CODE. */ #ifdef TEST /* Compile with -DTEST to make an executable for use in testing the above definition of `getopt'. */ int main (argc, argv) int argc; char **argv; { int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; c = getopt (argc, argv, "abc:d:0123456789"); if (c == -1) break; switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (digit_optind != 0 && digit_optind != this_option_optind) printf ("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf ("option %c\n", c); break; case 'a': printf ("option a\n"); break; case 'b': printf ("option b\n"); break; case 'c': printf ("option c with value `%s'\n", optarg); break; case '?': break; default: printf ("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) printf ("%s ", argv[optind++]); printf ("\n"); } exit (0); } #endif /* TEST */ patchutils-0.4.2/src/getopt.h000066400000000000000000000144631370426545100161560ustar00rootroot00000000000000/* Declarations for getopt. Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef _GETOPT_H #ifndef __need_getopt # define _GETOPT_H 1 #endif /* If __GNU_LIBRARY__ is not already defined, either we are being used standalone, or this is the first header included in the source file. If we are being used with glibc, we need to include , but that does not exist if we are standalone. So: if __GNU_LIBRARY__ is not defined, include , which will pull in for us if it's from glibc. (Why ctype.h? It's guaranteed to exist and it doesn't flood the namespace with stuff the way some other headers do.) */ #if !defined __GNU_LIBRARY__ # include #endif #ifdef __cplusplus extern "C" { #endif /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ extern char *optarg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller and for communication between successive calls to `getopt'. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the non-option elements that the caller should itself scan. Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ extern int optind; /* Callers store zero here to inhibit the error message `getopt' prints for unrecognized options. */ extern int opterr; /* Set to an option character which was unrecognized. */ extern int optopt; #ifndef __need_getopt /* Describe the long-named options requested by the application. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector of `struct option' terminated by an element containing a name which is zero. The field `has_arg' is: no_argument (or 0) if the option does not take an argument, required_argument (or 1) if the option requires an argument, optional_argument (or 2) if the option takes an optional argument. If the field `flag' is not NULL, it points to a variable that is set to the value given in the field `val' when the option is found, but left unchanged if the option is not found. To have a long-named option do something other than set an `int' to a compiled-in constant, such as set a value from `optarg', set the option's `flag' field to zero and its `val' field to a nonzero value (the equivalent single-letter option character, if there is one). For long options that have a zero `flag' field, `getopt' returns the contents of the `val' field. */ struct option { # if (defined __STDC__ && __STDC__) || defined __cplusplus const char *name; # else char *name; # endif /* has_arg can't be an enum because some compilers complain about type mismatches in all the code that assumes it is an int. */ int has_arg; int *flag; int val; }; /* Names for the values of the `has_arg' field of `struct option'. */ # define no_argument 0 # define required_argument 1 # define optional_argument 2 #endif /* need getopt */ /* Get definitions and prototypes for functions to process the arguments in ARGV (ARGC of them, minus the program name) for options given in OPTS. Return the option character from OPTS just read. Return -1 when there are no more options. For unrecognized options, or options missing arguments, `optopt' is set to the option letter, and '?' is returned. The OPTS string is a list of characters which are recognized option letters, optionally followed by colons, specifying that that letter takes an argument, to be placed in `optarg'. If a letter in OPTS is followed by two colons, its argument is optional. This behavior is specific to the GNU `getopt'. The argument `--' causes premature termination of argument scanning, explicitly telling `getopt' that there are no more options. If OPTS begins with `--', then non-option arguments are treated as arguments to the option '\0'. This behavior is specific to the GNU `getopt'. */ #if (defined __STDC__ && __STDC__) || defined __cplusplus # ifdef __GNU_LIBRARY__ /* Many other libraries have conflicting prototypes for getopt, with differences in the consts, in stdlib.h. To avoid compilation errors, only prototype getopt for the GNU C library. */ extern int getopt (int __argc, char *const *__argv, const char *__shortopts); # else /* not __GNU_LIBRARY__ */ extern int getopt (); # endif /* __GNU_LIBRARY__ */ # ifndef __need_getopt extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind); extern int getopt_long_only (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind); /* Internal only. Users should not call this directly. */ extern int _getopt_internal (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind, int __long_only); # endif #else /* not __STDC__ */ extern int getopt (); # ifndef __need_getopt extern int getopt_long (); extern int getopt_long_only (); extern int _getopt_internal (); # endif #endif /* __STDC__ */ #ifdef __cplusplus } #endif /* Make sure we later can get all the definitions and declarations. */ #undef __need_getopt #endif /* getopt.h */ patchutils-0.4.2/src/getopt1.c000066400000000000000000000106541370426545100162300ustar00rootroot00000000000000/* getopt_long and getopt_long_only entry points for GNU getopt. Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H #include #endif #include "getopt.h" #if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ #ifndef const #define const #endif #endif #include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 #include #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION #define ELIDE_CODE #endif #endif #ifndef ELIDE_CODE /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ #include #endif #ifndef NULL #define NULL 0 #endif int getopt_long (argc, argv, options, long_options, opt_index) int argc; char *const *argv; const char *options; const struct option *long_options; int *opt_index; { return _getopt_internal (argc, argv, options, long_options, opt_index, 0); } /* Like getopt_long, but '-' as well as '--' can indicate a long option. If an option that starts with '-' (not '--') doesn't match a long option, but does match a short option, it is parsed as a short option instead. */ int getopt_long_only (argc, argv, options, long_options, opt_index) int argc; char *const *argv; const char *options; const struct option *long_options; int *opt_index; { return _getopt_internal (argc, argv, options, long_options, opt_index, 1); } #endif /* Not ELIDE_CODE. */ #ifdef TEST #include int main (argc, argv) int argc; char **argv; { int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; int option_index = 0; static struct option long_options[] = { {"add", 1, 0, 0}, {"append", 0, 0, 0}, {"delete", 1, 0, 0}, {"verbose", 0, 0, 0}, {"create", 0, 0, 0}, {"file", 1, 0, 0}, {0, 0, 0, 0} }; c = getopt_long (argc, argv, "abc:d:0123456789", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (digit_optind != 0 && digit_optind != this_option_optind) printf ("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf ("option %c\n", c); break; case 'a': printf ("option a\n"); break; case 'b': printf ("option b\n"); break; case 'c': printf ("option c with value `%s'\n", optarg); break; case 'd': printf ("option d with value `%s'\n", optarg); break; case '?': break; default: printf ("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) printf ("%s ", argv[optind++]); printf ("\n"); } exit (0); } #endif /* TEST */ patchutils-0.4.2/src/interdiff.c000066400000000000000000001363761370426545100166310ustar00rootroot00000000000000/* * interdiff - create incremental patch between two against a common source * combinediff - create cumulative patch from two incremental patches * flipdiff - exchange the order of two incremental patches * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2009, 2011 Tim Waugh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef HAVE_ALLOCA_H # include #endif /* HAVE_ALLOCA_H */ #include #ifdef HAVE_ERROR_H # include #endif /* HAVE_ERROR_H */ #include #include #include #include #include #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ #include #ifdef HAVE_SYS_TYPES_H # include #endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_SYS_WAIT_H # include #endif /* HAVE_SYS_WAIT_H */ #include "util.h" #include "diff.h" #ifndef DIFF #define DIFF "diff" #endif #ifndef PATCH #define PATCH "patch" #endif /* This can be invoked as interdiff, combinediff, or flipdiff. */ static enum { mode_inter, mode_combine, mode_flip, } mode; static int flipdiff_inplace = 0; struct file_list { char *file; long pos; struct file_list *next; struct file_list *tail; }; struct lines { char *line; size_t length; unsigned long n; struct lines *next; struct lines *prev; }; struct lines_info { char *unline; unsigned long first_offset; unsigned long min_context; struct lines *head; struct lines *tail; }; static int human_readable = 1; static char diff_opts[4]; static unsigned int max_context_real = 3, max_context = 3; static int context_specified = 0; static int ignore_components = 0; static int unzip = 0; static int no_revert_omitted = 0; static int debug = 0; static struct patlist *pat_drop_context = NULL; static struct file_list *files_done = NULL; static struct file_list *files_in_patch2 = NULL; /* checks whether file needs processing and sets context */ static int check_filename (const char *fn) { if (patlist_match(pat_drop_context, fn)) { max_context = 0; } else { max_context = max_context_real; } return 1; } static void add_to_list (struct file_list **list, const char *file, long pos) { struct file_list *make; make = xmalloc (sizeof *make); make->next = NULL; make->tail = NULL; make->file = xstrdup (file); make->pos = pos; if (*list) { (*list)->tail->next = make; (*list)->tail = make; } else { make->tail = make; *list = make; } } static long file_in_list (struct file_list *list, const char *file) { file = stripped (file, ignore_components); while (list) { if (!strcmp (stripped (list->file, ignore_components), file)) return list->pos; list = list->next; } return -1; } static void free_list (struct file_list *list) { struct file_list *next; for (; list; list = next) { next = list->next; free (list->file); free (list); } } static void insert_line_before (struct lines_info *lines, struct lines *at, struct lines *make) { make->next = at; make->prev = at->prev; if (at->prev) at->prev->next = make; else lines->head = make; at->prev = make; } /* Returns 1 is there is a conflict. */ static int add_line (struct lines_info *lines, const char *line, size_t length, unsigned long n) { struct lines *make; struct lines *at; make = xmalloc (sizeof *make); make->n = n; make->line = xmalloc (length + 1); memcpy (make->line, line, length); make->line[length] = '\0'; make->length = length; if (!lines->tail) { /* New */ make->prev = NULL; make->next = NULL; lines->head = make; lines->tail = make; return 0; } if (lines->tail->n < n) { /* End */ lines->tail->next = make; make->next = NULL; make->prev = lines->tail; lines->tail = make; return 0; } if (!lines->head) error (EXIT_FAILURE, 0, "List corrupted: no head"); at = lines->head; while (at) { if (n < at->n) { insert_line_before (lines, at, make); return 0; } if (n == at->n) { free (make->line); free (make); if (at->length == length && !memcmp (at->line, line, length)) /* Already there. */ return 0; /* Clash: first one wins. */ if (at->length < length) return -1; if (at->length > length) return 1; return memcmp (at->line, line, length); } make->prev = at; at = at->next; } if (!at) error (EXIT_FAILURE, 0, "List corrupted: ordering"); return 1; } static void merge_lines (struct lines_info *lines1, struct lines_info *lines2) { struct lines *at, *at_prev, *make; /* * Note: we don't care about the tail member here - not needed * anymore. */ if (lines2->first_offset < lines1->first_offset) lines1->first_offset = lines2->first_offset; if (!lines1->head) { /* first list empty - only take second */ lines1->head = lines2->head; return; } /* merge lines in one pass */ at = lines1->head; make = lines2->head; while (at) { while (make) { if (make->n > at->n) break; if (make->n < at->n) { struct lines *next = make->next; insert_line_before (lines1, at, make); make = next; continue; } make = make->next; /* line number equal - first wins */ } at_prev = at; at = at->next; } /* append the rest of list 2 to list 1 */ if (make) at_prev->next = make; } static void free_lines (struct lines *list) { struct lines *next; for (; list; list = next) { next = list->next; free (list->line); free (list); } } static void clear_lines_info (struct lines_info *info) { free_lines (info->head); info->tail = info->head = NULL; free (info->unline); info->unline = NULL; } static void whitespace_damage (const char *which) { error (EXIT_FAILURE, 0, "Whitespace damage detected in %s", which); } static struct lines * create_orig (FILE *f, struct lines_info *file, int reverted, int *clash) { unsigned long linenum; char *line = NULL, first_char; size_t linelen = 0; int last_was_add; long pos = ftell (f); unsigned long min_context = (unsigned long) -1; do { if (getline (&line, &linelen, f) == -1) break; } while (strncmp (line, "@@ ", 3)); while (!feof (f)) { /* Find next hunk */ unsigned long orig_lines, new_lines, newline; int file_is_removed = 0; unsigned long context; int leading_context; char *p, *q; if (strncmp (line, "@@", 2)) { fseek (f, pos, SEEK_SET); break; } if (reverted) { new_lines = orig_num_lines (line); orig_lines = new_num_lines (line); } else { orig_lines = orig_num_lines (line); new_lines = new_num_lines (line); } p = strchr (line, reverted ? '+' : '-'); if (!p) break; p++; linenum = strtoul (p, &q, 10); if (p == q) break; if (linenum == 0) { file_is_removed = 1; file->first_offset = 0; } else if (!file->first_offset || linenum < file->first_offset) { file->first_offset = linenum; if (!orig_lines) file->first_offset++; } /* Note the amount of leading context, in case the user * supplied a -U option. */ context = 0; leading_context = 1; /* Now copy the relevant bits of the hunk */ last_was_add = 0; newline = 1; while (orig_lines || new_lines || newline) { ssize_t got; pos = ftell (f); got = getline (&line, &linelen, f); if (got == -1) break; if (!orig_lines && !new_lines && line[0] != '\\') break; first_char = line[0]; if (reverted) { if (first_char == '-') first_char = '+'; else if (first_char == '+') first_char = '-'; } switch (first_char) { case '\n': whitespace_damage("input"); case ' ': if (leading_context) context++; if (new_lines) new_lines--; case '-': if (first_char == '-') leading_context = 0; if (orig_lines) orig_lines--; if (!file_is_removed) if (add_line (file, line + 1, (size_t) got - 1, linenum++) && clash) { ++*clash; if (debug) printf ("clash at " "line %lu\n", linenum - 1); } break; case '+': leading_context = 0; if (new_lines) new_lines--; break; case '\\': leading_context = 0; newline = 0; if (!file_is_removed && !last_was_add) { struct lines *at, *prev = NULL; for (at = file->head; at; at = at->next) prev = at; if (!prev) error (EXIT_FAILURE, 0, "Garbled patch"); if (prev->length >= 1 && prev->line[prev->length-1] == '\n') prev->length--; } break; } last_was_add = (line[0] == '+'); } if (!newline) { pos = ftell (f); if (getline (&line, &linelen, f) == -1) break; } if (context < min_context) min_context = context; } if (line) free (line); file->min_context = min_context; return file->head; } static void construct_unline (struct lines_info *file_info) { char *un; struct lines *at; size_t i; if (file_info->unline) /* Already done. */ return; un = file_info->unline = xmalloc (7); /* First pass: construct a small line not in the file. */ for (i = 0, at = file_info->head; at && i < 5; i++, at = at->next) { size_t j = strlen (at->line) - 1; if (i < j) j = i; un[i] = at->line[j] + 1; if (iscntrl (un[i])) un[i] = '!'; } for (; i < 5; i++) un[i] = '!'; un[i++] = '\n'; un[i] = '\0'; for (i = 4; i > 0; i--) { /* Is it unique yet? */ for (at = file_info->head; at; at = at->next) { if (!strcmp (at->line, un)) break; } if (!at) /* Yes! */ break; un[i] = '\n'; un[i + 1] = '\0'; } if (i == 0) { /* Okay, we'll do it the hard way, and generate a long line. */ size_t maxlength = 0; for (at = file_info->head; at; at = at->next) { size_t len = strlen (at->line); if (len > maxlength) maxlength = len; } free (un); un = file_info->unline = xmalloc (maxlength + 3); for (i = 0; i < maxlength; i++) un[i] = '!'; un[i++] = '\n'; un[i] = '\0'; } } static int write_file (struct lines_info *file_info, int fd) { unsigned long linenum; struct lines *at; FILE *fout = fdopen (fd, "w"); construct_unline (file_info); for (linenum = 1; linenum < file_info->first_offset; linenum++) fputs (file_info->unline, fout); for (at = file_info->head; at; at = at->next) { unsigned long i = at->n - linenum; while (i--) { fprintf (fout, "%s", file_info->unline); linenum++; } fwrite (at->line, at->length, 1, fout); linenum++; } fclose (fout); return 0; } static int do_output_patch1_only (FILE *p1, FILE *out, int not_reverted) { char *line; char *oldname; char first_char; size_t linelen; ssize_t got; long pos; oldname = NULL; linelen = 0; if (getline (&oldname, &linelen, p1) < 0) error (EXIT_FAILURE, errno, "Bad patch #1"); if (strncmp (oldname, "--- ", 4)) error (EXIT_FAILURE, 0, "Bad patch #1"); line = NULL; linelen = 0; if (getline (&line, &linelen, p1) < 0) error (EXIT_FAILURE, errno, "Bad patch #1"); if (strncmp (line, "+++ ", 4)) error (EXIT_FAILURE, 0, "Bad patch #1"); if (not_reverted) { /* Combinediff: copy patch */ if (human_readable && mode != mode_flip) fprintf (out, "unchanged:\n"); fputs (oldname, out); fputs (line, out); } else if (!no_revert_omitted) { if (human_readable) fprintf (out, "reverted:\n"); fprintf (out, "--- %s", line + 4); fprintf (out, "+++ %s", oldname + 4); } free (oldname); pos = ftell (p1); got = getline (&line, &linelen, p1); if (got < 0) error (EXIT_FAILURE, errno, "Bad patch #1"); for (;;) { unsigned long orig_lines; unsigned long new_lines; unsigned long newline; char *d1, *d2, *p; size_t h; if (strncmp (line, "@@ ", 3)) { fseek (p1, pos, SEEK_SET); break; } p = line + 3; h = strcspn (p, " \t"); d1 = xstrndup (p, h); p += h; p += strspn (p, " \t"); h = strcspn (p, " \t"); d2 = xstrndup (p, h); if (!*d1 || !*d2) error (EXIT_FAILURE, 0, "Bad patch #1"); if (not_reverted) { /* Combinediff: copy patch */ fwrite (line, (size_t) got, 1, out); new_lines = orig_num_lines (d1); orig_lines = new_num_lines (d2); } else { /* Interdiff: revert patch */ if (!no_revert_omitted) fprintf (out, "@@ -%s +%s @@\n", d2 + 1, d1 + 1); orig_lines = orig_num_lines (d1); new_lines = new_num_lines (d2); } free (d1); free (d2); newline = 1; while (orig_lines || new_lines || newline) { pos = ftell (p1); got = getline (&line, &linelen, p1); if (got == -1) break; if (!orig_lines && !new_lines && line[0] != '\\') break; first_char = line[0]; if (not_reverted) { if (first_char == '+') first_char = '-'; else if (first_char == '-') first_char = '+'; } switch (first_char) { case '\n': whitespace_damage("patch #1"); case ' ': if (orig_lines) orig_lines--; if (new_lines) new_lines--; if (not_reverted || !no_revert_omitted) fwrite (line, (size_t) got, 1, out); break; case '+': if (new_lines) new_lines--; if (not_reverted || !no_revert_omitted) { fputc ('-', out); fwrite (line + 1, (size_t) got - 1, 1, out); } break; case '-': if (orig_lines) orig_lines--; if (not_reverted || !no_revert_omitted) { fputc ('+', out); fwrite (line + 1, (size_t) got - 1, 1, out); } break; case '\\': newline = 0; if (not_reverted || !no_revert_omitted) fwrite (line, (size_t) got, 1, out); break; } } if (!newline) { pos = ftell (p1); if (getline (&line, &linelen, p1) == -1) break; } } if (line) free (line); return 0; } static int output_patch1_only (FILE *p1, FILE *out, int not_reverted) { const char *tmpdir; unsigned int tmplen; const char tail1[] = "/interdiff-1.XXXXXX"; const char tail2[] = "/interdiff-2.XXXXXX"; char *tmpp1, *tmpp2; char options[100]; int tmpp1fd, tmpp2fd; long pos; char *oldname = NULL, *newname = NULL; size_t oldnamelen = 0, newnamelen = 0; struct lines_info file_orig = { NULL, 0, 0, NULL, NULL }; struct lines_info file_new = { NULL, 0, 0, NULL, NULL }; pid_t child; FILE *in; int diff_is_empty = 1; unsigned int use_context = max_context; if (diff_opts[0] == '\0' && !context_specified) return do_output_patch1_only (p1, out, not_reverted); /* We want to redo the diff using the supplied options. */ tmpdir = getenv ("TMPDIR"); if (!tmpdir) tmpdir = P_tmpdir; tmplen = strlen (tmpdir); tmpp1 = alloca (tmplen + sizeof (tail1)); memcpy (tmpp1, tmpdir, tmplen); memcpy (tmpp1 + tmplen, tail1, sizeof (tail1)); tmpp2 = alloca (tmplen + sizeof (tail2)); memcpy (tmpp2, tmpdir, tmplen); memcpy (tmpp2 + tmplen, tail2, sizeof (tail2)); tmpp1fd = xmkstemp (tmpp1); tmpp2fd = xmkstemp (tmpp2); pos = ftell (p1); do { if (oldname) { free (oldname); oldname = NULL; oldnamelen = 0; } if (getline (&oldname, &oldnamelen, p1) < 0) error (EXIT_FAILURE, errno, "Bad patch #1"); } while (strncmp (oldname, "--- ", 4)); oldname[strlen (oldname) - 1] = '\0'; if (getline (&newname, &newnamelen, p1) < 0) error (EXIT_FAILURE, errno, "Bad patch #1"); if (strncmp (newname, "+++ ", 4)) error (EXIT_FAILURE, errno, "Bad patch #1"); newname[strlen (newname) - 1] = '\0'; /* Recreate the original and modified state. */ fseek (p1, pos, SEEK_SET); create_orig (p1, &file_orig, !not_reverted, NULL); fseek (p1, pos, SEEK_SET); create_orig (p1, &file_new, not_reverted, NULL); /* Decide how much context to use. */ if (file_orig.min_context < use_context) use_context = file_orig.min_context; if (use_context == 3) sprintf(options, "-%su", diff_opts); else sprintf (options, "-%sU%d", diff_opts, use_context); /* Write it out. */ write_file (&file_orig, tmpp1fd); free (file_new.unline); file_new.unline = xstrdup (file_orig.unline); write_file (&file_new, tmpp2fd); clear_lines_info (&file_orig); clear_lines_info (&file_new); fflush (NULL); in = xpipe (DIFF, &child, "r", DIFF, options, tmpp1, tmpp2, NULL); /* Eat the first line */ for (;;) { int ch = fgetc (in); if (ch == EOF || ch == '\n') break; diff_is_empty = 0; } /* Eat the second line */ for (;;) { int ch = fgetc (in); if (ch == EOF || ch == '\n') break; } if (!diff_is_empty) { char *line = NULL; size_t linelen = 0; if (not_reverted) { fprintf (out, "--- %s\n", oldname + 4); fprintf (out, "+++ %s\n", newname + 4); } else { fprintf (out, "--- %s\n", newname + 4); fprintf (out, "+++ %s\n", oldname + 4); } for (;;) { ssize_t got = getline (&line, &linelen, in); if (got < 0) break; fwrite (line, (size_t) got, 1, out); } free (line); } fclose (in); waitpid (child, NULL, 0); if (debug) printf ("reconstructed orig1=%s orig2=%s\n", tmpp1, tmpp2); else { unlink (tmpp1); unlink (tmpp2); } free (oldname); free (newname); return 0; } static int apply_patch (FILE *patch, const char *file, int reverted) { const char *basename; unsigned long orig_lines, new_lines; size_t linelen; char *line; pid_t child; int status; FILE *w; basename = strrchr (file, '/'); if (basename) basename++; else basename = file; w = xpipe(PATCH, &child, "w", PATCH, reverted ? "-Rsp0" : "-sp0", file, NULL); fprintf (w, "--- %s\n+++ %s\n", basename, basename); line = NULL; linelen = 0; orig_lines = new_lines = 0; for (;;) { ssize_t got = getline (&line, &linelen, patch); if (got == -1) break; if (!orig_lines && !new_lines) { /* FIXME: Should this compare with '@@ ' instead of '--- '? */ if (!strncmp (line, "--- ", 4)) break; if (!strncmp (line, "diff ", 5) || !strncmp (line, "new file mode ", 14) || !strncmp (line, "index ", 6)) continue; } fwrite (line, (size_t) got, 1, w); if (!strncmp (line, "@@ ", 3)) { orig_lines = orig_num_lines (line); new_lines = new_num_lines (line); continue; } if (orig_lines && line[0] != '+') orig_lines--; if (new_lines && line[0] != '-') new_lines--; } fclose (w); waitpid (child, &status, 0); if (line) free (line); return WEXITSTATUS (status); } static int trim_context (FILE *f /* positioned at start of @@ line */, const char *unline /* drop this line */, FILE *out /* where to send output */) { /* For each hunk, trim the context so that the number of * pre-context lines does not exceed the number of * post-context lines. See the fuzz1 test case. */ char *line = NULL; size_t linelen; for (;;) { fpos_t pos; unsigned long pre = 0, pre_seen = 0, post = 0; unsigned long strip_pre = 0, strip_post = 0; unsigned long orig_offset, new_offset; unsigned long orig_count, orig_orig_count, new_orig_count; unsigned long new_count, orig_new_count, new_new_count; unsigned long total_count = 0; /* Read @@ line. */ if (getline (&line, &linelen, f) < 0) break; if (line[0] == '\\') { /* Pass '\' lines through unaltered. */ fputs (line, out); continue; } if (read_atatline (line, &orig_offset, &orig_count, &new_offset, &new_count)) error (EXIT_FAILURE, 0, "Line not understood: %s", line); orig_orig_count = new_orig_count = orig_count; orig_new_count = new_new_count = new_count; fgetpos (f, &pos); while (orig_count || new_count) { if (getline (&line, &linelen, f) < 0) break; total_count++; switch (line[0]) { case '\n': whitespace_damage("input"); case ' ' : if (orig_count) orig_count--; if (new_count) new_count--; if (!pre_seen) { pre++; if (!strcmp (line + 1, unline)) strip_pre = pre; } else { post++; if (strip_post || !strcmp (line + 1, unline)) strip_post++; } break; case '-': if (orig_count) orig_count--; if (strip_post) goto split_hunk; pre_seen = 1; post = 0; break; case '+': if (new_count) new_count--; if (strip_post) goto split_hunk; pre_seen = 1; post = 0; break; } } pre -= strip_pre; post -= strip_post; if (post && pre > post) strip_pre += pre - post; orig_offset += strip_pre; new_orig_count -= strip_pre + strip_post; new_offset += strip_pre; new_new_count -= strip_pre + strip_post; if (orig_orig_count && !new_orig_count) orig_offset--; if (orig_new_count && !new_new_count) new_offset--; if (debug) printf ("Trim: %lu,%lu\n", strip_pre, strip_post); fsetpos (f, &pos); fprintf (out, "@@ -%lu", orig_offset); if (new_orig_count != 1) fprintf (out, ",%lu", new_orig_count); fprintf (out, " +%lu", new_offset); if (new_new_count != 1) fprintf (out, ",%lu", new_new_count); fprintf (out, " @@\n"); while (total_count--) { ssize_t got = getline (&line, &linelen, f); assert (got > 0); if (strip_pre) { strip_pre--; continue; } if (total_count < strip_post) continue; fwrite (line, (size_t) got, 1, out); } } free (line); return 0; split_hunk: error (0, 0, "hunk-splitting is required in this case, but is not yet implemented"); error (1, 0, "use the -U option to work around this"); return 0; } static int output_delta (FILE *p1, FILE *p2, FILE *out) { const char *tmpdir = getenv ("TMPDIR"); unsigned int tmplen; const char tail1[] = "/interdiff-1.XXXXXX"; const char tail2[] = "/interdiff-2.XXXXXX"; char *tmpp1, *tmpp2; int tmpp1fd, tmpp2fd; struct lines_info file = { NULL, 0, 0, NULL, NULL }; struct lines_info file2 = { NULL, 0, 0, NULL, NULL }; char *oldname = NULL, *newname = NULL; pid_t child; FILE *in; size_t namelen; long pos1 = ftell (p1), pos2 = ftell (p2); long pristine1, pristine2; long start1, start2; char options[100]; int diff_is_empty = 1; pristine1 = ftell (p1); pristine2 = ftell (p2); if (!tmpdir) tmpdir = P_tmpdir; tmplen = strlen (tmpdir); tmpp1 = alloca (tmplen + sizeof (tail1)); memcpy (tmpp1, tmpdir, tmplen); memcpy (tmpp1 + tmplen, tail1, sizeof (tail1)); tmpp2 = alloca (tmplen + sizeof (tail2)); memcpy (tmpp2, tmpdir, tmplen); memcpy (tmpp2 + tmplen, tail2, sizeof (tail2)); if (max_context == 3) sprintf(options, "-%su", diff_opts); else sprintf (options, "-%sU%d", diff_opts, max_context); tmpp1fd = xmkstemp (tmpp1); tmpp2fd = xmkstemp (tmpp2); do { if (oldname) { free (oldname); oldname = NULL; } if (getline (&oldname, &namelen, p1) < 0) error (EXIT_FAILURE, errno, "Bad patch #1"); } while (strncmp (oldname, "+++ ", 4)); oldname[strlen (oldname) - 1] = '\0'; do { if (newname) { free (newname); newname = NULL; } if (getline (&newname, &namelen, p2) < 0) error (EXIT_FAILURE, errno, "Bad patch #2"); } while (strncmp (newname, "+++ ", 4)); newname[strlen (newname) - 1] = '\0'; start1 = ftell (p1); start2 = ftell (p2); fseek (p1, pos1, SEEK_SET); fseek (p2, pos2, SEEK_SET); create_orig (p2, &file, 0, NULL); fseek (p1, pos1, SEEK_SET); fseek (p2, pos2, SEEK_SET); create_orig (p1, &file2, mode == mode_combine, NULL); merge_lines(&file, &file2); pos1 = ftell (p1); /* Write it out. */ write_file (&file, tmpp1fd); write_file (&file, tmpp2fd); fseek (p1, start1, SEEK_SET); fseek (p2, start2, SEEK_SET); if (apply_patch (p1, tmpp1, mode == mode_combine)) error (EXIT_FAILURE, 0, "Error applying patch1 to reconstructed file"); if (apply_patch (p2, tmpp2, 0)) error (EXIT_FAILURE, 0, "Error applying patch2 to reconstructed file"); fseek (p1, pos1, SEEK_SET); fflush (NULL); in = xpipe(DIFF, &child, "r", DIFF, options, tmpp1, tmpp2, NULL); /* Eat the first line */ for (;;) { int ch = fgetc (in); if (ch == EOF || ch == '\n') break; diff_is_empty = 0; } /* Eat the second line */ for (;;) { int ch = fgetc (in); if (ch == EOF || ch == '\n') break; } if (!diff_is_empty) { /* ANOTHER temporary file! This is to catch the case * where we just don't have enough context to generate * a proper interdiff. */ FILE *tmpdiff = xtmpfile (); char *line = NULL; size_t linelen; for (;;) { ssize_t got = getline (&line, &linelen, in); if (got < 0) break; fwrite (line, (size_t) got, 1, tmpdiff); if (*line != ' ' && !strcmp (line + 1, file.unline)) { /* Uh-oh. We're trying to output a * line that made up (we never saw the * original). As long as this is at * the end of a hunk we can safely * drop it (done in trim_context * later). */ got = getline (&line, &linelen, in); if (got < 0) continue; else if (strncmp (line, "@@ ", 3)) { /* An interdiff isn't possible. * Evasive action: just revert the * original and copy the new * version. */ fclose (tmpdiff); free (line); goto evasive_action; } fwrite (line, (size_t) got, 1, tmpdiff); } } free (line); /* First character */ if (human_readable) { char *p, *q, c, d; c = d = '\0'; /* shut gcc up */ p = strchr (oldname + 4, '\t'); if (p) { c = *p; *p = '\0'; } q = strchr (newname + 4, '\t'); if (q) { d = *q; *q = '\0'; } fprintf (out, DIFF " %s %s %s\n", options, oldname + 4, newname + 4); if (p) *p = c; if (q) *q = d; } fprintf (out, "--- %s\n", oldname + 4); fprintf (out, "+++ %s\n", newname + 4); rewind (tmpdiff); trim_context (tmpdiff, file.unline, out); fclose (tmpdiff); } fclose (in); waitpid (child, NULL, 0); if (debug) printf ("reconstructed orig1=%s orig2=%s\n", tmpp1, tmpp2); else { unlink (tmpp1); unlink (tmpp2); } free (oldname); free (newname); clear_lines_info (&file); return 0; evasive_action: if (debug) printf ("reconstructed orig1=%s orig2=%s\n", tmpp1, tmpp2); else { unlink (tmpp1); unlink (tmpp2); } if (human_readable) fprintf (out, "%s impossible; taking evasive action\n", (mode == mode_combine) ? "merge" : "interdiff"); fseek (p1, pristine1, SEEK_SET); fseek (p2, pristine2, SEEK_SET); output_patch1_only (p1, out, mode == mode_combine); output_patch1_only (p2, out, 1); return 0; } static int copy_residue (FILE *p2, FILE *out) { struct file_list *at; for (at = files_in_patch2; at; at = at->next) { if (file_in_list (files_done, at->file) != -1) continue; /* check if we need to process it and init context */ if (!check_filename(at->file)) continue; fseek (p2, at->pos, SEEK_SET); if (human_readable && mode != mode_flip) fprintf (out, "only in patch2:\n"); output_patch1_only (p2, out, 1); } return 0; } static int index_patch2 (FILE *p2) { char *line = NULL; size_t linelen = 0; int is_context = 0; int file_is_empty = 1; /* Index patch2 */ while (!feof (p2)) { unsigned long skip; char *names[2]; char *p, *end; long pos = ftell (p2); if (getline (&line, &linelen, p2) == -1) break; file_is_empty = 0; if (strncmp (line, "--- ", 4)) { is_context = !strncmp (line, "*** ", 4); continue; } if (is_context) error (EXIT_FAILURE, 0, "I don't understand context diffs yet."); names[0] = filename_from_header (line + 4); if (getline (&line, &linelen, p2) == -1) { free (names[0]); break; } if (strncmp (line, "+++ ", 4)) { free (names[0]); continue; } names[1] = filename_from_header (line + 4); if (getline (&line, &linelen, p2) == -1) { free (names[0]); free (names[1]); break; } if (strncmp (line, "@@ ", 3)) goto try_next; p = strchr (line + 3, '+'); if (!p) goto try_next; p = strchr (p, ','); if (p) { /* Like '@@ -1,3 +1,3 @@' */ p++; skip = strtoul (p, &end, 10); if (p == end) goto try_next; } else /* Like '@@ -1 +1 @@' */ skip = 1; add_to_list (&files_in_patch2, best_name (2, names), pos); while (skip--) { if (getline (&line, &linelen, p2) == -1) break; if (line[0] == '-') /* Doesn't count towards skip count */ skip++; } try_next: free (names[0]); free (names[1]); } if (line) free (line); if (file_is_empty || files_in_patch2) return 0; else return 1; } /* With flipdiff we have two patches we want to reorder. The * algorithm is: * * 1. Reconstruct the file as it looks after patch1, using the context * from patch2 as well. * * 2. Apply patch2, in order to reconstruct the file as it looks after * both patches have been applied. Write this out twice. * * 3. Analyse patch2, taking note of the additions and subtractions it * makes. * * 4. To one of the copies of the reconstructed final image, undo the * changes from patch1 by analysing the patch line by line * (ourselves!). Need to take account of offsets due to patch2, and * the fact that patch2 may have changed some lines. */ struct offset { unsigned long line; /* line number after patch1, before patch2 */ long offset; /* offset modification */ }; static struct offset * add_offset (unsigned long line, long offset, struct offset *offsets, unsigned long *allocated, unsigned long *num_offsets) { if (*num_offsets == *allocated) { *allocated *= 2; offsets = xrealloc (offsets, *allocated * sizeof (struct offset)); } offsets[*num_offsets].line = line; offsets[*num_offsets].offset = offset; ++*num_offsets; if (debug) printf ("%lu: %ld\n", line, offset); return offsets; } static void free_offsets (struct offset *offsets) { free (offsets); } static int patch2_removes_line (unsigned long line, /* line number after patch1 */ struct offset *offsets, unsigned long num_offsets) { unsigned long i; for (i = 0; i < num_offsets; i++) { unsigned long this_line = offsets[i].line; long this_offset = offsets[i].offset; if (this_line <= line && this_offset < 0 && this_line - this_offset > line) { if (debug) printf ("@%lu: removed (%ld)\n", line, this_offset); return 1; } } return 0; } static long offset_at_line (unsigned long line, /* line number after patch1 */ struct offset *offsets, unsigned long num_offsets) { long offset = 0; unsigned long i; for (i = 0; i < num_offsets; i++) { unsigned long this_line = offsets[i].line; long this_offset = offsets[i].offset; if (this_line > line) break; offset += this_offset; if (this_line <= line && this_offset < 0 && this_line - this_offset > line) break; } if (debug) printf ("@%lu: %ld\n", line, offset); return offset; } static int insert_line (struct lines_info *lines, const char *line, size_t length, unsigned long n) { struct lines *at; /* Renumber subsequent lines. */ for (at = lines->head; at; at = at->next) if (n <= at->n) break; while (at) { at->n++; at = at->next; } /* Insert the line. */ if (debug) printf ("Insert at %lu: %s", n, line); return add_line (lines, line, length, n); } static void remove_line (struct lines_info *lines, const char *line, unsigned long n) { struct lines *at, *kill = NULL; /* Renumber subsequent lines. */ for (at = lines->head; at; at = at->next) if (n <= at->n) break; if (at && n == at->n) { kill = at; if (strcmp (at->line, line) && kill->prev) { kill = kill->prev; if (debug) printf ("Not removing from %lu: %s", n, at->line); } } at = kill; while (at) { at->n--; at = at->next; } /* Remove the line. */ if (debug) printf ("Remove from %lu: %s", n, kill->line); if (kill->prev) kill->prev->next = kill->next; if (kill->next) kill->next->prev = kill->prev; if (lines->head == kill) lines->head = kill->next; if (lines->tail == kill) lines->tail = kill->prev; free (kill->line); free (kill); } static int take_diff (const char *f1, const char *f2, char *headers[2], const char *unline, FILE *out) { char options[100]; pid_t child; int diff_is_empty = 1; FILE *in; if (max_context == 3) sprintf (options, "-%su", diff_opts); else sprintf (options, "-%sU%d", diff_opts, max_context); if (debug) printf ("+ " DIFF " %s %s %s\n", options, f1, f2); in = xpipe (DIFF, &child, "r", DIFF, options, f1, f2, NULL); /* Eat the first line */ for (;;) { int ch = fgetc (in); if (ch == EOF || ch == '\n') break; diff_is_empty = 0; } /* Eat the second line */ for (;;) { int ch = fgetc (in); if (ch == EOF || ch == '\n') break; } if (!diff_is_empty) { FILE *tmpdiff = xtmpfile (); while (!feof (in)) { int ch = fgetc (in); if (ch != EOF) fputc (ch, tmpdiff); } rewind (tmpdiff); fputs (headers[0], out); fputs (headers[1], out); trim_context (tmpdiff, unline, out); fclose (tmpdiff); } fclose (in); waitpid (child, NULL, 0); return 0; } static int flipdiff (FILE *p1, FILE *p2, FILE *flip1, FILE *flip2) { char *line = NULL; size_t linelen = 0; const char tail1[] = "/flipdiff-1.XXXXXX"; const char tail2[] = "/flipdiff-2.XXXXXX"; const char tail3[] = "/flipdiff-3.XXXXXX"; char *tmpdir = getenv ("TMPDIR"); char *header1[2], *header2[2]; unsigned int tmplen; char *tmpp1, *tmpp2, *tmpp3; int tmpfd; FILE *f; fpos_t at1, at2; struct lines_info intermediate = { NULL, 0, 0, NULL, NULL }; struct offset *offsets = NULL; unsigned long offset_alloc = 100; unsigned long num_offsets = 0; long this_offset = 0; unsigned long first_linenum = 0; unsigned long linenum; int saw_first_offset; int clash = 0; unsigned long orig_lines, new_lines; /* Read headers. */ header1[0] = header1[1] = NULL; linelen = 0; getline (&header1[0], &linelen, p1); linelen = 0; getline (&header1[1], &linelen, p1); header2[0] = header2[1] = NULL; linelen = 0; getline (&header2[0], &linelen, p2); linelen = 0; getline (&header2[1], &linelen, p2); linelen = 0; fgetpos (p1, &at1); fgetpos (p2, &at2); /* Generate temporary file name templates. */ if (!tmpdir) tmpdir = P_tmpdir; tmplen = strlen (tmpdir); tmpp1 = alloca (tmplen + sizeof (tail1)); memcpy (tmpp1, tmpdir, tmplen); memcpy (tmpp1 + tmplen, tail1, sizeof (tail1)); tmpp2 = alloca (tmplen + sizeof (tail2)); memcpy (tmpp2, tmpdir, tmplen); memcpy (tmpp2 + tmplen, tail2, sizeof (tail2)); tmpp3 = alloca (tmplen + sizeof (tail3)); memcpy (tmpp3, tmpdir, tmplen); memcpy (tmpp3 + tmplen, tail3, sizeof (tail3)); /* Reconstruct the file after patch1. */ create_orig (p1, &intermediate, 1, NULL); /* Reconstruct the file before patch2. */ create_orig (p2, &intermediate, 0, &clash); /* If any of the lines grokked from the patches mis-matched, we are * likely to run into problems. */ if (clash) error (EXIT_FAILURE, 0, "patches clashed in %d place%s - " "re-generate them first", clash, clash == 1 ? "" : "s"); /* Now we have all the context we're going to get. Write out * the file and apply patch1 in reverse, so we end up with the * file as it should look before applying patches. */ tmpfd = xmkstemp (tmpp1); write_file (&intermediate, tmpfd); fsetpos (p1, &at1); if (apply_patch (p1, tmpp1, 1)) error (EXIT_FAILURE, 0, "Error reconstructing original file"); /* Write it out again and apply patch2, so we end up with the * file as it should look after both patches. */ tmpfd = xmkstemp (tmpp3); write_file (&intermediate, tmpfd); fsetpos (p2, &at2); if (apply_patch (p2, tmpp3, 0)) error (EXIT_FAILURE, 0, "Error reconstructing final file"); /* Examine patch2 to figure out offsets. */ fsetpos (p2, &at2); offsets = xmalloc (offset_alloc * sizeof (struct offset)); orig_lines = new_lines = 0; for (;;) { if (getline (&line, &linelen, p2) == -1) { if (this_offset) { offsets = add_offset (first_linenum, this_offset, offsets, &offset_alloc, &num_offsets); this_offset = 0; } break; } if (!orig_lines && !new_lines && this_offset) { offsets = add_offset (first_linenum, this_offset, offsets, &offset_alloc, &num_offsets); this_offset = 0; } if (!orig_lines && !new_lines && strncmp (line, "@@ ", 3)) break; if (!strncmp (line, "@@ ", 3)) { if (read_atatline (line, &linenum, &orig_lines, NULL, &new_lines)) error (EXIT_FAILURE, 0, "line not understood: %s", line); continue; } if (orig_lines && line[0] != '+') orig_lines--; if (new_lines && line[0] != '-') new_lines--; switch (line[0]) { case '\n': whitespace_damage("patch #2"); case ' ': if (this_offset) { offsets = add_offset (first_linenum, this_offset, offsets, &offset_alloc, &num_offsets); this_offset = 0; } break; case '-': if (this_offset > 0) { offsets = add_offset (first_linenum, this_offset, offsets, &offset_alloc, &num_offsets); this_offset = 0; } if (this_offset == 0) first_linenum = linenum; this_offset--; break; case '+': if (this_offset < 0) { offsets = add_offset (first_linenum, this_offset, offsets, &offset_alloc, &num_offsets); this_offset = 0; } if (this_offset == 0) first_linenum = linenum; this_offset++; break; } if (line[0] != '+') linenum++; } /* Now read the temporary file we wrote (and patched) back * into memory, into our 'intermediate' structure, in order to * modify it (ourselves!) using patch1. */ free_lines (intermediate.head); intermediate.head = intermediate.tail = NULL; f = fopen (tmpp3, "r"); if (!f) error (EXIT_FAILURE, errno, "error opening temporary file"); linenum = 0; saw_first_offset = 0; while (!feof (f)) { ssize_t got; linenum++; got = getline (&line, &linelen, f); if (got == -1) break; if (!strcmp (line, intermediate.unline)) { if (!saw_first_offset) intermediate.first_offset = linenum + 1; continue; } if (!saw_first_offset) { saw_first_offset = 1; intermediate.first_offset = linenum; } add_line (&intermediate, line, (size_t) got, linenum); } /* Modify it according to patch1, making sure to adjust for * offsets introduced in patch2. */ fsetpos (p1, &at1); this_offset = 0; orig_lines = new_lines = 0; for (;;) { ssize_t got; fgetpos (p1, &at1); got = getline (&line, &linelen, p1); if (got == -1) break; if (!orig_lines && !new_lines && strncmp (line, "@@ ", 3)) { fsetpos (p1, &at1); break; } if (!orig_lines && !new_lines) { if (read_atatline (line, NULL, &orig_lines, &linenum, &new_lines)) error (EXIT_FAILURE, 0, "line not understood: %s", line); continue; } /* We'll track the offset relative to the intermediate * file in linenum. */ if (orig_lines && line[0] != '+') orig_lines--; if (new_lines && line[0] != '-') new_lines--; if (line[0] == '+') { if (!patch2_removes_line (linenum, offsets, num_offsets)) { unsigned long at = linenum; at += offset_at_line (linenum, offsets, num_offsets); at += this_offset; remove_line (&intermediate, line + 1, at); this_offset--; } } else if (line[0] == '-') { if (!patch2_removes_line (linenum, offsets, num_offsets)) { unsigned long at = linenum; at += offset_at_line (linenum, offsets, num_offsets); at += this_offset; insert_line (&intermediate, line + 1, (size_t) got - 1, at); } this_offset++; } if (line[0] != '-') linenum++; } tmpfd = xmkstemp (tmpp2); write_file (&intermediate, tmpfd); /* Now tmpp1 is the start point, tmpp3 is the end point, and * tmpp2 is the mid-point once the diffs have been flipped. * So just take diffs and we're done. */ take_diff (tmpp1, tmpp2, header2, intermediate.unline, flip1); take_diff (tmpp2, tmpp3, header1, intermediate.unline, flip2); free (line); free_offsets (offsets); fclose (f); if (debug) printf ("flipped\n"); else { unlink (tmpp1); unlink (tmpp2); unlink (tmpp3); } return 0; } static int copy (FILE *from, FILE *to) { while (!feof (from)) { int ch = fgetc (from); if (ch == EOF) break; fputc (ch, to); } return 0; } static int no_patch (const char *f) { error (0, 0, "%s doesn't contain a patch", f); return 0; } static int interdiff (FILE *p1, FILE *p2, const char *patch1, const char *patch2) { char *line = NULL; size_t linelen = 0; int is_context = 0; int patch_found = 0; int file_is_empty = 1; FILE *flip1 = NULL, *flip2 = NULL; if (mode == mode_flip) { flip1 = xtmpfile (); flip2 = xtmpfile (); } if (index_patch2 (p2)) no_patch (patch2); /* Search for next file to patch */ while (!feof (p1)) { char *names[2]; char *p; long pos, start_pos = ftell (p1); if (line) { free (line); line = NULL; linelen = 0; } if (getline (&line, &linelen, p1) == -1) break; file_is_empty = 0; if (strncmp (line, "--- ", 4)) { is_context = !strncmp (line, "*** ", 4); continue; } if (is_context) error (EXIT_FAILURE, 0, "I don't understand context diffs yet."); names[0] = filename_from_header (line + 4); if (getline (&line, &linelen, p1) == -1) break; if (strncmp (line, "+++ ", 4)) continue; names[1] = filename_from_header (line + 4); p = xstrdup (best_name (2, names)); free (names[0]); free (names[1]); patch_found = 1; /* check if we need to process it and init context */ if (!check_filename(p)) { add_to_list (&files_done, p, 0); continue; } fseek (p1, start_pos, SEEK_SET); pos = file_in_list (files_in_patch2, p); if (pos == -1) { output_patch1_only (p1, mode == mode_flip ? flip2 : stdout, mode != mode_inter); } else { fseek (p2, pos, SEEK_SET); if (mode == mode_flip) flipdiff (p1, p2, flip1, flip2); else output_delta (p1, p2, stdout); } add_to_list (&files_done, p, 0); free (p); } if (!file_is_empty && !patch_found) no_patch (patch1); copy_residue (p2, mode == mode_flip ? flip1 : stdout); if (mode == mode_flip) { /* Now we flipped the two patches, show them. */ rewind (flip1); rewind (flip2); if (flipdiff_inplace) { FILE *pp1 = xopen (patch1, "wb"); FILE *pp2 = xopen (patch2, "wb"); copy (flip1, pp2); copy (flip2, pp1); fclose (pp1); fclose (pp2); } else { copy (flip1, stdout); puts ("\n=== 8< === cut here === 8< ===\n"); copy (flip2, stdout); } } if (flip1) fclose (flip1); if (flip2) fclose (flip2); free_list (files_in_patch2); free_list (files_done); if (line) free (line); return 0; } NORETURN static void syntax (int err) { const char *const syntax_str = "usage: %s [OPTIONS] patch1 patch2\n" " %s --version|--help\n" "OPTIONS are:\n" " -U N, --unified=N\n" " max lines of context to carry\n" " -i, --ignore-case\n" " Consider upper- and lower-case to be the same\n" " -w, --ignore-all-space\n" " ignore whitespace changes in patches\n" " -b, --ignore-space-change\n" " ignore changes in the amount of whitespace\n" " -B, --ignore-blank-lines\n" " ignore changes whose lines are all blank\n" " -p N, --strip-match=N\n" " pathname components to ignore\n" " -q, --quiet\n" " don't add rationale text\n" " -d PAT, --drop-context=PAT\n" " drop context on matching files\n" " -z, --decompress\n" " decompress .gz and .bz2 files\n" " --interpolate run as 'interdiff'\n" " --combine run as 'combinediff'\n" " --flip run as 'flipdiff'\n" " --no-revert-omitted\n" " (interdiff) When a patch from patch1 is not in patch2,\n" " don't revert it\n" " --in-place (flipdiff) Write the output to the original input\n" " files\n"; fprintf (err ? stderr : stdout, syntax_str, progname, progname); exit (err); } static void set_interdiff (void) { /* This is interdiff. */ set_progname ("interdiff"); mode = mode_inter; } static void set_combinediff (void) { /* This is combinediff. */ set_progname ("combinediff"); mode = mode_combine; } static void set_flipdiff (void) { /* This is flipdiff. */ set_progname ("flipdiff"); mode = mode_flip; } static void get_mode_from_name (const char *argv0) { /* This is interdiff, unless it is named 'combinediff' or * 'flipdiff'. */ const char *p = strrchr (argv0, '/'); if (!p++) p = argv0; if (strstr (p, "combine")) set_combinediff (); else if (strstr (p, "flip")) set_flipdiff (); else set_interdiff (); } int main (int argc, char *argv[]) { FILE *p1, *p2; int num_diff_opts = 0; int ret; get_mode_from_name (argv[0]); diff_opts[0] = '\0'; for (;;) { static struct option long_options[] = { {"help", 0, 0, 1000 + 'H'}, {"version", 0, 0, 1000 + 'V'}, {"interpolate", 0, 0, 1000 + 'I' }, {"combine", 0, 0, 1000 + 'C' }, {"flip", 0, 0, 1000 + 'F' }, {"no-revert-omitted", 0, 0, 1000 + 'R' }, {"in-place", 0, 0, 1000 + 'i' }, {"debug", 0, 0, 1000 + 'D' }, {"strip-match", 1, 0, 'p'}, {"unified", 1, 0, 'U'}, {"drop-context", 1, 0, 'd'}, {"ignore-blank-lines", 0, 0, 'B'}, {"ignore-space-change", 0, 0, 'b'}, {"ignore-case", 0, 0, 'i'}, {"ignore-all-space", 0, 0, 'w'}, {"decompress", 0, 0, 'z'}, {"quiet", 0, 0, 'q'}, {0, 0, 0, 0} }; char *end; int c = getopt_long (argc, argv, "BU:bd:hip:qwz", long_options, NULL); if (c == -1) break; switch (c) { case 1000 + 'V': printf("%s - patchutils version %s\n", progname, VERSION); exit(0); case 1000 + 'H': syntax (0); break; case 'h': break; case 'U': max_context_real = strtoul (optarg, &end, 0); if (optarg == end) syntax (1); context_specified = 1; break; case 'p': ignore_components = strtoul (optarg, &end, 0); if (optarg == end) syntax (1); break; case 'q': human_readable = 0; break; case 'd': patlist_add (&pat_drop_context, optarg); break; case 'z': unzip = 1; break; case 'B': case 'b': case 'i': case 'w': if (!memchr (diff_opts, c, num_diff_opts)) { diff_opts[num_diff_opts++] = c; diff_opts[num_diff_opts] = '\0'; } break; case 1000 + 'I': set_interdiff (); break; case 1000 + 'C': set_combinediff (); break; case 1000 + 'F': set_flipdiff (); break; case 1000 + 'R': no_revert_omitted = 1; break; case 1000 + 'i': if (mode != mode_flip) syntax (1); flipdiff_inplace = 1; break; case 1000 + 'D': debug = 1; break; default: syntax(1); } } if (unzip && flipdiff_inplace) error (EXIT_FAILURE, 0, "-z and --in-place are mutually exclusive."); if (optind + 2 != argc) syntax (1); if (unzip) { p1 = xopen_unzip (argv[optind], "rb"); p2 = xopen_unzip (argv[optind + 1], "rb"); } else { if (strcmp (argv[optind], "-") == 0 && strcmp(argv[optind+1], "-") == 0) error (EXIT_FAILURE, 0, "only one input file can come from stdin"); p1 = strcmp (argv[optind], "-") == 0 ? stdin : xopen (argv[optind], "rbm"); p2 = strcmp (argv[optind+1], "-") == 0 ? stdin : xopen (argv[optind + 1], "rbm"); } p1 = convert_to_unified (p1, "rb", 1); p2 = convert_to_unified (p2, "rb", 1); ret = interdiff (p1, p2, argv[optind], argv[optind + 1]); fclose (p1); fclose (p2); patlist_free (&pat_drop_context); return ret; } patchutils-0.4.2/src/myerror.c000066400000000000000000000032541370426545100163420ustar00rootroot00000000000000/* Error handler for noninteractive utilities Copyright (C) 1990-1998, 2000, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. Its master source is NOT part of the C library, however. The master source lives in /gd/gnu/lib. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* Written by David MacKenzie . */ #ifdef HAVE_CONFIG_H # include #endif #ifndef HAVE_ERROR #include #include #include #include #ifdef HAVE_SYS_TYPES_H # include #endif /* HAVE_SYS_TYPES_H */ #include "util.h" void error (int status, int errnum, const char *message, ...) { va_list args; fflush (stdout); fprintf (stderr, "%s: ", progname); va_start (args, message); vfprintf (stderr, message, args); va_end (args); if (errnum) { fprintf (stderr, ": %s", strerror (errnum)); } putc ('\n', stderr); fflush (stderr); if (status) exit (status); } #endif patchutils-0.4.2/src/rediff.c000066400000000000000000000612161370426545100161040ustar00rootroot00000000000000/* * rediff - fix offset and counts of a hand-edited diff * Copyright (C) 2001, 2002, 2004, 2009, 2011, 2019 Tim Waugh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #ifdef HAVE_ERROR_H # include #endif /* HAVE_ERROR_H */ #include #include #include #include #include #ifdef HAVE_SYS_TYPES_H # include // for ssize_t #endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_UNISTD_H # include // for access #endif /* HAVE_UNISTD_H */ #ifdef HAVE_SYS_WAIT_H # include #endif /* HAVE_SYS_WAIT_H */ #include "diff.h" #include "util.h" #ifndef DIFF #define DIFF "diff" #endif /* DIFF */ struct file_info { const char *orig_file; const char *new_file; int info_written; int info_pending; }; struct hunk { fpos_t filepos; struct file_info *info; unsigned long line_in_diff; unsigned long num_lines; unsigned long orig_offset; unsigned long orig_count; unsigned long new_offset; unsigned long new_count; struct hunk *next; /* must be ordered by line_in_diff */ int discard_offset; }; /* Copy hunk from in to out with no modifications. * @@ line has already been read. * orig_lines: original line count * new_lines: new line count */ static unsigned long copy_hunk (FILE *in, FILE *out, unsigned long orig_lines, unsigned long new_lines) { int newline = 1; fpos_t pos; char *line = NULL; size_t linelen = 0; unsigned long count = 0; while (orig_lines || new_lines || newline) { fgetpos (in, &pos); if (getline (&line, &linelen, in) == -1) break; if (!orig_lines && !new_lines && line[0] != '\\') break; count++; fputs (line, out); switch (line[0]) { case ' ': if (new_lines) new_lines--; case '-': if (orig_lines) orig_lines--; break; case '+': if (new_lines) new_lines--; break; case '\\': newline = 0; break; } } if (newline) /* Back up a line. */ fsetpos (in, &pos); return count; } /* Copy hunk from in to out, adjusting offsets by line_offset. */ static unsigned long adjust_offsets_and_copy (long *offset, FILE *in, FILE *out) { char *line = NULL; size_t linelen = 0; unsigned long orig_offset, orig_lines, new_offset, new_lines; unsigned long count = 0; char *trailing; if (getline (&line, &linelen, in) == -1) goto out; count++; if (!strncmp (line, "--- ", 4)) { /* This is the first hunk of a group. Copy the * file info. */ fputs (line, out); if (getline (&line, &linelen, in) == -1) goto out; count++; fputs (line, out); if (getline (&line, &linelen, in) == -1) goto out; count++; /* The line offsets no longer apply. */ *offset = 0; } if (read_atatline (line, &orig_offset, &orig_lines, &new_offset, &new_lines)) { line[strlen (line) - 1] = '\0'; error (EXIT_FAILURE, 0, "Line not understood: %s", line); } /* Find the part after "@@...@@". */ trailing = strchr (line, '+'); trailing += strcspn (trailing, " \n"); if (*trailing == ' ') trailing++; trailing += strspn (trailing, "@"); /* Adjust offsets */ fprintf (out, "@@ -%lu", orig_offset); if (orig_lines != 1) fprintf (out, ",%lu", orig_lines); fprintf (out, " +%lu", new_offset + *offset); if (new_lines != 1) fprintf (out, ",%lu", new_lines); fprintf (out, " @@%s", trailing); free (line); /* Copy remaining lines of hunk */ count += copy_hunk (in, out, orig_lines, new_lines); out: return count; } /* Copy n lines from in to out. */ static unsigned long copy_lines (FILE *in, FILE *out, unsigned long n) { char *line = NULL; size_t linelen = 0; unsigned long count = 0; while (n--) { if (getline (&line, &linelen, in) == -1) break; count++; fputs (line, out); } if (line) free (line); return count; } /* Copy trailing non-diff lines in hunk from in to out. * done: number of lines of hunk already copied. */ static void copy_trailing (struct hunk *hunk, FILE *in, FILE *out, unsigned long done) { if (hunk->next) { /* Copy trailing non-diff text. */ unsigned long todo; if (done < hunk->next->line_in_diff - hunk->line_in_diff) { todo = (hunk->next->line_in_diff - hunk->line_in_diff - done); /* Take one off to account for the difference. */ if (todo > 1) copy_lines (in, out, todo - 1); } } else { /* Copy the rest of the file. */ while (copy_lines (in, out, 100)) ; } } /* Copy hunks from in to out. * from: starting hunk. * upto: hunk to stop before, or NULL. * line_offset: offset adjustment to apply. * is_first: zero unless this is the first hunk in the file. */ static void copy_to (struct hunk *from, struct hunk *upto, long *line_offset, FILE *in, FILE *out, int is_first) { if (!is_first && from && from->info && !from->info->info_written && from->info->info_pending) { fputs (from->info->orig_file, out); fputs (from->info->new_file, out); from->info->info_written = 1; } if (is_first && from) { /* Copy leading non-diff text. */ fseek (in, 0, SEEK_SET); copy_lines (in, out, from->line_in_diff - 1); } for (; from && from != upto; from = from->next) { unsigned long count; fsetpos (in, &from->filepos); count = adjust_offsets_and_copy (line_offset, in, out); copy_trailing (from, in, out, count); } } /* Deal with an added hunk. */ static long added_hunk (const char *meta, long offset, FILE *modify, FILE *t, unsigned long morig_count, unsigned long mnew_count) { long this_offset = 0; char *line = NULL; size_t linelen = 0; char *p = strchr (meta, '-'), *q; unsigned long orig_offset = 0, new_offset; unsigned long orig_count = 0, new_count = 0; FILE *newhunk = xtmpfile (); if (!newhunk) error (EXIT_FAILURE, errno, "Couldn't create temporary file"); if (p) { p++; orig_offset = strtoul (p, &q, 10); } if (!p || p == q) { if (p) p[strlen (p) - 1] = '\0'; error (EXIT_FAILURE, 0, "Hunk addition requires original line: %s", meta); } while (morig_count || mnew_count) { if (getline (&line, &linelen, modify) == -1) break; if (line[0] != '+') error (EXIT_FAILURE, 0, "Only whole hunks may be added"); mnew_count--; switch (line[1]) { case ' ': orig_count++; new_count++; break; case '+': new_count++; this_offset++; break; case '-': orig_count++; this_offset--; break; default: error (EXIT_FAILURE, 0, "Multiple added hunks not supported"); } fputs (line + 1, newhunk); } new_offset = orig_offset + offset; if (!new_count) new_offset--; fprintf (t, "@@ -%lu", orig_offset); if (orig_count != 1) fprintf (t, ",%lu", orig_count); fprintf (t, " +%lu", new_offset); if (new_count != 1) fprintf (t, ",%lu", new_count); fprintf (t, " @@\n"); rewind (newhunk); while (copy_lines (newhunk, t, 100)); fclose (newhunk); if (line) free (line); return this_offset; } /* Deal with a removed hunk. */ static long removed_hunk (const char *meta, FILE *modify, FILE *t, struct hunk **hunkp, unsigned long morig_count, unsigned long mnew_count, unsigned long *replaced) { struct hunk *hunk = *hunkp; long this_offset = 0; char *line = NULL; size_t linelen = 0; unsigned long orig_offset, new_offset; unsigned long orig_count, new_count; int r; *replaced = 0; if (read_atatline (meta, &orig_offset, &orig_count, &new_offset, &new_count)) goto out; if (getline (&line, &linelen, modify) == -1) goto out; if (line[0] == '+' && line[1] == '@') { /* Minimally correct modified @@ banners. */ unsigned long oo, no; char *trailing; if (read_atatline (line + 1, &oo, NULL, &no, NULL)) goto out; /* Display a file name banner. */ if (hunk->info && !hunk->info->info_written) { fputs (hunk->info->orig_file, t); fputs (hunk->info->new_file, t); hunk->info->info_written = 1; } trailing = strchr (line + 1, '+'); trailing += strcspn (trailing, " \n"); if (*trailing == ' ') trailing++; trailing += strspn (trailing, "@"); if (oo != orig_offset) no = new_offset + oo - orig_offset; else oo = orig_offset + no - new_offset; fprintf (t, "@@ -%lu", oo); if (orig_count != 1) fprintf (t, ",%lu", orig_count); fprintf (t, " +%lu", no); if (new_count != 1) fprintf (t, ",%lu", new_count); fprintf (t, " @@%s", trailing); goto out; } if (mnew_count) goto only_whole; *replaced = --morig_count; while (morig_count) { while (orig_count || new_count) { if (line[0] != '-') goto only_whole; switch (line[1]) { case ' ': orig_count--; new_count--; break; case '+': new_count--; this_offset--; break; case '-': orig_count--; this_offset++; break; default: error (EXIT_FAILURE, 0, "Garbled input: %s", line + 1); } if (!--morig_count) break; r = getline (&line, &linelen, modify); assert (r != -1); } if (morig_count) { if (line[0] != '-') goto only_whole; if (read_atatline (line + 1, &orig_offset, &orig_count, &new_offset, &new_count)) goto out; hunk = hunk->next; hunk->info = (*hunkp)->info; if (hunk->info) hunk->info->info_pending = 1; *hunkp = hunk; r = getline (&line, &linelen, modify); assert (r != -1); morig_count--; } } out: if (line) free (line); return this_offset; only_whole: error (EXIT_FAILURE, 0, "Only whole hunks may be added"); exit (EXIT_FAILURE); } /* Output a modified hunk to out. * hunk: original hunk * line_offset: offset modification to apply * modify: diff output that applies to this hunk * original: original diff */ static long show_modified_hunk (struct hunk **hunkp, long line_offset, FILE *modify, FILE *original, FILE *out) { struct hunk *hunk = *hunkp; long this_offset = 0; unsigned long calc_orig_count; unsigned long calc_new_offset, calc_new_count; unsigned long orig_offset, orig_count, new_offset, new_count; unsigned long morig_offset, morig_count, mnew_offset, mnew_count; char *line = NULL; size_t linelen = 0; FILE *t = xtmpfile (); int t_written_to = 0; unsigned long i, at = 1; unsigned long replaced, unaltered; char *trailing; int r; if (!t) error (EXIT_FAILURE, errno, "Couldn't open temporary file"); rewind (modify); fsetpos (original, &hunk->filepos); r = getline (&line, &linelen, original); assert (r != -1); if (hunk->info) { r = getline (&line, &linelen, original); assert (r != -1); r = getline (&line, &linelen, original); assert (r != -1); at += 2; } r = read_atatline (line, &orig_offset, &orig_count, &new_offset, &new_count); assert (!r); calc_orig_count = orig_count; calc_new_offset = new_offset; calc_new_count = new_count; trailing = strchr (line, '+'); trailing += strcspn (trailing, " \n"); if (*trailing == ' ') trailing++; trailing += strspn (trailing, "@"); trailing = xstrdup (trailing); r = getline (&line, &linelen, modify); assert (r != -1); r = read_atatline (line, &morig_offset, &morig_count, &mnew_offset, &mnew_count); assert (!r); replaced = morig_count; do { /* Lines before the modification are unaltered. */ int trim = 0, skip_trim; if (morig_offset < hunk->line_in_diff) error (EXIT_FAILURE, errno, "Invalid changes made"); unaltered = morig_offset - hunk->line_in_diff; if (!morig_count) unaltered++; if (unaltered > at) unaltered -= at; else unaltered = 0; if (!unaltered) trim = 1; #ifdef DEBUG fprintf (stderr, "First %lu lines unaltered\n", unaltered); #endif /* DEBUG */ for (i = unaltered; i; i--) { r = getline (&line, &linelen, original); assert (r != -1); fputs (line, t); at++; t_written_to = 1; switch (line[0]) { case ' ': if (new_count) new_count--; case '-': if (orig_count) orig_count--; break; case '+': if (new_count) new_count--; break; } } while (morig_count || mnew_count) { skip_trim = 0; if (getline (&line, &linelen, modify) == -1) break; if (line[0] == '\\' || line[1] == '\\') error (EXIT_FAILURE, 0, "Don't know how to handle newline " "issues yet."); #ifdef DEBUG fprintf (stderr, "Modify using: %s", line); #endif /* DEBUG */ switch (line[0]) { case '-': switch (line[1]) { case '+': this_offset--; calc_new_count--; skip_trim = 1; break; case '-': this_offset++; calc_orig_count--; break; case ' ': calc_new_count--; calc_orig_count--; break; case '@': goto hunk_end; default: error (EXIT_FAILURE, 0, "Not supported: %c%c", line[0], line[1]); } if (trim && !skip_trim) { orig_offset++; calc_new_offset++; } if (morig_count) morig_count--; break; case '+': switch (line[1]) { case '+': this_offset++; calc_new_count++; fputs (line + 1, t); t_written_to = 1; break; case '-': this_offset--; calc_orig_count++; trim = 0; fputs (line + 1, t); t_written_to = 1; break; case ' ': calc_orig_count++; calc_new_count++; fputs (line + 1, t); t_written_to = 1; break; case '@': goto hunk_end; default: error (EXIT_FAILURE, 0, "Not supported: %c%c", line[0], line[1]); } if (trim) { orig_offset--; calc_new_offset--; } if (mnew_count) mnew_count--; break; } } /* Skip replaced lines in original hunk. */ #ifdef DEBUG fprintf (stderr, "Skip %lu replaced lines\n", replaced); #endif /* DEBUG */ while (replaced) { replaced--; r = getline (&line, &linelen, original); assert (r != -1); at++; switch (line[0]) { case ' ': if (new_count) new_count--; case '-': if (orig_count) orig_count--; break; case '+': if (new_count) new_count--; break; } } hunk_end: if (line[0] && line[1] == '@') { if (line[0] == '+') { long loff; FILE *write_to; write_to = t_written_to ? t : out; if (hunk->info && !hunk->info->info_written) { fputs (hunk->info->orig_file, out); fputs (hunk->info->new_file, out); hunk->info->info_written = 1; } loff = added_hunk (line + 1, this_offset, modify, write_to, morig_count, mnew_count); if (!hunk->discard_offset) line_offset += loff; #ifdef DEBUG else fprintf (stderr, "Discarding offset: %ld\n", loff); #endif /* DEBUG */ } else if (line[0] == '-') { FILE *write_to; write_to = t_written_to ? t : out; this_offset += removed_hunk (line + 1, modify, write_to, hunkp, morig_count, mnew_count, &replaced); hunk = *hunkp; #ifdef DEBUG fprintf (stderr, "Skip %lu replaced lines\n", replaced); #endif /* DEBUG */ /* Prevent an offset banner for this * hunk being generated. */ calc_orig_count = 0; calc_new_count = 0; while (replaced) { replaced--; r = getline (&line, &linelen, original); assert (r != -1); at++; switch (line[0]) { case ' ': if (new_count) new_count--; case '-': if (orig_count) orig_count--; break; case '+': if (new_count) new_count--; break; } } } else error (EXIT_FAILURE, 0, "diff output not understood"); } if (getline (&line, &linelen, modify) == -1) break; r = read_atatline (line, &morig_offset, &morig_count, &mnew_offset, &mnew_count); assert (!r); replaced = morig_count; } while (!feof (modify)); #ifdef DEBUG fprintf (stderr, "Copy remaining lines of original hunk (%lu,%lu)\n", orig_count, new_count); #endif /* DEBUG */ while (orig_count || new_count) { if (getline (&line, &linelen, original) == -1) break; fputs (line, t); #ifdef DEBUG fputs (line, stderr); #endif /* DEBUG */ at++; switch (line[0]) { case ' ': if (new_count) new_count--; case '-': if (orig_count) orig_count--; break; case '+': if (new_count) new_count--; break; } assert (line[0] != '@'); } #ifdef DEBUG fprintf (stderr, "Result:\n"); #endif /* DEBUG */ if (hunk->info && !hunk->info->info_written) { fputs (hunk->info->orig_file, out); fputs (hunk->info->new_file, out); hunk->info->info_written = 1; } rewind (t); if (calc_orig_count || calc_new_count) { fprintf (out, "@@ -%lu", orig_offset); if (calc_orig_count != 1) fprintf (out, ",%lu", calc_orig_count); fprintf (out, " +%lu", calc_new_offset + line_offset); if (calc_new_count != 1) fprintf (out, ",%lu", calc_new_count); fprintf (out, " @@%s", trailing); } free (trailing); while (getline (&line, &linelen, t) != -1) fputs (line, out); if (line) free (line); fclose (modify); fclose (t); #ifdef DEBUG fprintf (stderr, "Trailing:\n"); #endif /* DEBUG */ copy_trailing (hunk, original, out, at - 1); #ifdef DEBUG fprintf (stderr, "(End, offset %ld)\n", this_offset); #endif /* DEBUG */ return this_offset; } /* Write a corrected version of the edited diff to standard output. * * This works by comparing the modified lines in the edited diff with * the hunks in the original diff. */ static int rediff (const char *original, const char *edited, FILE *out) { pid_t child; FILE *o; FILE *m; FILE *t = NULL; char *line = NULL; size_t linelen = 0; unsigned long linenum = 0; struct hunk *hunks = NULL, **p = &hunks, *last = NULL; struct hunk *current_hunk = NULL; long line_offset = 0; /* Let's take a look at what hunks are in the original diff. */ o = xopen (original, "rbm"); while (!feof (o)) { unsigned long o_count, n_count; struct hunk *newhunk; fpos_t pos; /* Search for start of hunk (or file info). */ do { fgetpos (o, &pos); if (getline (&line, &linelen, o) == -1) break; linenum++; if (!strncmp (line, "*** ", 4)) error (EXIT_FAILURE, errno, "Don't know how to handle context " "format yet."); } while (strncmp (line, "@@ ", 3) && strncmp (line, "--- ", 4)); if (feof (o)) break; if (last) last->num_lines = linenum - last->line_in_diff + 1; newhunk = xmalloc (sizeof *newhunk); newhunk->filepos = pos; newhunk->line_in_diff = linenum; newhunk->num_lines = 0; if (!strncmp (line, "--- ", 4)) { struct file_info *info = xmalloc (sizeof *info); info->info_written = info->info_pending = 0; info->orig_file = xstrdup (line); if (getline (&line, &linelen, o) == -1) error (EXIT_FAILURE, errno, "Premature end of file"); info->new_file = xstrdup (line); newhunk->info = info; if (getline (&line, &linelen, o) == -1) error (EXIT_FAILURE, errno, "Premature end of file"); linenum += 2; } else newhunk->info = NULL; read_atatline (line, &newhunk->orig_offset, &newhunk->orig_count, &newhunk->new_offset, &newhunk->new_count); o_count = newhunk->orig_count; n_count = newhunk->new_count; newhunk->next = NULL; if (*p) (*p)->next = newhunk; *p = last = newhunk; p = &newhunk->next; #ifdef DEBUG if (newhunk->info) fprintf (stderr, "This is the first of a group\n"); fprintf (stderr, "Original hunk at line %lu: " "-%lu,%lu +%lu,%lu\n", newhunk->line_in_diff, newhunk->orig_offset, newhunk->orig_count, newhunk->new_offset, newhunk->new_count); #endif /* DEBUG */ /* Skip to next hunk. */ while (o_count || n_count) { if (getline (&line, &linelen, o) == -1) break; linenum++; switch (line[0]) { case ' ': if (n_count) n_count--; case '-': if (o_count) o_count--; break; case '+': if (n_count) n_count--; break; } } } if (!hunks) error (EXIT_FAILURE, 0, "Original patch seems empty"); last->num_lines = linenum - last->line_in_diff + 1; /* Run diff between original and edited. */ t = xpipe (DIFF, &child, "r", DIFF, "-U0", original, edited, NULL); m = xtmpfile (); if (m) { size_t buffer_size = 10000; char *buffer = xmalloc (buffer_size); while (!feof (t)) { size_t got = fread (buffer, 1, buffer_size, t); fwrite (buffer, 1, got, m); } fclose (t); waitpid (child, NULL, 0); rewind (m); free (buffer); } else error (EXIT_FAILURE, errno, "Couldn't create temporary file"); /* For each hunk in m, identify which hunk in o has been * touched. Display unmodified hunks before that one * (adjusting offsets), then step through the touched hunk * applying changes as necessary. */ *line = '\0'; while (!feof (m)) { unsigned long orig_line; unsigned long orig_count; struct hunk *which; fpos_t pos; while (strncmp (line, "@@ ", 3)) { fgetpos (m, &pos); if (getline (&line, &linelen, m) == -1) break; } if (feof (m)) break; read_atatline (line, &orig_line, &orig_count, NULL, NULL); if (!orig_count) orig_line++; /* Find out which hunk that is. */ for (which = hunks; which; which = which->next) { int header; if (!which->next) { /* Last one; this must be it. */ break; } header = which->next->info ? 2 : 0; if (which->next->line_in_diff + header > orig_line) /* Next one is past that point. */ break; } assert (which); if (which->line_in_diff + which->num_lines <= orig_line) which->discard_offset = 1; #ifdef DEBUG fprintf (stderr, "Modified hunk starts on line %lu\n", which->line_in_diff); if (which->discard_offset) fprintf (stderr, "(But discarding offset)\n"); #endif /* DEBUG */ /* If this is modifying a new hunk, we need to write * out what we had and all the intervening hunks, * adjusting offsets as we go. */ if (current_hunk != which) { if (current_hunk) { line_offset += show_modified_hunk (¤t_hunk, line_offset, t, o, out); current_hunk = current_hunk->next; } /* Copy hunks, adjusting offsets. */ copy_to (current_hunk ? current_hunk : hunks, which, &line_offset, o, out, current_hunk == NULL); /* This meta hunk is the first pertaining to * the hunk in the original. */ t = xtmpfile (); } current_hunk = which; /* Append the meta hunk to a temporary file. */ fputs (line, t); while (!feof (m)) { if (getline (&line, &linelen, m) == -1) break; if (!strncmp (line, "@@ ", 3)) break; fputs (line, t); } } /* Now display the remaining hunks, adjusting offsets. */ if (current_hunk) { line_offset += show_modified_hunk (¤t_hunk, line_offset, t, o, out); current_hunk = current_hunk->next; if (current_hunk) copy_to (current_hunk, NULL, &line_offset, o, out, 0); } else copy_to (hunks, NULL, &line_offset, o, out, 1); fclose (o); fclose (m); if (line) free (line); return 0; } static char * syntax_str = "usage: %s ORIGINAL EDITED\n" " %s EDITED\n"; NORETURN static void syntax (int err) { fprintf (err ? stderr : stdout, syntax_str, progname, progname); exit (err); } int main (int argc, char *argv[]) { /* name to use in error messages */ set_progname ("rediff"); while (1) { static struct option long_options[] = { {"help", 0, 0, 'h'}, {"version", 0, 0, 'v'}, {0, 0, 0, 0} }; int c = getopt_long (argc, argv, "vh", long_options, NULL); if (c == -1) break; switch (c) { case 'v': printf("rediff - patchutils version %s\n", VERSION); exit(0); case 'h': syntax (0); break; default: syntax(1); } } if (argc - optind < 1) syntax (1); if (argc - optind == 1) { char *p = xmalloc (strlen (argv[0]) + strlen ("recountdiff") + 1); char *f; char **const new_argv = xmalloc (sizeof (char *) * (argc + 1)); memcpy (new_argv, argv, sizeof (char *) * (argc + 1)); new_argv[0] = p; strcpy (p, argv[0]); f = strrchr (p, '/'); if (!f) f = p; else f++; strcpy (f, "recountdiff"); execvp (new_argv[0], new_argv); p = xstrdup (new_argv[0]); f = strstr (p, "src/"); if (f) { while (*(f + 4)) { *f = *(f + 4); f++; } *f = '\0'; new_argv[0] = p; execv (new_argv[0], new_argv); } error (EXIT_FAILURE, 0, "couldn't execute recountdiff"); } if (access (argv[optind + 1], R_OK)) error (EXIT_FAILURE, errno, "can't read edited file"); return rediff (argv[optind], argv[optind + 1], stdout); } patchutils-0.4.2/src/util.c000066400000000000000000000164151370426545100156230ustar00rootroot00000000000000/* * interdiff - create incremental patch between two against a common source * * Utility functions. * Copyright (C) 2001 Marko Kreen * Copyright (C) 2001, 2003, 2009, 2011 Tim Waugh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #ifdef HAVE_ERROR_H # include #endif /* HAVE_ERROR_H */ #include #include #include #include #include #include #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ #include #ifdef HAVE_SYS_TYPES_H # include #endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_SYS_WAIT_H # include #endif /* HAVE_SYS_WAIT_H */ #include "util.h" /* safe malloc */ void *xmalloc (size_t size) { void *res = malloc(size); if (!res) error (EXIT_FAILURE, errno, "malloc"); return res; } void *xrealloc (void *ptr, size_t size) { void *res = realloc (ptr, size); if (!res) error (EXIT_FAILURE, errno, "realloc"); return res; } /* safe strdup */ char *xstrdup (const char *s) { size_t len = strlen (s) + 1; char *result = xmalloc (len); memcpy (result, s, len); return result; } /* only copy the first n characters of s */ char *xstrndup (const char *s, const size_t n) { char *result; result = xmalloc(n + 1); strncpy(result, s, n); result[n] = '\0'; return result; } int xmkstemp (char *pattern) { int fd = mkstemp (pattern); if (fd < 0) error (EXIT_FAILURE, errno, "mkstemp: %s", pattern); return fd; } FILE *xtmpfile (void) { FILE *ret; char *tmpfname; char *tmpdir = getenv ("TMPDIR"); size_t tmpdirlen; int fd; if (tmpdir == NULL || !strcmp (tmpdir, P_tmpdir)) return tmpfile (); tmpdirlen = strlen (tmpdir); tmpfname = xmalloc (tmpdirlen + 8); strcpy (tmpfname, tmpdir); strcpy (tmpfname + tmpdirlen, "/XXXXXX"); fd = mkstemp (tmpfname); ret = fdopen (fd, "w+b"); if (ret == NULL) error (EXIT_FAILURE, errno, "fdopen"); unlink (tmpfname); free (tmpfname); return ret; } /* * Pattern operations. */ /* list of patterns */ struct patlist { struct patlist *next; char *pattern; }; void patlist_add(struct patlist **dst, const char *s) { struct patlist *item = xmalloc (sizeof *item); item->pattern = xstrdup (s); item->next = *dst; *dst = item; } void patlist_add_file(struct patlist **dst, const char *fn) { FILE *fd; char *line = NULL; size_t linelen = 0; size_t len; fd = fopen (fn, "r"); if (NULL == fd) return; while ((len = getline (&line, &linelen, fd)) != -1) { if (len < 1) /* Shouldn't really happen */ continue; /* Remove '\n' from pattern */ if ('\n' == line[len - 1]) { if (len == 1) /* only '\n' present */ continue; line[len - 1] = '\0'; } patlist_add (dst, line); } fclose (fd); } int patlist_match(struct patlist *list, const char *s) { while (list) { if (!fnmatch (list->pattern, s, 0)) return 1; list = list->next; } return 0; } void patlist_free(struct patlist **list) { struct patlist *l, *next; for (l = *list; l; l = next) { next = l->next; free (l->pattern); free (l); } *list = NULL; } FILE *xopen (const char *name, const char *mode) { FILE *f; f = fopen(name, mode); if (!f) { perror(name); exit(1); } return f; } FILE *xopen_seekable (const char *name, const char *mode) { /* If it's seekable, good. If not, we need to make it seekable. */ FILE *f = xopen (name, mode); if (fseek (f, 0L, SEEK_SET) != 0) { const size_t buflen = 64 * 1024; char *buffer = xmalloc (buflen); FILE *tmp = xtmpfile(); while (!feof (f)) { size_t count = fread (buffer, 1, buflen, f); if (count < 1) break; fwrite (buffer, count, 1, tmp); } free (buffer); fclose (f); f = tmp; fseek (f, 0L, SEEK_SET); } return f; } /* unzip if needed */ FILE *xopen_unzip (const char *name, const char *mode) { char *p, *zprog = NULL; FILE *fi, *fo; const size_t buflen = 64 * 1024; char *buffer; pid_t pid; int status; int any_data = 0; p = strrchr(name, '.'); if (p != NULL) { if (!strcmp (p, ".bz2")) zprog = "bzcat"; else if (!strcmp(p, ".gz")) zprog = "zcat"; } if (zprog == NULL) return xopen_seekable (name, mode); buffer = xmalloc (buflen); fo = xtmpfile(); fi = xpipe(zprog, &pid, "r", zprog, name, NULL); while (!feof (fi)) { size_t count = fread (buffer, 1, buflen, fi); if (ferror (fi)) { perror(name); exit(1); } if (count < 1) break; fwrite (buffer, count, 1, fo); if (ferror (fo)) error (EXIT_FAILURE, errno, "writing temp file"); any_data = 1; } free (buffer); fclose (fi); waitpid (pid, &status, 0); if (any_data == 0 && WEXITSTATUS (status) != 0) { fclose (fo); exit (1); } fseek (fo, 0L, SEEK_SET); return fo; } /* safe pipe/popen. mode is either "r" or "w" */ FILE * xpipe(const char * cmd, pid_t *pid, const char *mode, ...) { va_list ap; int fildes[2]; int child; int nargs = 0; char *argv[128], *arg; FILE *res; if (!mode || (*mode != 'r' && *mode != 'w')) error (EXIT_FAILURE, 0, "xpipe: bad mode: %s", mode); va_start(ap, mode); do { arg = va_arg(ap, char *); argv[nargs++] = arg; if (nargs >= 128) error (EXIT_FAILURE, 0, "xpipe: too many args"); } while (arg != NULL); va_end(ap); fflush (NULL); pipe (fildes); child = fork (); if (child == -1) { perror ("fork"); exit (1); } if (child == 0) { if (*mode == 'r') { close (fildes[0]); close (1); dup (fildes[1]); close (fildes[1]); } else { close (fildes[1]); close (1); dup(2); close (0); dup (fildes[0]); close (fildes[0]); } execvp (cmd, argv); /* Shouldn't get here */ error (EXIT_FAILURE, errno, "execvp"); } if (pid != NULL) *pid = child; if (*mode == 'r') { close (fildes[1]); res = fdopen (fildes[0], "r"); } else { close (fildes[0]); res = fdopen (fildes[1], "w"); } if (res == NULL) error (EXIT_FAILURE, errno, "fdopen"); return res; } /* * stuff needed for non-GNU systems */ #ifndef HAVE_GETLINE #define GLSTEP 512 /* suboptimal implementation of glibc's getline() */ ssize_t getline(char **line, size_t *n, FILE *f) { char *p; size_t len; if (*line == NULL || *n < 2) { p = realloc(*line, GLSTEP); if (!p) return -1; *line = p; *n = GLSTEP; } p = fgets(*line, *n, f); if (!p) return -1; len = strlen(p); while ((*line)[len - 1] != '\n') { p = realloc(*line, *n + GLSTEP); if (!p) return -1; *line = p; *n += GLSTEP; p = fgets(p + len, *n - len, f); if (!p) break; len = len + strlen(p); } return (ssize_t) len; } #endif char *progname = "(null)"; /* for error() */ void set_progname(const char *s) { progname = xstrdup(s); } patchutils-0.4.2/src/util.h000066400000000000000000000045351370426545100156300ustar00rootroot00000000000000/* * interdiff - create incremental patch between two against a common source * * Utility functions. * Copyright (C) 2001 Marko Kreen * Copyright (C) 2001, 2003, 2009 Tim Waugh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ /* GCC attributes */ #if !defined(__GNUC__) || __GNUC__ < 2 || \ (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ # define NORETURN # define FORMAT(x) #else /* GNU C: */ # define NORETURN __attribute__ ((__noreturn__)) # define FORMAT(x) __attribute__ ((__format__ x)) #endif /* safe malloc */ void *xmalloc (size_t size); void *xrealloc (void *tr, size_t size); /* safe strdup */ char *xstrdup (const char *s); /* safe strndup */ char *xstrndup (const char *s, const size_t n); /* safe mkstemp */ int xmkstemp (char *pattern); /* safe tmpfile */ FILE *xtmpfile (void); FILE *xopen(const char *file, const char *mode); FILE *xopen_seekable(const char *file, const char *mode); FILE *xopen_unzip(const char *file, const char *mode); FILE *xpipe(const char *cmd, pid_t *pid, const char *mode, ...); struct patlist; /* create a new item */ void patlist_add(struct patlist **dst, const char *s); /* load whole list from file */ void patlist_add_file(struct patlist **dst, const char *fn); /* match a string to all patterns */ int patlist_match(struct patlist *list, const char *s); /* free rxlist */ void patlist_free(struct patlist **list); extern char *progname; void set_progname(const char * s); /* for non-glibc systems */ #ifndef HAVE_GETLINE ssize_t getline(char **line, size_t *n, FILE *f); #endif #ifndef HAVE_ERROR extern void error (int status, int errnum, const char *format, ...) FORMAT ((__printf__, 3, 4)); #endif /* HAVE_ERROR */ patchutils-0.4.2/tests/000077500000000000000000000000001370426545100150465ustar00rootroot00000000000000patchutils-0.4.2/tests/U0/000077500000000000000000000000001370426545100153325ustar00rootroot00000000000000patchutils-0.4.2/tests/U0/run-test000077500000000000000000000010111370426545100170320ustar00rootroot00000000000000#!/bin/sh # # This is an interdiff(1) test case. # Test: -U0 works correctly. . ${top_srcdir-.}/tests/common.sh >file.orig cat << EOF > file add some stuff to the file which was empty EOF ${DIFF} -u file.orig file > patch1 cp file after-patch1 cat << EOF > file add some lines to the beginning of the file add some stuff to the file which was empty EOF ${DIFF} -u file.orig file > patch2 ${INTERDIFF} -U0 patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 ${PATCH} after-patch1 < patch1-2 || exit 1 patchutils-0.4.2/tests/U3/000077500000000000000000000000001370426545100153355ustar00rootroot00000000000000patchutils-0.4.2/tests/U3/run-test000077500000000000000000000010211370426545100170360ustar00rootroot00000000000000#!/bin/sh # # This is an interdiff(1) test case. # Test: -U3 works correctly. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig one two three EOF cat << EOF > file one two three add some stuff to the file which had 3 lines EOF ${DIFF} -U0 file.orig file > patch ${INTERDIFF} -U3 /dev/null patch 2>errors > interdiffed || exit 1 [ -s errors ] && exit 1 # Should be four lines beginning '+' (one in the header) count=$(grep '^+' interdiffed | wc -l) [ "$count" -eq 4 ] || exit 1 grep -q '^ ' interdiffed && exit 1 exit 0 patchutils-0.4.2/tests/U5/000077500000000000000000000000001370426545100153375ustar00rootroot00000000000000patchutils-0.4.2/tests/U5/run-test000077500000000000000000000012171370426545100170470ustar00rootroot00000000000000#!/bin/sh # # This is an interdiff(1) test case. # Test: -U5 works correctly. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig one two three four five six seven eight nine ten eleven twelve EOF cat << EOF > file one two three four five six add some stuff to the file which had 3 lines seven eight nine ten eleven twelve EOF ${DIFF} -U99 file.orig file > patch ${INTERDIFF} -U5 /dev/null patch 2>errors > interdiffed || exit 1 [ -s errors ] && exit 1 # Should be 5 context lines before and after grep -q one interdiffed && exit 1 grep -q two interdiffed || exit 1 grep -q eleven interdiffed || exit 1 grep -q twelve interdiffed && exit 1 exit 0 patchutils-0.4.2/tests/addhunk1/000077500000000000000000000000001370426545100165455ustar00rootroot00000000000000patchutils-0.4.2/tests/addhunk1/run-test000077500000000000000000000012201370426545100202470ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Add a hunk, filling in missing offsets and counts. . ${top_srcdir-.}/tests/common.sh cat << EOF > original-patch --- file.orig +++ file @@ -6,7 +6,7 @@ blah blah blah -not +important blah blah blah EOF cat original-patch - << EOF > edited-patch @@ -37 blah blah blah +blah blah blah blah EOF ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -6,7 +6,7 @@ blah blah blah -not +important blah blah blah @@ -37,6 +37,7 @@ blah blah blah +blah blah blah blah EOF patchutils-0.4.2/tests/addhunk2/000077500000000000000000000000001370426545100165465ustar00rootroot00000000000000patchutils-0.4.2/tests/addhunk2/run-test000077500000000000000000000011741370426545100202600ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Add a hunk. . ${top_srcdir-.}/tests/common.sh cat << EOF > original-patch --- file.orig +++ file @@ -37,7 +37,7 @@ blah blah blah -not +important blah blah blah EOF cat << EOF > edited-patch --- file.orig +++ file @@ -6,1 +5,0 @@ -no blah @@ -37,7 +37,7 @@ blah blah blah -not +important blah blah blah EOF ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -6 +5,0 @@ -no blah @@ -37,7 +36,7 @@ blah blah blah -not +important blah blah blah EOF patchutils-0.4.2/tests/addhunk3/000077500000000000000000000000001370426545100165475ustar00rootroot00000000000000patchutils-0.4.2/tests/addhunk3/run-test000077500000000000000000000014701370426545100202600ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Add a hunk at the end of a patch but before another. . ${top_srcdir-.}/tests/common.sh cat << EOF > original-patch --- file.orig +++ file @@ -6,7 +6,7 @@ blah blah blah -not +important blah blah blah --- otherfile.orig +++ otherfile @@ -1 +1 @@ -a +A EOF cat << EOF > edited-patch --- file.orig +++ file @@ -6,7 +6,7 @@ blah blah blah -not +important blah blah blah @@ -36 +36 @@ -old +new --- otherfile.orig +++ otherfile @@ -1 +1 @@ -a +A EOF ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -6,7 +6,7 @@ blah blah blah -not +important blah blah blah @@ -36 +36 @@ -old +new --- otherfile.orig +++ otherfile @@ -1 +1 @@ -a +A EOF patchutils-0.4.2/tests/apply1/000077500000000000000000000000001370426545100162545ustar00rootroot00000000000000patchutils-0.4.2/tests/apply1/run-test000077500000000000000000000004011370426545100177560ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir cat << EOF > dir/file.orig a b -- EOF cat << EOF > dir/file a b EOF ${DIFF} -u dir/file.orig dir/file > patch1 ${INTERDIFF} patch1 patch1 2>errors > patch1-1 || exit 1 [ -s errors ] && exit 1 exit 0 patchutils-0.4.2/tests/broken1/000077500000000000000000000000001370426545100164075ustar00rootroot00000000000000patchutils-0.4.2/tests/broken1/run-test000077500000000000000000000004401370426545100201140ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh cat << EOF > broken_patch --- file +++ file @@ -1,0 +1,0 @@ \ No newline at end of file EOF ${INTERDIFF} broken_patch broken_patch 2>errors >output && exit 1 [ -z errors ] && exit 1 [ -z `cat output` ] || exit 1 [ -f core ] && exit 1 exit 0 patchutils-0.4.2/tests/clean1/000077500000000000000000000000001370426545100162115ustar00rootroot00000000000000patchutils-0.4.2/tests/clean1/run-test000077500000000000000000000010271370426545100177200ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Use --clean in filter mode. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff non-diff line --- a/file1 +++ b/file1 @@ -0,0 +1 @@ +a EOF ${FILTERDIFF} --clean diff 2>errors >filtered || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - filtered || exit 1 --- a/file1 +++ b/file1 @@ -0,0 +1 @@ +a EOF ${FILTERDIFF} --clean -x file1 diff 2>errors >filtered || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - filtered || exit 1 --- a/file1 +++ b/file1 @@ -0,0 +1 @@ +a EOF patchutils-0.4.2/tests/clean2/000077500000000000000000000000001370426545100162125ustar00rootroot00000000000000patchutils-0.4.2/tests/clean2/run-test000077500000000000000000000011071370426545100177200ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Make sure --clean removes hunk-level comments. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff non-diff line --- a/file1 +++ b/file1 @@ -0,0 +1 @@ this is a hunk-level comment +a EOF ${FILTERDIFF} --clean diff 2>errors >filtered || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - filtered || exit 1 --- a/file1 +++ b/file1 @@ -0,0 +1 @@ +a EOF ${FILTERDIFF} --clean -x file1 diff 2>errors >filtered || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - filtered || exit 1 --- a/file1 +++ b/file1 @@ -0,0 +1 @@ +a EOF patchutils-0.4.2/tests/combine1/000077500000000000000000000000001370426545100165435ustar00rootroot00000000000000patchutils-0.4.2/tests/combine1/run-test000077500000000000000000000011421370426545100202500ustar00rootroot00000000000000#!/bin/sh # This is a combinediff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c d e f g h i j k l m n o p q r s t u v w x y z EOF cp file.orig file.a-z cat << EOF > file b c d e f g h i j k l n o p q r s t u v w x y EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file b c one d e f g h i j k l two n o p q r s t u v w x three y EOF ${DIFF} -u file.orig file > patch2 ${COMBINEDIFF} patch1 patch2 2>errors >patches || exit 1 [ -s errors ] && exit 1 # There should be no fuzz. patch file.a-z < patches >fuzz || exit 1 [ -s errors ] && exit 1 exit 0 patchutils-0.4.2/tests/combine2/000077500000000000000000000000001370426545100165445ustar00rootroot00000000000000patchutils-0.4.2/tests/combine2/run-test000077500000000000000000000010461370426545100202540ustar00rootroot00000000000000#!/bin/bash # This is a combinediff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- file.orig +++ file @@ -1 +1 @@ -a +b --- otherfile.orig +++ otherfile @@ -1,2 +1 @@ -a -b +A @@ -3 +2,2 @@ -c +B +C EOF cat << EOF > patch2 --- file.orig +++ file @@ -1 +1 @@ -b +c EOF ${COMBINEDIFF} patch1 patch2 2>errors >patches || exit 1 [ -s errors ] && exit 1 echo a > file (echo a; echo b; echo c) > otherfile ${PATCH} < patches || exit 1 echo c > c cmp file c || exit 1 (echo A; echo B; echo C) > abc cmp otherfile abc || exit 1 patchutils-0.4.2/tests/combine3/000077500000000000000000000000001370426545100165455ustar00rootroot00000000000000patchutils-0.4.2/tests/combine3/run-test000077500000000000000000000010461370426545100202550ustar00rootroot00000000000000#!/bin/bash # This is a combinediff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- otherfile.orig +++ otherfile @@ -1,2 +1 @@ -a -b +A @@ -3 +2,2 @@ -c +B +C --- file.orig +++ file @@ -1 +1 @@ -a +b EOF cat << EOF > patch2 --- file.orig +++ file @@ -1 +1 @@ -b +c EOF ${COMBINEDIFF} patch1 patch2 2>errors >patches || exit 1 [ -s errors ] && exit 1 echo a > file (echo a; echo b; echo c) > otherfile ${PATCH} < patches || exit 1 echo c > c cmp file c || exit 1 (echo A; echo B; echo C) > abc cmp otherfile abc || exit 1 patchutils-0.4.2/tests/comma/000077500000000000000000000000001370426545100161425ustar00rootroot00000000000000patchutils-0.4.2/tests/comma/run-test000077500000000000000000000007061370426545100176540ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir cat << EOF > dir/file.orig a EOF cat << EOF > dir/file 1 2 3 EOF cat << EOF > dir/xyzzy.orig a b c EOF cat << EOF > dir/xyzzy a b d EOF # "gendiff dir .orig", but without requiring gendiff: ( for f in file xyzzy do printf "diff -up dir/$f.orig dir/$f\n" diff -up dir/$f.orig dir/$f done) > patch1 ${INTERDIFF} patch1 patch1 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 exit 0 patchutils-0.4.2/tests/common.sh000066400000000000000000000014221370426545100166710ustar00rootroot00000000000000[ -n "$VERBOSE" ] && set -x ${ARENA:=test-arena} THISDIR=$(dirname $0) ARENA=${ARENA}/${THISDIR##*/} rm -rf $ARENA mkdir -p $ARENA top_builddir=`cd ${top_builddir-.}; pwd` INTERDIFF=${top_builddir}/src/interdiff REDIFF=${top_builddir}/src/rediff COMBINEDIFF=${top_builddir}/src/combinediff FLIPDIFF=${top_builddir}/src/flipdiff LSDIFF=${top_builddir}/src/lsdiff PATCHVIEW=${top_builddir}/src/patchview GREPDIFF=${top_builddir}/src/grepdiff FILTERDIFF=${top_builddir}/src/filterdiff SELECTDIFF=${top_builddir}/src/selectdiff RECOUNTDIFF=${top_builddir}/scripts/recountdiff UNWRAPDIFF=${top_builddir}/scripts/unwrapdiff SPLITDIFF=${top_builddir}/scripts/splitdiff export LSDIFF : ${DIFF:=diff} : ${PATCH:=patch -s} cd $ARENA if [ -n "$LxINENO" ]; then export PS4='[$LINENO] ' fi set -x patchutils-0.4.2/tests/context1/000077500000000000000000000000001370426545100166135ustar00rootroot00000000000000patchutils-0.4.2/tests/context1/run-test000077500000000000000000000012341370426545100203220ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Context format, to-omission check. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 *** file.orig --- file *************** *** 2,8 **** b c } - return 0; d e f --- 2,7 ---- EOF ${FILTERDIFF} patch1-filtered 2>errors || exit 1 [ -s errors ] && exit 1 cmp patch1 patch1-filtered || exit 1 cat << EOF > patch2 *** file.orig --- file *************** *** 1,8 **** a b c } - return 0; d e f --- 1,8 ---- a b c + return -ENOSYS; } d e f EOF ${FILTERDIFF} patch2-filtered 2>errors || exit 1 [ -s errors ] && exit 1 cmp patch2 patch2-filtered || exit 1 patchutils-0.4.2/tests/convert1/000077500000000000000000000000001370426545100166075ustar00rootroot00000000000000patchutils-0.4.2/tests/convert1/run-test000077500000000000000000000010231370426545100203120ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Convert context to unified. . ${top_srcdir-.}/tests/common.sh mkdir dir.orig dir cat < dir.orig/a a b c EOF cat < dir.orig/b b c d EOF cat < dir/a a B c EOF cat < dir/b b C d EOF ${DIFF} -rc dir.orig dir > cdiff ${FILTERDIFF} --format=unified cdiff 2>errors > diff || exit 1 [ -s errors ] && exit 1 cd dir.orig ${PATCH} -p1 -i ../diff 2>errors || exit 1 [ -s errors ] && exit 1 cmp a - < dir.orig/a a b c . . . . . . . c b a EOF cat < dir.orig/b b c d EOF cat < dir/a a B c . . . . . . . c B a EOF cat < dir/b b C d EOF ${DIFF} -ru dir.orig dir > cdiff ${FILTERDIFF} --format=context cdiff 2>errors > diff || exit 1 [ -s errors ] && exit 1 cd dir.orig ${PATCH} -p1 -i ../diff 2>errors || exit 1 [ -s errors ] && exit 1 cmp a - < dir/file.orig a b -- EOF cat << EOF > dir/file a b EOF ${DIFF} -u dir/file.orig dir/file > patch1 ${INTERDIFF} /dev/null patch1 2>errors > patch-1 || exit 1 [ -s errors ] && exit 1 tail -1 patch-1 > lastline cat << EOF | cmp - lastline || exit 1 --- EOF patchutils-0.4.2/tests/create1/000077500000000000000000000000001370426545100163725ustar00rootroot00000000000000patchutils-0.4.2/tests/create1/run-test000077500000000000000000000024411370426545100201020ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh cat << EOF > orig a b c EOF cat << EOF > new1 a b EOF cat << EOF > new2 c a b EOF mkdir orig.dir new1.dir new2.dir cat << EOF > orig.dir/file a EOF cat << EOF > new1.dir/file b EOF cp new1 start ${DIFF} -u orig new1 > patch1 ${DIFF} -u orig new2 > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 ${PATCH} < patch1-2 || exit 1 cmp new1 new2 || exit 1 ${PATCH} -R < patch1-2 cmp new1 start || exit 1 cp new1 new4 cp new2 new3 cp new3 start ${DIFF} -u orig new3 > patch3 ${DIFF} -u orig new4 > patch4 ${INTERDIFF} patch3 patch4 2>errors > patch3-4 || exit 1 [ -s errors ] && exit 1 ${PATCH} < patch3-4 || exit 1 cmp new3 new4 || exit 1 ${PATCH} -R < patch3-4 cmp new3 start || exit 1 ${DIFF} -urN orig.dir new1.dir > patch5 ${DIFF} -urN orig.dir new2.dir > patch6 ${INTERDIFF} patch5 patch6 2>errors > patch5-6 || exit 1 [ -s errors ] && exit 1 ${INTERDIFF} patch6 patch5 2>errors > patch6-5 || exit 1 [ -s errors ] && exit 1 cd new1.dir ${PATCH} -p1 < ../patch5-6 || exit 1 cd .. ${DIFF} -urN new1.dir new2.dir || exit 1 cd new1.dir ${PATCH} -Rp1 < ../patch5-6 || exit 1 cd ../new2.dir ${PATCH} -p1 < ../patch6-5 || exit 1 cd .. ${DIFF} -urN new1.dir new2.dir || exit 1 cd new2.dir ${PATCH} -Rp1 < ../patch6-5 || exit 1 cd .. patchutils-0.4.2/tests/dashes/000077500000000000000000000000001370426545100163155ustar00rootroot00000000000000patchutils-0.4.2/tests/dashes/run-test000077500000000000000000000012421370426545100200230ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh cat << EOF > orig -- EOF cat << EOF > new1 ++ EOF cat << EOF > new2 b EOF cp new1 start ${DIFF} -u orig new1 > patch1 ${DIFF} -u orig new2 > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 ${PATCH} < patch1-2 || exit 1 cmp new1 new2 || exit 1 ${PATCH} -R < patch1-2 cmp new1 start || exit 1 mv new1 tmp mv new2 new1 mv tmp new2 cp new1 start ${DIFF} -u orig new1 > patch3 ${DIFF} -u orig new2 > patch4 ${INTERDIFF} patch3 patch4 2>errors > patch3-4 || exit 1 [ -s errors ] && exit 1 ${PATCH} < patch3-4 || exit 1 cmp new1 new2 || exit 1 ${PATCH} -R < patch3-4 cmp new1 start || exit 1 patchutils-0.4.2/tests/dashes1/000077500000000000000000000000001370426545100163765ustar00rootroot00000000000000patchutils-0.4.2/tests/dashes1/run-test000077500000000000000000000016271370426545100201130ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir cat << EOF > dir/file.orig -- EOF cat << EOF > new1 -- EOF cat << EOF > new2 b EOF cp new1 dir/file ${DIFF} -u dir/file.orig dir/file > patch1 cp new2 dir/file ${DIFF} -u dir/file.orig dir/file > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 mkdir test cp new1 test/file cd test ${PATCH} < ../patch1-2 || exit 1 cd .. cmp new2 test/file || exit 1 cd test ${PATCH} -R < ../patch1-2 cd .. cmp new1 test/file || exit 1 mv new1 tmp mv new2 new1 mv tmp new2 cp new1 dir/file ${DIFF} -u dir/file.orig dir/file > patch3 cp new2 dir/file ${DIFF} -u dir/file.orig dir/file > patch4 ${INTERDIFF} patch3 patch4 2>errors > patch3-4 || exit 1 [ -s errors ] && exit 1 cp new1 test/file cd test ${PATCH} < ../patch3-4 || exit 1 cd .. cmp new2 test/file || exit 1 cd test ${PATCH} -R < ../patch3-4 cd .. cmp new1 test/file || exit 1 patchutils-0.4.2/tests/dashes2/000077500000000000000000000000001370426545100163775ustar00rootroot00000000000000patchutils-0.4.2/tests/dashes2/run-test000077500000000000000000000016271370426545100201140ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir cat << EOF > dir/file.orig -- EOF cat << EOF > new1 a EOF cat << EOF > new2 -- EOF cp new1 dir/file ${DIFF} -u dir/file.orig dir/file > patch1 cp new2 dir/file ${DIFF} -u dir/file.orig dir/file > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 mkdir test cp new1 test/file cd test ${PATCH} < ../patch1-2 || exit 1 cd .. cmp new2 test/file || exit 1 cd test ${PATCH} -R < ../patch1-2 cd .. cmp new1 test/file || exit 1 mv new1 tmp mv new2 new1 mv tmp new2 cp new1 dir/file ${DIFF} -u dir/file.orig dir/file > patch3 cp new2 dir/file ${DIFF} -u dir/file.orig dir/file > patch4 ${INTERDIFF} patch3 patch4 2>errors > patch3-4 || exit 1 [ -s errors ] && exit 1 cp new1 test/file cd test ${PATCH} < ../patch3-4 || exit 1 cd .. cmp new2 test/file || exit 1 cd test ${PATCH} -R < ../patch3-4 cd .. cmp new1 test/file || exit 1 patchutils-0.4.2/tests/dashes3/000077500000000000000000000000001370426545100164005ustar00rootroot00000000000000patchutils-0.4.2/tests/dashes3/run-test000077500000000000000000000007701370426545100201130ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir cat << EOF > dir/file.orig -- EOF cat << EOF > new1 -- EOF cat << EOF > new2 b EOF cp new1 dir/file ${DIFF} -u dir/file.orig dir/file > patch1 mkdir dir.modified mv dir/file.orig dir/file cp new2 dir.modified/file cp new1 dir.modified/xxx ${DIFF} -urN dir dir.modified > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 cd dir ${PATCH} < ../patch1-2 || exit 1 cd .. ${DIFF} -urN dir dir.modified || exit 1 patchutils-0.4.2/tests/dashes4/000077500000000000000000000000001370426545100164015ustar00rootroot00000000000000patchutils-0.4.2/tests/dashes4/run-test000077500000000000000000000011601370426545100201060ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir cat << EOF > dir/file.orig -- foo bar baz bing bong bang crash wallop EOF cat << EOF > new1 -- foo bar baz bing bong bang crash wallop EOF cat << EOF > new2 b foo bar baz bing bong bang crash wallop thump EOF cp new1 dir/file ${DIFF} -u dir/file.orig dir/file > patch1 mkdir dir.modified mv dir/file.orig dir/file cp new2 dir.modified/file ${DIFF} -urN dir dir.modified > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 mkdir test cp new1 test/file cd test ${PATCH} < ../patch1-2 || exit 1 cd .. cmp new2 test/file || exit 1 patchutils-0.4.2/tests/delhunk1/000077500000000000000000000000001370426545100165615ustar00rootroot00000000000000patchutils-0.4.2/tests/delhunk1/run-test000077500000000000000000000011601370426545100202660ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Remove a hunk. . ${top_srcdir-.}/tests/common.sh cat << EOF > edited-patch --- file.orig +++ file @@ -37,6 +38,7 @@ blah blah blah +blah blah blah blah EOF cat << EOF > original-patch --- file.orig +++ file @@ -6,6 +6,7 @@ blah blah blah +important blah blah blah @@ -37,6 +38,7 @@ blah blah blah +blah blah blah blah EOF ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -37,6 +37,7 @@ blah blah blah +blah blah blah blah EOF patchutils-0.4.2/tests/delhunk2/000077500000000000000000000000001370426545100165625ustar00rootroot00000000000000patchutils-0.4.2/tests/delhunk2/run-test000077500000000000000000000010711370426545100202700ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Remove a hunk. . ${top_srcdir-.}/tests/common.sh cat << EOF > edited-patch --- file.orig +++ file @@ -6,7 +6,7 @@ blah blah blah -not +important blah blah blah EOF cat edited-patch - << EOF > original-patch @@ -37,6 +37,7 @@ blah blah blah +blah blah blah blah EOF ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -6,7 +6,7 @@ blah blah blah -not +important blah blah blah EOF patchutils-0.4.2/tests/delhunk3/000077500000000000000000000000001370426545100165635ustar00rootroot00000000000000patchutils-0.4.2/tests/delhunk3/run-test000077500000000000000000000007241370426545100202750ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Remove two consecutive hunks. . ${top_srcdir-.}/tests/common.sh cat << EOF > edited-patch --- file.orig +++ file @@ -10 +10 @@ -a +b EOF cat edited-patch - << EOF > original-patch @@ -20 +20 @@ -a +b @@ -30 +30 @@ -a +b EOF ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -10 +10 @@ -a +b EOF patchutils-0.4.2/tests/delhunk4/000077500000000000000000000000001370426545100165645ustar00rootroot00000000000000patchutils-0.4.2/tests/delhunk4/run-test000077500000000000000000000007601370426545100202760ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Remove two consecutive hunks. . ${top_srcdir-.}/tests/common.sh cat << EOF > original-patch --- file.orig +++ file @@ -10 +10 @@ -a +b @@ -20 +20 @@ -a +b @@ -30 +30 @@ -a +b EOF cat << EOF > edited-patch --- file.orig +++ file @@ -30 +30 @@ -a +b EOF ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -30 +30 @@ -a +b EOF patchutils-0.4.2/tests/delhunk5/000077500000000000000000000000001370426545100165655ustar00rootroot00000000000000patchutils-0.4.2/tests/delhunk5/run-test000077500000000000000000000007721370426545100203020ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Remove one hunk and edit the offset banner of the next. . ${top_srcdir-.}/tests/common.sh cat << EOF > original-patch --- file.orig +++ file @@ -10 +10 @@ -a +b @@ -20 +20 @@ -a +b EOF cat << EOF > edited-patch --- file.orig +++ file @@ -25,1 +20,1 @@ -a +b EOF ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -25 +25 @@ -a +b EOF patchutils-0.4.2/tests/delhunk6/000077500000000000000000000000001370426545100165665ustar00rootroot00000000000000patchutils-0.4.2/tests/delhunk6/run-test000077500000000000000000000014611370426545100202770ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Remove one file completely. . ${top_srcdir-.}/tests/common.sh cat << EOF > original-patch diff -ur 1/a 2/a --- 1/a 2005-04-22 12:45:33.000000000 +0200 +++ 2/a 2005-04-22 12:45:48.000000000 +0200 @@ -1 +1 @@ -a +c diff -ur 1/b 2/b --- 1/b 2005-04-22 12:45:36.000000000 +0200 +++ 2/b 2005-04-22 12:45:49.000000000 +0200 @@ -1 +1 @@ -b +d EOF cat << EOF > edited-patch diff -ur 1/b 2/b --- 1/b 2005-04-22 12:45:36.000000000 +0200 +++ 2/b 2005-04-22 12:45:49.000000000 +0200 @@ -1 +1 @@ -b +d EOF ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 diff -ur 1/b 2/b --- 1/b 2005-04-22 12:45:36.000000000 +0200 +++ 2/b 2005-04-22 12:45:49.000000000 +0200 @@ -1 +1 @@ -b +d EOF patchutils-0.4.2/tests/edit1/000077500000000000000000000000001370426545100160545ustar00rootroot00000000000000patchutils-0.4.2/tests/edit1/run-test000077500000000000000000000007411370426545100175650ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Change the content of an added line. No offsets need changing. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a EOF cat << EOF > file b EOF ${DIFF} -u file.orig file > original-patch sed -e 's/^+b$/+c/' original-patch > edited-patch ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 # The rediffed patch should be the same. cmp edited-patch rediffed-patch || exit 1 patchutils-0.4.2/tests/edit10/000077500000000000000000000000001370426545100161345ustar00rootroot00000000000000patchutils-0.4.2/tests/edit10/run-test000077500000000000000000000016431370426545100176470ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Edit an offset only (should be minimally corrected). . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- file.orig +++ file @@ -1,5 +1,5 @@ blah -blah +blah blah blah blah EOF sed -e 's/5/6/g' patch > edited1 sed -e 's/1/2/' patch > edited2 sed -e 's/+1/+3/' patch > edited3 ${REDIFF} patch edited1 2>errors >rediffed1 || exit 1 [ -s errors ] && exit 1 ${REDIFF} patch edited2 2>errors >rediffed2 || exit 1 [ -s errors ] && exit 1 ${REDIFF} patch edited3 2>errors >rediffed3 || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed1 || exit 1 --- file.orig +++ file @@ -1,5 +1,5 @@ blah -blah +blah blah blah blah EOF cat << EOF | cmp - rediffed2 || exit 1 --- file.orig +++ file @@ -2,5 +2,5 @@ blah -blah +blah blah blah blah EOF cat << EOF | cmp - rediffed3 || exit 1 --- file.orig +++ file @@ -3,5 +3,5 @@ blah -blah +blah blah blah blah EOF patchutils-0.4.2/tests/edit2/000077500000000000000000000000001370426545100160555ustar00rootroot00000000000000patchutils-0.4.2/tests/edit2/run-test000077500000000000000000000007711370426545100175710ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Change a '-' to a ' ', and add a new line. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a EOF cat << EOF > file b EOF ${DIFF} -u file.orig file > original-patch sed -e 's/^-a$/ a/' original-patch > edited-patch cat << EOF >> edited-patch +c EOF ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 ${PATCH} file.orig < rediffed-patch || exit 1 cat << EOF | cmp - file.orig || exit 1 a b c EOF patchutils-0.4.2/tests/edit3/000077500000000000000000000000001370426545100160565ustar00rootroot00000000000000patchutils-0.4.2/tests/edit3/run-test000077500000000000000000000010271370426545100175650ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Change a ' ' to a '-' in the first of two hunks. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c d e f g h i j k l m EOF cat << EOF > file b c d e f g h i j k l EOF ${DIFF} -u file.orig file > original-patch sed -e 's/^ b$/-b/' original-patch > edited-patch ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 ${PATCH} file.orig < rediffed-patch || exit 1 cat << EOF | cmp - file.orig || exit 1 c d e f g h i j k l EOF patchutils-0.4.2/tests/edit4/000077500000000000000000000000001370426545100160575ustar00rootroot00000000000000patchutils-0.4.2/tests/edit4/run-test000077500000000000000000000010301370426545100175600ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Change a ' ' to a '-' in the second of two hunks. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c d e f g h i j k l m EOF cat << EOF > file b c d e f g h i j k l EOF ${DIFF} -u file.orig file > original-patch sed -e 's/^ l$/-l/' original-patch > edited-patch ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 ${PATCH} file.orig < rediffed-patch || exit 1 cat << EOF | cmp - file.orig || exit 1 b c d e f g h i j k EOF patchutils-0.4.2/tests/edit5/000077500000000000000000000000001370426545100160605ustar00rootroot00000000000000patchutils-0.4.2/tests/edit5/run-test000077500000000000000000000011651370426545100175720ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Make a change in the first of two files. . ${top_srcdir-.}/tests/common.sh mkdir dir.orig dir cat << EOF > dir.orig/file1 file1 EOF cat << EOF > dir.orig/file2 file2 EOF cat << EOF > dir/file1 IFLE1 EOF cat << EOF > dir/file2 FILE2 EOF ${DIFF} -u dir.orig dir > original-patch sed -e 's/^+IFLE1$/+FILE1/' original-patch > edited-patch ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cd dir.orig ${PATCH} < ../rediffed-patch || exit 1 cat << EOF | cmp - file1 || exit 1 FILE1 EOF cat << EOF | cmp - file2 || exit 1 FILE2 EOF patchutils-0.4.2/tests/edit6/000077500000000000000000000000001370426545100160615ustar00rootroot00000000000000patchutils-0.4.2/tests/edit6/run-test000077500000000000000000000011661370426545100175740ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Make a change in the second of two files. . ${top_srcdir-.}/tests/common.sh mkdir dir.orig dir cat << EOF > dir.orig/file1 file1 EOF cat << EOF > dir.orig/file2 file2 EOF cat << EOF > dir/file1 FILE1 EOF cat << EOF > dir/file2 IFLE2 EOF ${DIFF} -u dir.orig dir > original-patch sed -e 's/^+IFLE2$/+FILE2/' original-patch > edited-patch ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cd dir.orig ${PATCH} < ../rediffed-patch || exit 1 cat << EOF | cmp - file1 || exit 1 FILE1 EOF cat << EOF | cmp - file2 || exit 1 FILE2 EOF patchutils-0.4.2/tests/edit7/000077500000000000000000000000001370426545100160625ustar00rootroot00000000000000patchutils-0.4.2/tests/edit7/run-test000077500000000000000000000015321370426545100175720ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Pass through extra stuff. . ${top_srcdir-.}/tests/common.sh cat << EOF > original-patch This is the patch I want to apply: --- file.orig +++ file @@ -6,7 +6,7 blah blah blah -not +important blah blah blah Oh, and this one: --- unchanged.orig +++ unchanged @@ -37,6 +37,7 @@ blah blah blah +blah blah blah blah Okay? Hope so. EOF sed -e 's/-not$/+very/' original-patch > edited-patch ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 This is the patch I want to apply: --- file.orig +++ file @@ -6,6 +6,8 @@ blah blah blah +very +important blah blah blah Oh, and this one: --- unchanged.orig +++ unchanged @@ -37,6 +37,7 @@ blah blah blah +blah blah blah blah Okay? Hope so. EOF patchutils-0.4.2/tests/edit8/000077500000000000000000000000001370426545100160635ustar00rootroot00000000000000patchutils-0.4.2/tests/edit8/run-test000077500000000000000000000012421370426545100175710ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Remove an addition and check the subsequent offsets. . ${top_srcdir-.}/tests/common.sh cat << EOF > original-patch --- file.orig +++ file @@ -1,6 +1,8 @@ blah blah blah +Remove this line! +But not this one! blah blah blah @@ -100,3 +102,4 @@ blah blah blah -End of file EOF sed -e '/^+R/d' original-patch > edited-patch ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -1,6 +1,7 @@ blah blah blah +But not this one! blah blah blah @@ -100,3 +101,4 @@ blah blah blah -End of file EOF patchutils-0.4.2/tests/edit9/000077500000000000000000000000001370426545100160645ustar00rootroot00000000000000patchutils-0.4.2/tests/edit9/run-test000077500000000000000000000007711370426545100176000ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Remove an added line 1. . ${top_srcdir-.}/tests/common.sh cat << EOF > original-patch --- file.orig +++ file @@ -1,5 +1,6 @@ +Remove this line! blah -blah +blah blah blah blah EOF sed -e '/^+R/d' original-patch > edited-patch ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -1,5 +1,5 @@ blah -blah +blah blah blah blah EOF patchutils-0.4.2/tests/filterb/000077500000000000000000000000001370426545100164755ustar00rootroot00000000000000patchutils-0.4.2/tests/filterb/run-test000077500000000000000000000004721370426545100202070ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Handle binary diff chunk headers . ${top_srcdir-.}/tests/common.sh printf "\ --- a/file1 +++ b/file1 @@ -1 +1,2 @@ The '\0' (NUL) character a +b " >diff ${FILTERDIFF} diff 2>errors >filtered || exit 1 [ -s errors ] && exit 1 cmp diff filtered || exit 1 patchutils-0.4.2/tests/filterp/000077500000000000000000000000001370426545100165135ustar00rootroot00000000000000patchutils-0.4.2/tests/filterp/run-test000077500000000000000000000006271370426545100202270ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Use -p in filter mode. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- a/not-this/file1 +++ b/not-this/file1 @@ -0,0 +1 @@ +a --- a/file1 +++ b/file1 @@ -0,0 +1 @@ +a EOF ${FILTERDIFF} -p1 -i file1 diff 2>errors >filtered || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - filtered || exit 1 --- a/file1 +++ b/file1 @@ -0,0 +1 @@ +a EOF patchutils-0.4.2/tests/flip1/000077500000000000000000000000001370426545100160615ustar00rootroot00000000000000patchutils-0.4.2/tests/flip1/run-test000077500000000000000000000010321370426545100175640ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. # Test: Patch2 reduces to nothing after flip. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c EOF cat << EOF > file a d c EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file a c EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -1,3 +1,2 @@ a -b c === 8< === cut here === 8< === EOF patchutils-0.4.2/tests/flip10/000077500000000000000000000000001370426545100161415ustar00rootroot00000000000000patchutils-0.4.2/tests/flip10/run-test000077500000000000000000000011051370426545100176450ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- file.orig +++ file @@ -1 +1 @@ -a +A EOF cat << EOF > patch2 --- file.orig +++ file @@ -10 +10 @@ -a +A --- unrelated.orig +++ unrelated @@ -1 +1 @@ -a +A EOF ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -10 +10 @@ -a +A --- unrelated.orig +++ unrelated @@ -1 +1 @@ -a +A === 8< === cut here === 8< === --- file.orig +++ file @@ -1 +1 @@ -a +A EOF patchutils-0.4.2/tests/flip11/000077500000000000000000000000001370426545100161425ustar00rootroot00000000000000patchutils-0.4.2/tests/flip11/run-test000077500000000000000000000011051370426545100176460ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- file.orig +++ file @@ -1 +1 @@ -a +A --- unrelated.orig +++ unrelated @@ -1 +1 @@ -a +A EOF cat << EOF > patch2 --- file.orig +++ file @@ -10 +10 @@ -a +A EOF ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -10 +10 @@ -a +A === 8< === cut here === 8< === --- file.orig +++ file @@ -1 +1 @@ -a +A --- unrelated.orig +++ unrelated @@ -1 +1 @@ -a +A EOF patchutils-0.4.2/tests/flip12/000077500000000000000000000000001370426545100161435ustar00rootroot00000000000000patchutils-0.4.2/tests/flip12/run-test000077500000000000000000000021231370426545100176500ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 EOF cat << EOF > file 1 1 insert 2 3 4 5 6 7 8 9 modify 10 11 12 13 14 15 16 EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file 1 1 insert 2 3 4 5 6 add some lines 7 add some lines 7 add some lines 8 add some lines 9 add some lines 10 add some lines 11 add some lines 12 add some lines 13 add some lines 14 add some lines 6 7 8 9 modify 10 11 12 13 14 15 16 EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -3,6 +3,16 @@ 3 4 5 +6 add some lines +7 add some lines +7 add some lines +8 add some lines +9 add some lines +10 add some lines +11 add some lines +12 add some lines +13 add some lines +14 add some lines 6 7 8 === 8< === cut here === 8< === --- file.orig +++ file @@ -1,4 +1,5 @@ 1 +1 insert 2 3 4 @@ -16,7 +17,7 @@ 6 7 8 -9 +9 modify 10 11 12 EOF patchutils-0.4.2/tests/flip13/000077500000000000000000000000001370426545100161445ustar00rootroot00000000000000patchutils-0.4.2/tests/flip13/run-test000077500000000000000000000017131370426545100176550ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 EOF cat << EOF > file 1 2 3 4 5 6 7 8 9 10 11 12 modify 13 14 15 16 17 18 19 EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file 1 1 insert 2 insert 3 insert 4 insert 5 insert 6 insert 7 insert 8 insert 9 insert 10 insert 2 3 4 5 6 7 8 9 10 11 12 modify 13 14 15 16 16 insert 17 18 19 EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -1,4 +1,14 @@ 1 +1 insert +2 insert +3 insert +4 insert +5 insert +6 insert +7 insert +8 insert +9 insert +10 insert 2 3 4 @@ -14,6 +24,7 @@ 14 15 16 +16 insert 17 18 19 === 8< === cut here === 8< === --- file.orig +++ file @@ -19,7 +19,7 @@ 9 10 11 -12 +12 modify 13 14 15 EOF patchutils-0.4.2/tests/flip14/000077500000000000000000000000001370426545100161455ustar00rootroot00000000000000patchutils-0.4.2/tests/flip14/run-test000077500000000000000000000010631370426545100176540ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a a b c EOF cat << EOF > file a a d c EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file d c a a EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -1,4 +1,4 @@ -a -a b c +a +a === 8< === cut here === 8< === --- file.orig +++ file @@ -1,4 +1,4 @@ -b +d c a a EOF patchutils-0.4.2/tests/flip15/000077500000000000000000000000001370426545100161465ustar00rootroot00000000000000patchutils-0.4.2/tests/flip15/run-test000077500000000000000000000013261370426545100176570ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh # When a line is touched by both patches, the first patch after flipping # should get the change. Rationale: the patches ought to be largely # independent, and this is the best way of preserving the intent. cat << EOF > file.orig int a; EOF cat << EOF > file int a, b; EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file ssize_t a, b; EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -1 +1 @@ -int a; +ssize_t a, b; === 8< === cut here === 8< === EOF patchutils-0.4.2/tests/flip16/000077500000000000000000000000001370426545100161475ustar00rootroot00000000000000patchutils-0.4.2/tests/flip16/run-test000077500000000000000000000050211370426545100176540ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig 1 2 3 3a 4 5 6 7 pad 8 9 10 11 12 13 pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad1 pad2 pad3 padx pda padx pad3 pad2 pad1 pad pad pad pad pad a b c pad pad pad pad pad pad pad A B C pad pad pad EOF cat << EOF > file 1 2 3 4 5 6 7 pad 8 9 10 11 12 13 pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad1 pad2 pad3 padx pady padx pad3 pad2 pad1 pad pad pad pad pad a b c pad pad pad pad pad pad pad A B C pad pad pad EOF ${DIFF} -u file.orig file > patch1 mv -f file.orig file.orig.orig mv -f file file.orig cat << EOF > file 1 2 3 4 4a 5 6 7 pad 8 9 10 11a 12a 13a 14 15 16 17 18 19 20 11 12 13 pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad pad1 pad2 pad3 padx pady padx pad3 pad2 pad1 pad pad pad pad pad a b c d e f g h i j k l m n o p q r s t u v w x y z pad pad pad pad pad pad pad A B C D E F G H I J K L M N O P Q R S T U V W X Y Z pad pad pad EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -3,6 +3,7 @@ 3 3a 4 +4a 5 6 7 @@ -10,6 +11,16 @@ 8 9 10 +11a +12a +13a +14 +15 +16 +17 +18 +19 +20 11 12 13 @@ -116,6 +127,29 @@ a b c +d +e +f +g +h +i +j +k +l +m +n +o +p +q +r +s +t +u +v +w +x +y +z pad pad pad @@ -126,6 +160,29 @@ A B C +D +E +F +G +H +I +J +K +L +M +N +O +P +Q +R +S +T +U +V +W +X +Y +Z pad pad pad === 8< === cut here === 8< === --- file.orig +++ file @@ -1,7 +1,6 @@ 1 2 3 -3a 4 4a 5 @@ -114,7 +113,7 @@ pad2 pad3 padx -pda +pady padx pad3 pad2 EOF patchutils-0.4.2/tests/flip17/000077500000000000000000000000001370426545100161505ustar00rootroot00000000000000patchutils-0.4.2/tests/flip17/run-test000077500000000000000000000013011370426545100176520ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- file.orig +++ file @@ -0,0 +1,3 @@ +Added new code. +Seems to work. + EOF cat << EOF > patch2 --- file.orig +++ file @@ -5,7 +5,7 @@ Changed this. Changed that. -Borke it. +Broke it. Fixed it again. Fixed it. EOF ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -2,7 +2,7 @@ Changed this. Changed that. -Borke it. +Broke it. Fixed it again. Fixed it. === 8< === cut here === 8< === --- file.orig +++ file @@ -0,0 +1,3 @@ +Added new code. +Seems to work. + EOF patchutils-0.4.2/tests/flip18/000077500000000000000000000000001370426545100161515ustar00rootroot00000000000000patchutils-0.4.2/tests/flip18/run-test000077500000000000000000000014651370426545100176660ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- file.orig +++ file @@ -5,7 +5,7 @@ Changed this. Changed that. -Borke it. +Broke it. Fixed it again. Fixed it. @@ -16,6 +16,7 @@ Blah Blah Blah +Foo Blah Blah Blah EOF cat << EOF > patch2 --- file.orig +++ file @@ -13,3 +13,3 @@ Blah -blah +Blah Blah EOF ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-flipped << EOF || exit 1 --- file.orig +++ file @@ -13,5 +13,5 @@ Blah -blah +Blah Blah Blah Blah === 8< === cut here === 8< === --- file.orig +++ file @@ -5,7 +5,7 @@ Changed this. Changed that. -Borke it. +Broke it. Fixed it again. Fixed it. @@ -16,6 +16,7 @@ Blah Blah Blah +Foo Blah Blah Blah EOF patchutils-0.4.2/tests/flip19/000077500000000000000000000000001370426545100161525ustar00rootroot00000000000000patchutils-0.4.2/tests/flip19/run-test000077500000000000000000000016061370426545100176640ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. # We must give an error in this case, or else complete it successfully. # An error is acceptable. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- file.orig +++ file @@ -5,7 +5,7 @@ Changed this. Changed that. -Borke it. +Broke it. Fixed it again. Fixed it. EOF cat << EOF > patch2 --- file.orig +++ file @@ -13,3 +13,3 @@ Blah -blah +Blah Blah @@ -17,6 +17,7 @@ Blah Blah Blah +Foo Blah Blah Blah EOF ${FLIPDIFF} patch1 patch2 > patch-flipped 2>errors if [ "$?" -ne 0 ] then [ -s errors ] exit $? fi cmp - patch-flipped << EOF || exit 1 --- file.orig +++ file @@ -13,3 +13,3 @@ Blah -blah +Blah Blah @@ -17,6 +17,7 @@ Blah Blah Blah +Foo Blah Blah Blah === 8< === cut here === 8< === --- file.orig +++ file @@ -5,7 +5,7 @@ Changed this. Changed that. -Borke it. +Broke it. Fixed it again. Fixed it. EOF patchutils-0.4.2/tests/flip2/000077500000000000000000000000001370426545100160625ustar00rootroot00000000000000patchutils-0.4.2/tests/flip2/run-test000077500000000000000000000007611370426545100175750ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c EOF cat << EOF > file a d c EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file a c d EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -1,3 +1,3 @@ a -b c +d === 8< === cut here === 8< === EOF patchutils-0.4.2/tests/flip3/000077500000000000000000000000001370426545100160635ustar00rootroot00000000000000patchutils-0.4.2/tests/flip3/run-test000077500000000000000000000010441370426545100175710ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c EOF cat << EOF > file a d c EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file d c a EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -1,3 +1,3 @@ -a b c +a === 8< === cut here === 8< === --- file.orig +++ file @@ -1,3 +1,3 @@ -b +d c a EOF patchutils-0.4.2/tests/flip4/000077500000000000000000000000001370426545100160645ustar00rootroot00000000000000patchutils-0.4.2/tests/flip4/run-test000077500000000000000000000011241370426545100175710ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c d e f g h i j k l EOF cat << EOF > file b c d e f g h i j k l EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file b c d e f g h i j k EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -9,4 +9,3 @@ i j k -l === 8< === cut here === 8< === --- file.orig +++ file @@ -1,4 +1,3 @@ -a b c d EOF patchutils-0.4.2/tests/flip5/000077500000000000000000000000001370426545100160655ustar00rootroot00000000000000patchutils-0.4.2/tests/flip5/run-test000077500000000000000000000012261370426545100175750ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c d e f g h i j k l EOF cat << EOF > file a b cat dog d e f g h i j k l EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file a b cat dog elephant d e f g h i j k l EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -1,6 +1,7 @@ a b c +elephant d e f === 8< === cut here === 8< === --- file.orig +++ file @@ -1,6 +1,7 @@ a b -c +cat +dog elephant d e EOF patchutils-0.4.2/tests/flip6/000077500000000000000000000000001370426545100160665ustar00rootroot00000000000000patchutils-0.4.2/tests/flip6/run-test000077500000000000000000000012771370426545100176040ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c d e f g h i j k l EOF cat << EOF > file a b apple banana cat dog d e f g h i j k l EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file a b apple banana cat dog elephant d e f g h i j k l EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -1,6 +1,7 @@ a b c +elephant d e f === 8< === cut here === 8< === --- file.orig +++ file @@ -1,6 +1,9 @@ a b -c +apple +banana +cat +dog elephant d e EOF patchutils-0.4.2/tests/flip7/000077500000000000000000000000001370426545100160675ustar00rootroot00000000000000patchutils-0.4.2/tests/flip7/run-test000077500000000000000000000013001370426545100175700ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c d e f g h i j k l EOF cat << EOF > file a b apple banana cat dog d e f g h i j k l EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file a b elephant apple banana cat dog d e f g h i j k l EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -1,5 +1,6 @@ a b +elephant c d e === 8< === cut here === 8< === --- file.orig +++ file @@ -1,7 +1,10 @@ a b elephant -c +apple +banana +cat +dog d e f EOF patchutils-0.4.2/tests/flip8/000077500000000000000000000000001370426545100160705ustar00rootroot00000000000000patchutils-0.4.2/tests/flip8/run-test000077500000000000000000000015001370426545100175730ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file.orig a b c d e f g h i j k l m n o p q r s t u v w x y z EOF cat << EOF > file a b c D D D e f g h i j k L L L m n o p q r s T T T u v w x y z EOF ${DIFF} -u file.orig file > patch1 mv -f file file.orig cat << EOF > file a b c D D D e f g h i j k L L L m n o p q r s T T T u v x y z EOF ${DIFF} -u file.orig file > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file.orig +++ file @@ -20,7 +20,6 @@ t u v -w x y z === 8< === cut here === 8< === --- file.orig +++ file @@ -1,7 +1,9 @@ a b c -d +D +D +D e f g @@ -9,7 +11,9 @@ i j k -l +L +L +L m n o @@ -17,7 +21,9 @@ q r s -t +T +T +T u v x EOF patchutils-0.4.2/tests/flip9/000077500000000000000000000000001370426545100160715ustar00rootroot00000000000000patchutils-0.4.2/tests/flip9/run-test000077500000000000000000000010301370426545100175720ustar00rootroot00000000000000#!/bin/sh # This is a flipdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file1.orig a EOF cat << EOF > file1 A EOF cat << EOF > file2.orig b EOF cat << EOF > file2 B EOF ${DIFF} -u file1.orig file1 > patch1 ${DIFF} -u file2.orig file2 > patch2 ${FLIPDIFF} patch1 patch2 > patch-flipped || exit 1 sed -e "s/$(printf '\t').*$//" patch-flipped > patch-cmp cmp - patch-cmp << EOF || exit 1 --- file2.orig +++ file2 @@ -1 +1 @@ -b +B === 8< === cut here === 8< === --- file1.orig +++ file1 @@ -1 +1 @@ -a +A EOF patchutils-0.4.2/tests/fullheader1/000077500000000000000000000000001370426545100172425ustar00rootroot00000000000000patchutils-0.4.2/tests/fullheader1/run-test000077500000000000000000000016041370426545100207520ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Deal with git format-patch output more intelligently. . ${top_srcdir-.}/tests/common.sh cat <<"EOF" > git-output diff --git a/ChangeLog b/ChangeLog index aff7a94..304bef5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1 +1 @@ -Should hide diff and index lines +when not selected diff --git a/otherfile b/otherfile index 5feceb9..dde7898 10644 --- a/otherfile +++ b/otherfile @@ -1 +1 @@ -This file will +be selected EOF ${LSDIFF} -n git-output 2>errors >index || exit 1 [ -s errors ] && exit 1 cat <<"EOF" | cmp - index || exit 1 1 a/ChangeLog 8 a/otherfile EOF ${FILTERDIFF} -p1 -i otherfile git-output 2>errors >otherfile.patch || exit 1 [ -s errors ] && exit 1 cat <<"EOF" | cmp - otherfile.patch || exit 1 diff --git a/otherfile b/otherfile index 5feceb9..dde7898 10644 --- a/otherfile +++ b/otherfile @@ -1 +1 @@ -This file will +be selected EOF patchutils-0.4.2/tests/fullheader2/000077500000000000000000000000001370426545100172435ustar00rootroot00000000000000patchutils-0.4.2/tests/fullheader2/run-test000077500000000000000000000013631370426545100207550ustar00rootroot00000000000000#!/bin/sh # This is an interdiff(1) testcase. # Deal with git format-patch output more intelligently. # From: https://bugzilla.redhat.com/show_bug.cgi?id=1211062 . ${top_srcdir-.}/tests/common.sh cat <<"EOF" > git-output new file mode 100644 index 0000000..f0c06ab --- /dev/null +++ b/elf/tst-audit11mod1.c @@ -0,0 +1,6 @@ +extern int f2 (void); +int +f1 (void) +{ + return f2 (); +} diff --git a/elf/tst-audit11mod2.c b/elf/tst-audit11mod2.c new file mode 100644 index 0000000..cd3c9b1 --- /dev/null +++ b/elf/tst-audit11mod2.c @@ -0,0 +1,5 @@ +int +f2 (void) +{ + return 42; +} EOF ${INTERDIFF} git-output git-output 2>errors >index || { cat errors; exit 1; } [ -s errors ] && { cat errors; exit 1; } [ -s index ] && { cat index; exit 1; } exit 0 patchutils-0.4.2/tests/fullheader3/000077500000000000000000000000001370426545100172445ustar00rootroot00000000000000patchutils-0.4.2/tests/fullheader3/run-test000077500000000000000000000007531370426545100207600ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Handle git format-patch output containing remove-file diffs. # From: https://bugzilla.redhat.com/show_bug.cgi?id=1226985 . ${top_srcdir-.}/tests/common.sh cat <<"EOF" > git-output diff --git a/a b/a deleted file mode 100644 index 7898192..0000000 --- a/a +++ /dev/null @@ -1 +0,0 @@ -a EOF ${FILTERDIFF} git-output 2>errors >output || { cat errors; exit 1; } [ -s errors ] && { cat errors; exit 1; } cmp git-output output || exit 1 exit 0 patchutils-0.4.2/tests/fullheader4/000077500000000000000000000000001370426545100172455ustar00rootroot00000000000000patchutils-0.4.2/tests/fullheader4/run-test000077500000000000000000000011521370426545100207530ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Handle git format-patch output when stripping pathname components # From: https://github.com/twaugh/patchutils/issues/12 . ${top_srcdir-.}/tests/common.sh cat <<"EOF" > git-output diff --git a/test.txt b/test.txt index 257cc56..5716ca5 100644 --- a/test.txt +++ b/test.txt @@ -1 +1 @@ -foo +bar EOF ${FILTERDIFF} --strip=1 git-output 2>errors >output || { cat errors; exit 1; } [ -s errors ] && { cat errors; exit 1; } cmp output <<"EOF" || exit 1 diff --git test.txt test.txt index 257cc56..5716ca5 100644 --- test.txt +++ test.txt @@ -1 +1 @@ -foo +bar EOF exit 0 patchutils-0.4.2/tests/fuzz1/000077500000000000000000000000001370426545100161255ustar00rootroot00000000000000patchutils-0.4.2/tests/fuzz1/run-test000077500000000000000000000020711370426545100176340ustar00rootroot00000000000000#!/bin/sh # This is an interdiff(1) testcase. # Test: Prevent patch from checking EOF when not necessary # # I think the reason that this fails is that patch(1) assumes that # fewer post-context lines than pre-context lines indicates end of # file after the post-context. # # Possible work-around: get interdiff(1) to trim the pre-context lines # so that there aren't more than the post-context lines. # # IF YOU GET AN UNEXPECTED PASS (XPASS) when running this test you are # probably using a version of patch(1) that is missing a fix for # flushing stderr before exiting. . ${top_srcdir-.}/tests/common.sh cat << EOF > file LINE 1 line 2 line 3 line 4 line 5 if 1 fi if 2 fi A B C EOF cat << EOF > patch1 --- file +++ file @@ -1,4 +1,4 @@ -line 1 +LINE 1 line 2 line 3 line 4 EOF cat << EOF > patch2 --- file +++ file @@ -5,9 +5,6 @@ line 5 if 1 -fi -if -2 fi A B EOF ${INTERDIFF} patch1 patch2 2>errors >patch1-2 [ -s errors -o "$?" -gt "0" ] && { cat errors; exit 1;} ${PATCH} file < patch1-2 >errors || { cat errors; exit 1;} if grep fuzz errors; then exit 1; fi patchutils-0.4.2/tests/gendiff1/000077500000000000000000000000001370426545100165315ustar00rootroot00000000000000patchutils-0.4.2/tests/gendiff1/run-test000077500000000000000000000012341370426545100202400ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir cat << EOF > dir/file.orig a b EOF cat << EOF > abc a b c EOF cat << EOF > abd a b d EOF cp abc dir/file # "gendiff dir .orig" without requiring gendiff: (printf "diff -up dir/file.orig dir/file\n" diff -up dir/file.orig dir/file) > patch1 cp abd dir/file (printf "diff -up dir/file.orig dir/file\n" diff -up dir/file.orig dir/file) > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 mkdir test cp abc test/file cd test ${PATCH} -p1 < ../patch1-2 || exit 1 cd .. cmp abd test/file || exit 1 cd test ${PATCH} -R < ../patch1-2 || exit 1 cd .. cmp abc test/file || exit 1 patchutils-0.4.2/tests/gendiff2/000077500000000000000000000000001370426545100165325ustar00rootroot00000000000000patchutils-0.4.2/tests/gendiff2/run-test000077500000000000000000000012701370426545100202410ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir cat << EOF > dir/file.orig a b EOF cat << EOF > abc a b c EOF cat << EOF > abd a b d EOF cp abc dir/file # "gendiff dir .orig" without requiring gendiff: (printf "diff -up dir/file.orig dir/file\n" diff -up dir/file.orig dir/file) > patch1 cp abd dir/file mv dir/file.orig dir/file.old (printf "diff -up dir/file.old dir/file\n" diff -up dir/file.old dir/file) > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 mkdir test cp abc test/file cd test ${PATCH} -p1 < ../patch1-2 || exit 1 cd .. cmp abd test/file || exit 1 cd test ${PATCH} -R < ../patch1-2 || exit 1 cd .. cmp abc test/file || exit 1 patchutils-0.4.2/tests/grepdiff1/000077500000000000000000000000001370426545100167155ustar00rootroot00000000000000patchutils-0.4.2/tests/grepdiff1/run-test000077500000000000000000000005321370426545100204240ustar00rootroot00000000000000#!/bin/sh # This is a grepdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -0,0 +1 @@ ++a --- orig/file2 +++ file2 @@ -0,0 +1 @@ +a --- file3 +++ file3.orig @@ -0,0 +1 @@ +b EOF ${GREPDIFF} '\+a' diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 file1 EOF patchutils-0.4.2/tests/grepdiff2/000077500000000000000000000000001370426545100167165ustar00rootroot00000000000000patchutils-0.4.2/tests/grepdiff2/run-test000077500000000000000000000005521370426545100204270ustar00rootroot00000000000000#!/bin/sh # This is a grepdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -0,0 +1 @@ ++a --- orig/file2 +++ file2 @@ -0,0 +1 @@ +a --- file3 +++ file3.orig @@ -0,0 +1 @@ +b EOF ${GREPDIFF} -nv 'b' diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 9 file3 11 Hunk #1 EOF patchutils-0.4.2/tests/grepdiff3/000077500000000000000000000000001370426545100167175ustar00rootroot00000000000000patchutils-0.4.2/tests/grepdiff3/run-test000077500000000000000000000010161370426545100204240ustar00rootroot00000000000000#!/bin/sh # This is a grepdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -1 +1,2 @@ -A +a +b @@ -10 +11,2 @@ -C +c +d EOF ${GREPDIFF} --output-matching=file 'c' diff 2>errors >file || exit 1 ${GREPDIFF} --output-matching=hunk 'c' diff 2>errors >hunk || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - file || exit 1 --- file1 +++ file1 @@ -1 +1,2 @@ -A +a +b @@ -10 +11,2 @@ -C +c +d EOF cat << EOF | cmp - hunk || exit 1 --- file1 +++ file1 @@ -10 +10,2 @@ -C +c +d EOF patchutils-0.4.2/tests/grepdiff4/000077500000000000000000000000001370426545100167205ustar00rootroot00000000000000patchutils-0.4.2/tests/grepdiff4/run-test000077500000000000000000000012411370426545100204250ustar00rootroot00000000000000#!/bin/sh # This is a grepdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff *** file1.orig --- file1 *************** *** 1 **** ! A --- 1,2 ---- ! a ! b *** 10 **** ! C --- 11,12 ---- ! c ! d EOF ${GREPDIFF} --output-matching=file 'c' diff 2>errors >file || exit 1 ${GREPDIFF} --output-matching=hunk 'c' diff 2>errors >hunk || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - file || exit 1 *** file1.orig --- file1 *************** *** 1 **** ! A --- 1,2 ---- ! a ! b *************** *** 10 **** ! C --- 11,12 ---- ! c ! d EOF cat << EOF | cmp - hunk || exit 1 *** file1.orig --- file1 *************** *** 10 **** ! C --- 10,11 ---- ! c ! d EOF patchutils-0.4.2/tests/grepdiff5/000077500000000000000000000000001370426545100167215ustar00rootroot00000000000000patchutils-0.4.2/tests/grepdiff5/run-test000077500000000000000000000020111370426545100204220ustar00rootroot00000000000000#!/bin/sh # This is a grepdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -1 +1,2 @@ -A +a +b @@ -10 +11,2 @@ -C +c +d EOF ${GREPDIFF} --output-matching=hunk --as-numbered-lines=after 'cow' diff \ 2>>errors >no-match || exit 1 ${GREPDIFF} --output-matching=file --as-numbered-lines=before 'c' diff \ 2>errors >file-before || exit 1 ${GREPDIFF} --output-matching=hunk --as-numbered-lines=before 'c' diff \ 2>>errors >hunk-before || exit 1 ${GREPDIFF} --output-matching=file --as-numbered-lines=after 'c' diff \ 2>>errors >file-after || exit 1 ${GREPDIFF} --output-matching=hunk --as-numbered-lines=after 'c' diff \ 2>>errors >hunk-after || exit 1 [ -s errors ] && exit 1 [ -s no-match ] && exit 1 cat << EOF | cmp - file-before || exit 1 --- file1 1 :A ... 10 :C EOF cat << EOF | cmp - hunk-before || exit 1 --- file1 10 :C EOF cat << EOF | cmp - file-after || exit 1 +++ file1 1 :a 2 :b ... 11 :c 12 :d EOF cat << EOF | cmp - hunk-after || exit 1 +++ file1 10 :c 11 :d EOF patchutils-0.4.2/tests/grepdiff6/000077500000000000000000000000001370426545100167225ustar00rootroot00000000000000patchutils-0.4.2/tests/grepdiff6/run-test000077500000000000000000000021031370426545100204250ustar00rootroot00000000000000#!/bin/sh # This is a grepdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff *** file1.orig --- file1 *************** *** 1 **** ! A --- 1,2 ---- ! a ! b *** 10 **** ! C --- 11,12 ---- ! c ! d EOF ${GREPDIFF} --output-matching=hunk --as-numbered-lines=after 'cow' diff \ 2>>errors >no-match || exit 1 ${GREPDIFF} --output-matching=file --as-numbered-lines=before 'c' diff \ 2>errors >file-before || exit 1 ${GREPDIFF} --output-matching=hunk --as-numbered-lines=before 'c' diff \ 2>>errors >hunk-before || exit 1 ${GREPDIFF} --output-matching=file --as-numbered-lines=after 'c' diff \ 2>>errors >file-after || exit 1 ${GREPDIFF} --output-matching=hunk --as-numbered-lines=after 'c' diff \ 2>>errors >hunk-after || exit 1 [ -s errors ] && exit 1 [ -s no-match ] && exit 1 cat << EOF | cmp - file-before || exit 1 *** file1.orig 1 :A ... 10 :C EOF cat << EOF | cmp - hunk-before || exit 1 *** file1.orig 10 :C EOF cat << EOF | cmp - file-after || exit 1 --- file1 1 :a 2 :b ... 11 :c 12 :d EOF cat << EOF | cmp - hunk-after || exit 1 --- file1 10 :c 11 :d EOF patchutils-0.4.2/tests/grepdiff7/000077500000000000000000000000001370426545100167235ustar00rootroot00000000000000patchutils-0.4.2/tests/grepdiff7/run-test000077500000000000000000000006271370426545100204370ustar00rootroot00000000000000#!/bin/sh # This is a grepdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- foo 2004-03-30 15:55:52.037395000 -0600 +++ bar 2004-03-26 17:04:42.486526100 -0600 @@ -90,13 +90,13 @@ -a + -b + @@ -110,10 +110,6 @@ - - - - EOF ${GREPDIFF} --output-matching=file . diff 2>errors >matched || exit 1 [ -s errors ] && exit 1 cmp diff matched || exit 1 patchutils-0.4.2/tests/grepdiff8/000077500000000000000000000000001370426545100167245ustar00rootroot00000000000000patchutils-0.4.2/tests/grepdiff8/run-test000077500000000000000000000012151370426545100204320ustar00rootroot00000000000000#!/bin/sh # This is a grepdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -1,2 +1,2 @@ context -a +b --- file2 +++ file2 @@ -1 +1 @@ -bx +a EOF ${GREPDIFF} --only-match=rem 'a' diff 2>errors >rem || exit 1 ${GREPDIFF} --only-match=add 'a' diff 2>>errors >add || exit 1 ${GREPDIFF} --only-match=mod 'x' diff 2>>errors >mod || exit 1 ${GREPDIFF} --only-match=all 'x' diff 2>>errors >all || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rem || exit 1 file1 EOF cat << EOF | cmp - add || exit 1 file2 EOF cat << EOF | cmp - mod || exit 1 file2 EOF cat << EOF | cmp - all || exit 1 file1 file2 EOF patchutils-0.4.2/tests/grepdiff9/000077500000000000000000000000001370426545100167255ustar00rootroot00000000000000patchutils-0.4.2/tests/grepdiff9/run-test000077500000000000000000000013201370426545100204300ustar00rootroot00000000000000#!/bin/sh # This is a grepdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff *** file1 --- file1 *************** *** 1,2 **** context - a --- 1,2 ---- context + b *** file2 --- file2 *************** *** 1 **** - bx --- 1 ---- + a EOF ${GREPDIFF} --only-match=rem 'a' diff 2>errors >rem || exit 1 ${GREPDIFF} --only-match=add 'a' diff 2>>errors >add || exit 1 ${GREPDIFF} --only-match=mod 'x' diff 2>>errors >mod || exit 1 ${GREPDIFF} --only-match=all 'x' diff 2>>errors >all || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rem || exit 1 file1 EOF cat << EOF | cmp - add || exit 1 file2 EOF cat << EOF | cmp - mod || exit 1 file2 EOF cat << EOF | cmp - all || exit 1 file1 file2 EOF patchutils-0.4.2/tests/linux-2.2.17-pre4-5/000077500000000000000000000000001370426545100177445ustar00rootroot00000000000000patchutils-0.4.2/tests/linux-2.2.17-pre4-5/run-test000077500000000000000000000025211370426545100214530ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir orig new1 new2 cat << EOF > orig/pmac_support.c a1 b1 c1 d1 stuff d1 c1 b1 a1 pad pad pad pad pad pad pad EOF cat << EOF > new1/pmac_support.c a1 b1 c1 d1 insert above stuff stuff d1 c1 b1 a1 pad pad pad pad large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff pad pad pad EOF cat << EOF > new2/pmac_support.c a1 b1 c1 d1 insert above stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff large amount of stuff stuff d1 c1 b1 a1 pad pad pad pad pad pad pad EOF ${DIFF} -ur orig new1 > patch1 ${DIFF} -ur orig new2 > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 cd new1 ${PATCH} < ../patch1-2 || exit 1 cd .. diff -ur new1 new2 || exit 1 patchutils-0.4.2/tests/linux-2.4.0-test-pre-style/000077500000000000000000000000001370426545100215435ustar00rootroot00000000000000patchutils-0.4.2/tests/linux-2.4.0-test-pre-style/run-test000077500000000000000000000011151370426545100232500ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir -p v2.4.0-test5/linux mkdir linux cat << EOF > v2.4.0-test5/linux/file a b c EOF cat << EOF > new1 a b EOF cat << EOF > new2 b c EOF cp new1 linux/file ${DIFF} -u v2.4.0-test5/linux/file linux/file > patch1 cp new2 linux/file ${DIFF} -u v2.4.0-test5/linux/file linux/file > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 mkdir test cp new1 test/file cd test ${PATCH} < ../patch1-2 || exit 1 cd .. cmp new2 test/file || exit 1 cd test ${PATCH} -R < ../patch1-2 cd .. cmp new1 test/file || exit 1 patchutils-0.4.2/tests/linux-2.4.13-ac6-7/000077500000000000000000000000001370426545100175435ustar00rootroot00000000000000patchutils-0.4.2/tests/linux-2.4.13-ac6-7/run-test000077500000000000000000000041211370426545100212500ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- linux.vanilla/arch/i386/kernel/dmi_scan.c Thu Oct 25 16:26:33 2001 +++ linux.ac/arch/i386/kernel/dmi_scan.c Fri Oct 26 19:39:16 2001 @@ -380,12 +380,11 @@ pm_kbd_request_override = pckbd_pm_resume; printk(KERN_INFO "%s machine detected. Mousepad Resume Bug workaround enabled.\n", d->ident); } -#endif +#endif return 0; } - /* * Process the DMI blacklists */ @@ -400,7 +399,6 @@ blah blah blah -blah blah blah blah EOF cat << EOF > patch2 --- linux.vanilla/arch/i386/kernel/dmi_scan.c Thu Oct 25 16:26:33 2001 +++ linux.ac/arch/i386/kernel/dmi_scan.c Fri Nov 2 14:43:41 2001 @@ -380,11 +380,26 @@ pm_kbd_request_override = pckbd_pm_resume; printk(KERN_INFO "%s machine detected. Mousepad Resume Bug workaround enabled.\n", d->ident); } -#endif +#endif return 0; } +/* + * Dell Inspiron 8000 APM BIOS fails to correctly save and restore the + * config space of some PCI devices. + */ + +static __init int broken_apm_pci_restore(struct dmi_blacklist *d) +{ +#ifdef CONFIG_PCI + extern int pci_bridge_force_restore; + + printk(KERN_WARNING "%s detected. Forcing restore of PCI configuration space on APM resume.\n", d->ident); + pci_bridge_force_restore = 1; +#endif + return 0; +} /* * Process the DMI blacklists @@ -400,7 +415,6 @@ blah blah blah -blah blah blah blah EOF ${INTERDIFF} -q patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 cmp patch1-2 - << EOF || exit 1 --- linux.ac/arch/i386/kernel/dmi_scan.c Fri Oct 26 19:39:16 2001 +++ linux.ac/arch/i386/kernel/dmi_scan.c Fri Nov 2 14:43:41 2001 @@ -387,4 +387,20 @@ /* + * Dell Inspiron 8000 APM BIOS fails to correctly save and restore the + * config space of some PCI devices. + */ + +static __init int broken_apm_pci_restore(struct dmi_blacklist *d) +{ +#ifdef CONFIG_PCI + extern int pci_bridge_force_restore; + + printk(KERN_WARNING "%s detected. Forcing restore of PCI configuration space on APM resume.\n", d->ident); + pci_bridge_force_restore = 1; +#endif + return 0; +} + +/* * Process the DMI blacklists */ EOF patchutils-0.4.2/tests/lscontext1/000077500000000000000000000000001370426545100171525ustar00rootroot00000000000000patchutils-0.4.2/tests/lscontext1/run-test000077500000000000000000000006451370426545100206660ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh echo 'a' > file1.orig echo 'b' > file1 cp file1.orig file2.orig cp file1 file2 cp file1.orig file3.orig cp file1 file3 diff -c file1.orig file1 > diff diff -c file2.orig file2 >> diff diff -c file3.orig file3 >> diff ${LSDIFF} diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 file1 file2 file3 EOF patchutils-0.4.2/tests/lscontext2/000077500000000000000000000000001370426545100171535ustar00rootroot00000000000000patchutils-0.4.2/tests/lscontext2/run-test000077500000000000000000000004401370426545100206600ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > file1.orig a c EOF cat << EOF > file1 a b c EOF ${DIFF} -c file1.orig file1 > diff ${LSDIFF} diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 file1 EOF patchutils-0.4.2/tests/lscontext3/000077500000000000000000000000001370426545100171545ustar00rootroot00000000000000patchutils-0.4.2/tests/lscontext3/run-test000077500000000000000000000005211370426545100206610ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh printf 'a\n\n\n\n\n\n\n\nb\n' > file1.orig printf '\n\n\n\n\n\n\n' > file1 ${DIFF} -c file1.orig file1 > diff ${LSDIFF} -nv diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 1 file1 4 Hunk #1 11 Hunk #2 EOF patchutils-0.4.2/tests/lsdiff1/000077500000000000000000000000001370426545100163765ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff1/run-test000077500000000000000000000005331370426545100201060ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -0,0 +1 @@ +a --- orig/file2 +++ file2 @@ -0,0 +1 @@ +a --- file3 +++ file3.orig @@ -0,0 +1 @@ +a EOF ${LSDIFF} diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 file1 file2 file3 EOF patchutils-0.4.2/tests/lsdiff10/000077500000000000000000000000001370426545100164565ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff10/run-test000077500000000000000000000011621370426545100201650ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: -nv output format, context input . ${top_srcdir-.}/tests/common.sh cat << EOF > diff Here are some non-diff lines. They should not be displayed by lsdiff -v. *** file1 --- file1 *************** *** 0 **** --- 1 ---- + a *** 60 **** ! a --- 60 ---- ! b *** orig/file2 --- file2 *************** *** 0 **** --- 1 ---- + a *** file3 --- file3.orig *************** *** 0 **** --- 1 ---- + a EOF ${LSDIFF} -nv diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 3 file1 6 Hunk #1 9 Hunk #2 13 file2 16 Hunk #1 19 file3 22 Hunk #1 EOF patchutils-0.4.2/tests/lsdiff11/000077500000000000000000000000001370426545100164575ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff11/run-test000077500000000000000000000026131370426545100201700ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: See if lsdiff handles filenames with spaces with no tab sep. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff1 --- filename.orig Mon Dec 17 15:53:01 2001 +++ filename Thu Jan 1 01:00:00 1970 @@ -1 +0,0 @@ -(tabs -> spaces) EOF cat << EOF > diff2 --- file name.orig Mon Dec 17 15:53:01 2001 +++ file name Thu Jan 1 01:00:00 1970 @@ -1 +0,0 @@ -(tabs -> spaces, filename with space) EOF cat << EOF > diff3 --- spamthrottle/FILES Feb 2001 20:16:31 -0000 1.1.1.1 +++ spamthrottle/FILES Dec 2002 15:35:51 -0000 1.1.1.1.2.3 @@ -1 +0,0 @@ -(alternate date format) EOF cat << EOF > diff4 --- spam throttle/FILES Feb 2001 20:16:31 -0000 1.1.1.1 +++ spam throttle/FILES Dec 2002 15:35:51 -0000 1.1.1.1.2.3 @@ -1 +0,0 @@ -(alternate date format, filename with space) EOF cat << EOF > diff5 --- filename Fri, Jun 13 2003 12:22:00 +0100 +++ filename Fri, Jun 13 2003 12:22:00 +0100 @@ -1 +0,0 @@ -(unknown date format) EOF ${LSDIFF} -h diff1 diff2 diff3 diff4 diff5 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 filename file name spamthrottle/FILES spam throttle/FILES filename EOF ${LSDIFF} -H diff1 diff2 diff3 diff4 diff5 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 diff1:filename diff2:file name diff3:spamthrottle/FILES diff4:spam throttle/FILES diff5:filename EOF patchutils-0.4.2/tests/lsdiff12/000077500000000000000000000000001370426545100164605ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff12/run-test000077500000000000000000000004761370426545100201760ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: See if lsdiff -s behaves as expected with regard to /dev/null . ${top_srcdir-.}/tests/common.sh echo a >file1 echo a | ${DIFF} -du file1 /dev/null | \ ${LSDIFF} -s 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 - file1 EOF patchutils-0.4.2/tests/lsdiff13/000077500000000000000000000000001370426545100164615ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff13/run-test000077500000000000000000000022071370426545100201710ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: lsdiff -H behaviour . ${top_srcdir-.}/tests/common.sh mkdir dir dir.orig echo a > file1.orig echo A > file1 ${DIFF} -u file1.orig file1 > diff1 echo a > file2.orig echo A > file2 ${DIFF} -u file2.orig file2 > diff2 ${LSDIFF} -H diff1 diff2 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 diff1:file1 diff2:file2 EOF ${LSDIFF} diff1 diff2 2>errors >index || exit 1 [ -s errors ] && exit 1 cat <errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 (standard input):file1 EOF cat diff1 | ${LSDIFF} 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 file1 EOF ${LSDIFF} -Hnv diff1 diff2 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 diff1:1 file1 diff1- 3 Hunk #1 diff2:5 file2 diff2- 7 Hunk #1 EOF ${LSDIFF} -nv diff1 diff2 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 diff1:1 file1 diff1- 3 Hunk #1 diff2:5 file2 diff2- 7 Hunk #1 EOF patchutils-0.4.2/tests/lsdiff14/000077500000000000000000000000001370426545100164625ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff14/run-test000077500000000000000000000006421370426545100201730ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: -Es output format, unified input . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -0,0 +1 @@ +a @@ -60 +60 @@ -a +b --- orig/file2 +++ file2 @@ -0,0 +1 @@ +a --- file3 +++ file3.orig @@ -1 +0,0 @@ -a EOF ${LSDIFF} -Es diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 ! file1 + file2 - file3 EOF patchutils-0.4.2/tests/lsdiff15/000077500000000000000000000000001370426545100164635ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff15/run-test000077500000000000000000000007711370426545100201770ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: -Es output format, context input . ${top_srcdir-.}/tests/common.sh cat << EOF > diff *** file1 --- file1 *************** *** 0 **** --- 1 ---- + a *** 60 **** ! a --- 60 ---- ! b *** orig/file2 --- file2 *************** *** 0 **** --- 1 ---- + a *** file3 --- file3.orig *************** *** 1 **** - a --- 0 ---- EOF ${LSDIFF} -Es diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 ! file1 + file2 - file3 EOF patchutils-0.4.2/tests/lsdiff2/000077500000000000000000000000001370426545100163775ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff2/run-test000077500000000000000000000007011370426545100201040ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: See if -s works. . ${top_srcdir-.}/tests/common.sh mkdir dir dir.orig echo a > dir.orig/a echo A > dir/a ${DIFF} -uN dir.orig dir > diff rm dir/a ${DIFF} -uN dir.orig dir >> diff mv dir.orig/a dir ${DIFF} -uN dir.orig dir >> diff cat diff diff > diff2 ${LSDIFF} -s --strip=1 diff2 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 ! a - a + a ! a - a + a EOF patchutils-0.4.2/tests/lsdiff3/000077500000000000000000000000001370426545100164005ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff3/run-test000077500000000000000000000022271370426545100201120ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: See if -s works across locales. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff1 --- file1 Mon Dec 17 15:53:01 2001 +++ file1 Thu Jan 1 01:00:00 1970 @@ -1 +0,0 @@ -removed EOF cat << EOF > diff2 --- file2 Mon Dec 17 15:53:01 2001 +++ file2 Wed Dec 31 19:00:00 1969 @@ -1 +0,0 @@ -removed EOF cat << EOF > diff3 --- file3 2002-10-07 08:31:24.000000000 +0100 +++ file3 1970-01-01 01:00:00.000000000 +0100 @@ -1 +0,0 @@ -removed EOF cat << EOF > diff4 --- file4 2002-10-07 08:31:24.000000000 +0100 +++ file4 1969-12-31 23:45:00.000000000 -0015 @@ -1 +0,0 @@ -removed EOF cat << EOF > diff5 --- file5 2002-10-07 08:31:24.000000000 +0100 +++ file5 1970-01-01 00:00:00.000000000 +0100 @@ -1 +0,0 @@ -not removed --- this is a red herring EOF ${LSDIFF} -sh diff1 diff2 diff3 diff4 diff5 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 - file1 - file2 - file3 - file4 ! file5 EOF ${LSDIFF} -sH diff1 diff2 diff3 diff4 diff5 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 diff1:- file1 diff2:- file2 diff3:- file3 diff4:- file4 diff5:! file5 EOF patchutils-0.4.2/tests/lsdiff4/000077500000000000000000000000001370426545100164015ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff4/run-test000077500000000000000000000005721370426545100201140ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: See if lsdiff handles filenames with spaces. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff1 --- file name.orig Mon Dec 17 15:53:01 2001 +++ file name Thu Jan 1 01:00:00 1970 @@ -1 +0,0 @@ -removed EOF ${LSDIFF} diff1 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 file name EOF patchutils-0.4.2/tests/lsdiff5/000077500000000000000000000000001370426545100164025ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff5/run-test000077500000000000000000000016221370426545100201120ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: Different context output styles. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff1 *** file.orig Wed Mar 20 10:08:24 2002 --- file Wed Mar 20 10:08:24 2002 *************** *** 1,7 **** a b c ! d e f g --- 1,7 ---- a b c ! D e f g *************** *** 9,15 **** i j k ! l m n o --- 9,15 ---- i j k ! L m n o *************** *** 21,23 **** --- 21,26 ---- u v w + x + y + z EOF (IFS=\ first=1 while read line; do if test "x$line" = "x***************" then if test $first -eq 0 then continue fi first=0 fi echo "$line" done) < diff1 > diff2 ${LSDIFF} diff1 2>errors >index1 || exit 1 [ -s errors ] && exit 1 ${LSDIFF} diff2 2>errors >index2 || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index1 || exit 1 file EOF cat << EOF | cmp - index2 || exit 1 file EOF patchutils-0.4.2/tests/lsdiff6/000077500000000000000000000000001370426545100164035ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff6/run-test000077500000000000000000000011151370426545100201100ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: --strip and --addprefix tests. . ${top_srcdir-.}/tests/common.sh mkdir dir dir.orig echo a > dir.orig/a echo A > dir/a ${DIFF} -uN dir.orig dir > diff ${LSDIFF} --addprefix=prefix/ --strip=1 diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 prefix/a EOF ${FILTERDIFF} --addprefix=prefix/ --strip=1 diff 2>errors >filtered || exit 1 [ -s errors ] && exit 1 ${LSDIFF} filtered 2>errors >filtered-index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - filtered-index || exit 1 prefix/a EOF patchutils-0.4.2/tests/lsdiff7/000077500000000000000000000000001370426545100164045ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff7/run-test000077500000000000000000000005751370426545100201220ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: -n output format . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -0,0 +1 @@ +a --- orig/file2 +++ file2 @@ -0,0 +1 @@ +a --- file3 +++ file3.orig @@ -0,0 +1 @@ +a EOF ${LSDIFF} -n diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 1 file1 5 file2 9 file3 EOF patchutils-0.4.2/tests/lsdiff8/000077500000000000000000000000001370426545100164055ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff8/run-test000077500000000000000000000007211370426545100201140ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: -nv output format, unified input . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -0,0 +1 @@ +a @@ -60 +60 @@ -a +b --- orig/file2 +++ file2 @@ -0,0 +1 @@ +a --- file3 +++ file3.orig @@ -0,0 +1 @@ +a EOF ${LSDIFF} -nv diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 1 file1 3 Hunk #1 5 Hunk #2 8 file2 10 Hunk #1 12 file3 14 Hunk #1 EOF patchutils-0.4.2/tests/lsdiff9/000077500000000000000000000000001370426545100164065ustar00rootroot00000000000000patchutils-0.4.2/tests/lsdiff9/run-test000077500000000000000000000010511370426545100201120ustar00rootroot00000000000000#!/bin/sh # This is a lsdiff(1) testcase. # Test: -nv output format, context input . ${top_srcdir-.}/tests/common.sh cat << EOF > diff *** file1 --- file1 *************** *** 0 **** --- 1 ---- + a *** 60 **** ! a --- 60 ---- ! b *** orig/file2 --- file2 *************** *** 0 **** --- 1 ---- + a *** file3 --- file3.orig *************** *** 0 **** --- 1 ---- + a EOF ${LSDIFF} -nv diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 1 file1 4 Hunk #1 7 Hunk #2 11 file2 14 Hunk #1 17 file3 20 Hunk #1 EOF patchutils-0.4.2/tests/newline1/000077500000000000000000000000001370426545100165705ustar00rootroot00000000000000patchutils-0.4.2/tests/newline1/run-test000077500000000000000000000012711370426545100203000ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh cat << EOF > orig a b c EOF cat << EOF > new1 a b EOF cat << EOF > new2 a b EOF echo -n c >> new2 cp new1 start ${DIFF} -u orig new1 > patch1 ${DIFF} -u orig new2 > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 ${PATCH} < patch1-2 || exit 1 cmp new1 new2 || exit 1 ${PATCH} -R < patch1-2 cmp new1 start || exit 1 mv new1 tmp mv new2 new1 mv tmp new2 cp new1 start ${DIFF} -u orig new1 > patch3 ${DIFF} -u orig new2 > patch4 ${INTERDIFF} patch3 patch4 2>errors > patch3-4 || exit 1 [ -s errors ] && exit 1 ${PATCH} < patch3-4 || exit 1 cmp new1 new2 || exit 1 ${PATCH} -R < patch3-4 cmp new1 start || exit 1 patchutils-0.4.2/tests/newline2/000077500000000000000000000000001370426545100165715ustar00rootroot00000000000000patchutils-0.4.2/tests/newline2/run-test000077500000000000000000000005311370426545100202770ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir mkdir modified cat << EOF > modified/file a b EOF echo -n c >> modified/file touch patch1 ${DIFF} -urN dir modified > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 cd dir ${PATCH} < ../patch1-2 || exit 1 cd .. ${DIFF} -urN dir modified || exit 1 patchutils-0.4.2/tests/newline3/000077500000000000000000000000001370426545100165725ustar00rootroot00000000000000patchutils-0.4.2/tests/newline3/run-test000077500000000000000000000005361370426545100203050ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir mkdir modified cat << EOF > modified/file a b EOF echo -n c >> modified/file ${DIFF} -urN dir modified > patch1 touch patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 cd modified ${PATCH} < ../patch1-2 || exit 1 cd .. ${DIFF} -urN dir modified || exit 1 patchutils-0.4.2/tests/newline4/000077500000000000000000000000001370426545100165735ustar00rootroot00000000000000patchutils-0.4.2/tests/newline4/run-test000077500000000000000000000006421370426545100203040ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh cat << EOF > orig a b EOF echo -n c >> orig cat << EOF > new a b c EOF ${DIFF} -u orig new > patch ${INTERDIFF} patch patch 2>errors > null || exit 1 [ -s errors ] && exit 1 [ -s null ] && echo 1 ${INTERDIFF} patch /dev/null 2>errors > reverse || exit 1 [ -s errors ] && exit 1 ${PATCH} -i reverse new 2>errors || exit 1 [ -s errors ] && exit 1 cmp orig new || exit 1 patchutils-0.4.2/tests/newline5/000077500000000000000000000000001370426545100165745ustar00rootroot00000000000000patchutils-0.4.2/tests/newline5/run-test000077500000000000000000000005441370426545100203060ustar00rootroot00000000000000#!/bin/sh # # This is a filterdiff(1) test case. # Test: Handle adding newline to EOF . ${top_srcdir-.}/tests/common.sh cat << EOF > orig a b EOF echo -n c >> orig cat << EOF > new a b c EOF ${DIFF} -u orig new > patch ${FILTERDIFF} patch 2>errors > filtered || exit 1 [ -s errors ] && exit 1 ${PATCH} orig -i filtered || exit 1 cmp orig new || exit 1 patchutils-0.4.2/tests/newline6/000077500000000000000000000000001370426545100165755ustar00rootroot00000000000000patchutils-0.4.2/tests/newline6/run-test000077500000000000000000000005441370426545100203070ustar00rootroot00000000000000#!/bin/sh # # This is a filterdiff(1) test case. # Test: Handle adding newline to EOF . ${top_srcdir-.}/tests/common.sh cat << EOF > orig a b EOF echo -n c >> orig cat << EOF > new a b c EOF ${DIFF} -c orig new > patch ${FILTERDIFF} patch 2>errors > filtered || exit 1 [ -s errors ] && exit 1 ${PATCH} orig -i filtered || exit 1 cmp orig new || exit 1 patchutils-0.4.2/tests/nodate/000077500000000000000000000000001370426545100163205ustar00rootroot00000000000000patchutils-0.4.2/tests/nodate/run-test000077500000000000000000000006731370426545100200350ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- file.orig +++ file @@ -36 +36 @@ -oldline +newline EOF cat << EOF > patch2 --- file.orig Nov 27 2001 +++ file Nov 27 2001 @@ -36 +36 @@ -oldline +betterline EOF ${INTERDIFF} -U0 patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - patch1-2 || exit 1 diff -U0 file file --- file +++ file Nov 27 2001 @@ -36 +36 @@ -newline +betterline EOF patchutils-0.4.2/tests/nondiff/000077500000000000000000000000001370426545100164715ustar00rootroot00000000000000patchutils-0.4.2/tests/nondiff/run-test000077500000000000000000000005051370426545100202000ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 This is a non-diff line. --- file.orig +++ file @@ -36 +36 @@ -oldline +newline So is this. EOF ${FILTERDIFF} -x file patch1 2>errors > filtered || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - filtered || exit 1 This is a non-diff line. So is this. EOF patchutils-0.4.2/tests/nondiff1/000077500000000000000000000000001370426545100165525ustar00rootroot00000000000000patchutils-0.4.2/tests/nondiff1/run-test000077500000000000000000000007021370426545100202600ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 This is a non-diff line. *** file --- file *************** *** 1,5 **** a b ! c d e --- 1,5 ---- a b C d e So is this. *** file --- file *************** *** 0 **** --- 1 ---- + a And this. EOF ${FILTERDIFF} -x file patch1 2>errors > filtered || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - filtered || exit 1 This is a non-diff line. So is this. And this. EOF patchutils-0.4.2/tests/nul0/000077500000000000000000000000001370426545100157245ustar00rootroot00000000000000patchutils-0.4.2/tests/nul0/run-test000077500000000000000000000004521370426545100174340ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Handle embedded nul characters. . ${top_srcdir-.}/tests/common.sh echo -e "abc\0" > file1 echo abc > file2 ${DIFF} -au file1 file2 > diff ${FILTERDIFF} diff 2>errors >filtered || exit 1 [ -s errors ] && exit 1 cmp diff filtered || exit 1 patchutils-0.4.2/tests/nul1/000077500000000000000000000000001370426545100157255ustar00rootroot00000000000000patchutils-0.4.2/tests/nul1/run-test000077500000000000000000000004641370426545100174400ustar00rootroot00000000000000#!/bin/sh # This is an interdiff(1) testcase. # Test: Handle embedded nul characters. . ${top_srcdir-.}/tests/common.sh echo -e "abc\0" > file1 echo abc > file2 ${DIFF} -au file1 file2 > diff ${INTERDIFF} -q /dev/null diff 2>errors >newdiff || exit 1 [ -s errors ] && exit 1 cmp diff newdiff || exit 1 patchutils-0.4.2/tests/nul2/000077500000000000000000000000001370426545100157265ustar00rootroot00000000000000patchutils-0.4.2/tests/nul2/run-test000077500000000000000000000004731370426545100174410ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Handle embedded nul characters (context format). . ${top_srcdir-.}/tests/common.sh echo -e "abc\0" > file1 echo abc > file2 ${DIFF} -ac file1 file2 > diff ${FILTERDIFF} diff 2>errors >filtered || exit 1 [ -s errors ] && exit 1 cmp diff filtered || exit 1 patchutils-0.4.2/tests/nul3/000077500000000000000000000000001370426545100157275ustar00rootroot00000000000000patchutils-0.4.2/tests/nul3/run-test000077500000000000000000000006371370426545100174440ustar00rootroot00000000000000#!/bin/sh # This is an interdiff(1) testcase. # Test: Handle embedded nul characters (context format). . ${top_srcdir-.}/tests/common.sh echo -e "abc\0" > file1 echo abc > file2 ${DIFF} -ac file1 file2 > cdiff ${INTERDIFF} -q /dev/null cdiff 2>errors >newdiff || exit 1 [ -s errors ] && exit 1 ${FILTERDIFF} --format=unified cdiff 2>errors > diff || exit 1 [ -s errors ] && exit 1 cmp diff newdiff || exit 1 patchutils-0.4.2/tests/number1/000077500000000000000000000000001370426545100164175ustar00rootroot00000000000000patchutils-0.4.2/tests/number1/run-test000077500000000000000000000016541370426545100201340ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -1 +1,2 @@ -A +a +b @@ -10 +11,2 @@ -C +c +d EOF ${FILTERDIFF} --as-numbered-lines=after --hunks=100 diff \ 2>>errors >no-match || exit 1 ${FILTERDIFF} --as-numbered-lines=before diff \ 2>errors >file-before || exit 1 ${FILTERDIFF} --as-numbered-lines=before --hunks=2 diff \ 2>>errors >hunk-before || exit 1 ${FILTERDIFF} --as-numbered-lines=after diff \ 2>>errors >file-after || exit 1 ${FILTERDIFF} --as-numbered-lines=after --hunks=2 diff \ 2>>errors >hunk-after || exit 1 [ -s errors ] && exit 1 [ -s no-match ] && exit 1 cat << EOF | cmp - file-before || exit 1 --- file1 1 :A ... 10 :C EOF cat << EOF | cmp - hunk-before || exit 1 --- file1 10 :C EOF cat << EOF | cmp - file-after || exit 1 +++ file1 1 :a 2 :b ... 11 :c 12 :d EOF cat << EOF | cmp - hunk-after || exit 1 +++ file1 10 :c 11 :d EOF patchutils-0.4.2/tests/number2/000077500000000000000000000000001370426545100164205ustar00rootroot00000000000000patchutils-0.4.2/tests/number2/run-test000077500000000000000000000017461370426545100201370ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff *** file1.orig --- file1 *************** *** 1 **** ! A --- 1,2 ---- ! a ! b *** 10 **** ! C --- 11,12 ---- ! c ! d EOF ${FILTERDIFF} --as-numbered-lines=after --hunks=100 diff \ 2>>errors >no-match || exit 1 ${FILTERDIFF} --as-numbered-lines=before diff \ 2>errors >file-before || exit 1 ${FILTERDIFF} --as-numbered-lines=before --hunks=2 diff \ 2>>errors >hunk-before || exit 1 ${FILTERDIFF} --as-numbered-lines=after diff \ 2>>errors >file-after || exit 1 ${FILTERDIFF} --as-numbered-lines=after --hunks=2 diff \ 2>>errors >hunk-after || exit 1 [ -s errors ] && exit 1 [ -s no-match ] && exit 1 cat << EOF | cmp - file-before || exit 1 *** file1.orig 1 :A ... 10 :C EOF cat << EOF | cmp - hunk-before || exit 1 *** file1.orig 10 :C EOF cat << EOF | cmp - file-after || exit 1 --- file1 1 :a 2 :b ... 11 :c 12 :d EOF cat << EOF | cmp - hunk-after || exit 1 --- file1 10 :c 11 :d EOF patchutils-0.4.2/tests/number3/000077500000000000000000000000001370426545100164215ustar00rootroot00000000000000patchutils-0.4.2/tests/number3/run-test000077500000000000000000000011641370426545100201320ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -1,3 +1,3 @@ -Damaged patch (before) +Damaged patch (after) Previous line is damaged EOF ${FILTERDIFF} --as-numbered-lines=before diff \ 2>errors >file-before || exit 1 ${FILTERDIFF} --as-numbered-lines=after diff \ 2>>errors >file-after || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - file-before || exit 1 --- file1 1 :Damaged patch (before) 2 : 3 :Previous line is damaged EOF cat << EOF | cmp - file-after || exit 1 +++ file1 1 :Damaged patch (after) 2 : 3 :Previous line is damaged EOF patchutils-0.4.2/tests/overstrip/000077500000000000000000000000001370426545100171035ustar00rootroot00000000000000patchutils-0.4.2/tests/overstrip/run-test000077500000000000000000000006151370426545100206140ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: --strip behaves when stripping more pathname components than there are. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file +++ dir/file @@ -1 +1 @@ -a +A EOF ${FILTERDIFF} --strip=2 diff 2>errors >diff-stripped || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - diff-stripped || exit 1 --- file +++ file @@ -1 +1 @@ -a +A EOF patchutils-0.4.2/tests/patchview1/000077500000000000000000000000001370426545100171215ustar00rootroot00000000000000patchutils-0.4.2/tests/patchview1/run-test000077500000000000000000000005771370426545100206410ustar00rootroot00000000000000#!/bin/sh # This is a patchview(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file1 +++ file1 @@ -0,0 +1 @@ +a --- orig/file2 +++ file2 @@ -0,0 +1 @@ +a --- file3 +++ file3.orig @@ -0,0 +1 @@ +a EOF ${PATCHVIEW} diff 2>errors >index || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - index || exit 1 File #1 file1 File #2 file2 File #3 file3 EOF patchutils-0.4.2/tests/patchview2/000077500000000000000000000000001370426545100171225ustar00rootroot00000000000000patchutils-0.4.2/tests/patchview2/run-test000077500000000000000000000005141370426545100206310ustar00rootroot00000000000000#!/bin/sh # This is a patchview(1) testcase. # Test: Handle binary diff chunk headers . ${top_srcdir-.}/tests/common.sh /usr/bin/echo -ne "\ --- a/file1 +++ b/file1 @@ -1 +1,2 @@ The '\0' (NUL) character a +b " >diff ${PATCHVIEW} diff --filter 2>errors >filtered || exit 1 [ -s errors ] && exit 1 cmp diff filtered || exit 1 patchutils-0.4.2/tests/preserve1/000077500000000000000000000000001370426545100167625ustar00rootroot00000000000000patchutils-0.4.2/tests/preserve1/run-test000077500000000000000000000007041370426545100204720ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Preserve text after '@@' in unified input. . ${top_srcdir-.}/tests/common.sh cat << EOF > diff --- file.orig +++ file @@ -0,0 +1 @@ line 1 +a @@ -5 +6 @@ line 6 -a +b @@ -9 +10 @@ line 10 -a +b EOF ${FILTERDIFF} -#2,3 diff 2>errors >filtered || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - filtered || exit 1 --- file.orig +++ file @@ -5 +5 @@ line 6 -a +b @@ -9 +9 @@ line 10 -a +b EOF patchutils-0.4.2/tests/recount1/000077500000000000000000000000001370426545100166065ustar00rootroot00000000000000patchutils-0.4.2/tests/recount1/run-test000077500000000000000000000003761370426545100203230ustar00rootroot00000000000000#!/bin/sh # This is a recountdiff(1) testcase. # Test: Make no change. . ${top_srcdir-.}/tests/common.sh echo a > a.orig echo A > a ${DIFF} -u a.orig a > patch1 ${RECOUNTDIFF} patch1 > patch1-recounted || exit 1 cmp patch1 patch1-recounted || exit 1 patchutils-0.4.2/tests/recount2/000077500000000000000000000000001370426545100166075ustar00rootroot00000000000000patchutils-0.4.2/tests/recount2/run-test000077500000000000000000000007731370426545100203250ustar00rootroot00000000000000#!/bin/sh # This is a recountdiff(1) testcase. # Test: Test that it works. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- file --- file -- fooled you! +++ file @@ -1 +1 @@ -1 +2 +3 @@ -10 +10 @@ -1 +1 --- otherfile +++ otherfile @@ -1 +1,2 @@ 1 -1 +2 EOF ${RECOUNTDIFF} patch > patch-recounted || exit 1 cat << EOF | cmp - patch-recounted || exit 1 --- file --- file -- fooled you! +++ file @@ -1 +1,2 @@ -1 +2 +3 @@ -10 +11 @@ -1 +1 --- otherfile +++ otherfile @@ -1,2 +1,2 @@ 1 -1 +2 EOF patchutils-0.4.2/tests/recount3/000077500000000000000000000000001370426545100166105ustar00rootroot00000000000000patchutils-0.4.2/tests/recount3/run-test000077500000000000000000000011721370426545100203200ustar00rootroot00000000000000#!/bin/sh # This is a recountdiff(1) testcase. # Test: Test that '\' lines are handled correctly. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- file +++ file @@ -1 +1 @@ -1 \ No newline at end of file +2 +3 @@ -10 +10 @@ -1 +1 --- otherfile +++ otherfile @@ -1 +1,2 @@ 1 -1 +2 \ No newline at end of file @@ -10 +10 @@ -1 +1 EOF ${RECOUNTDIFF} patch > patch-recounted || exit 1 cat << EOF | cmp - patch-recounted || exit 1 --- file +++ file @@ -1 +1,2 @@ -1 \ No newline at end of file +2 +3 @@ -10 +11 @@ -1 +1 --- otherfile +++ otherfile @@ -1,2 +1,2 @@ 1 -1 +2 \ No newline at end of file @@ -10 +10 @@ -1 +1 EOF patchutils-0.4.2/tests/recount4/000077500000000000000000000000001370426545100166115ustar00rootroot00000000000000patchutils-0.4.2/tests/recount4/run-test000077500000000000000000000007361370426545100203260ustar00rootroot00000000000000#!/bin/sh # This is a recountdiff(1) testcase. # Test: Test that empty hunks work. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- file +++ file @@ -1 +1 @@ -1 @@ -10 +10 @@ -1 +1 --- otherfile +++ otherfile @@ -1 +1 @@ +2 @@ -10 +10 @@ -1 +1 EOF ${RECOUNTDIFF} patch > patch-recounted || exit 1 cat << EOF | cmp - patch-recounted || exit 1 --- file +++ file @@ -1 +0,0 @@ -1 @@ -10 +9 @@ -1 +1 --- otherfile +++ otherfile @@ -0,0 +1 @@ +2 @@ -10 +11 @@ -1 +1 EOF patchutils-0.4.2/tests/recount5/000077500000000000000000000000001370426545100166125ustar00rootroot00000000000000patchutils-0.4.2/tests/recount5/run-test000077500000000000000000000007601370426545100203240ustar00rootroot00000000000000#!/bin/sh # This is a recountdiff(1) testcase. # Test: Avoid a bug in handling '\' lines. . ${top_srcdir-.}/tests/common.sh cat <<"EOF" > patch --- file +++ file @@ -1 +1 @@ -\ +1 @@ -10 +10 @@ -1 +1 --- otherfile +++ otherfile @@ -1 +1 @@ -\ +1 @@ -10 +10 @@ -1 +1 EOF ${RECOUNTDIFF} patch > patch-recounted || exit 1 cat <<"EOF" | cmp - patch-recounted || exit 1 --- file +++ file @@ -1 +1 @@ -\ +1 @@ -10 +10 @@ -1 +1 --- otherfile +++ otherfile @@ -1 +1 @@ -\ +1 @@ -10 +10 @@ -1 +1 EOF patchutils-0.4.2/tests/recount6/000077500000000000000000000000001370426545100166135ustar00rootroot00000000000000patchutils-0.4.2/tests/recount6/run-test000077500000000000000000000005441370426545100203250ustar00rootroot00000000000000#!/bin/sh # This is a recountdiff(1) testcase. # Test: Avoid a bug in handling entirely-added files. . ${top_srcdir-.}/tests/common.sh cat <<"EOF" > patch --- file +++ file @@ -0,0 +1,15 @@ +1 +2 +3 +4 EOF ${RECOUNTDIFF} patch > patch-recounted || exit 1 cat <<"EOF" | cmp - patch-recounted || exit 1 --- file +++ file @@ -0,0 +1,4 @@ +1 +2 +3 +4 EOF patchutils-0.4.2/tests/recount7/000077500000000000000000000000001370426545100166145ustar00rootroot00000000000000patchutils-0.4.2/tests/recount7/run-test000077500000000000000000000006731370426545100203310ustar00rootroot00000000000000#!/bin/sh # This is a recountdiff(1) testcase. # Test: Avoid a bug in handling entirely-added files. . ${top_srcdir-.}/tests/common.sh cat <<"EOF" > patch --- file +++ file @@ -389,5 +398,6 @@ while (1) ; + # not needed # at all # stop EOF ${RECOUNTDIFF} patch > patch-recounted || exit 1 cat <<"EOF" | cmp - patch-recounted || exit 1 --- file +++ file @@ -389,6 +389,7 @@ while (1) ; + # not needed # at all # stop EOF patchutils-0.4.2/tests/rediff1/000077500000000000000000000000001370426545100163665ustar00rootroot00000000000000patchutils-0.4.2/tests/rediff1/run-test000077500000000000000000000006341370426545100201000ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Remove all original lines in a hunk. . ${top_srcdir-.}/tests/common.sh cat << "EOF" > patch.orig --- file +++ file @@ -3,3 +3,4 @@ 1 2 3 +4.5 EOF cat << "EOF" > patch.mod --- file +++ file @@ -3,3 +3,4 @@ +4.5 EOF ${REDIFF} patch.orig patch.mod > patch-rediffed || exit 1 cmp - patch-rediffed << "EOF" || exit 1 --- file +++ file @@ -6,0 +6 @@ +4.5 EOF patchutils-0.4.2/tests/rediff2/000077500000000000000000000000001370426545100163675ustar00rootroot00000000000000patchutils-0.4.2/tests/rediff2/run-test000077500000000000000000000011041370426545100200720ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Don't segfault when changes are made outside the diff. . ${top_srcdir-.}/tests/common.sh cat << "EOF" > patch.orig Index: file =================================================================== --- file +++ file @@ -3,3 +3,4 @@ 1 2 3 +4.5 EOF cat << "EOF" > patch.mod # this change is invalid Index: file =================================================================== --- file +++ file @@ -3,3 +3,4 @@ 1 2 3 +4.5 EOF ${REDIFF} patch.orig patch.mod > patch-rediffed 2>stderr && exit 1 [ $? = 1 ] || exit 1 exit 0 patchutils-0.4.2/tests/rediff3/000077500000000000000000000000001370426545100163705ustar00rootroot00000000000000patchutils-0.4.2/tests/rediff3/run-test000077500000000000000000000012301370426545100200730ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Adjust offsets correctly . ${top_srcdir-.}/tests/common.sh cat << "EOF" > patch.orig --- /tmp/a 2019-11-28 12:34:20.222622166 +0000 +++ /tmp/b 2019-11-28 12:34:51.932803492 +0000 @@ -1,7 +1,7 @@ 1 -2 +3 3 4 5 6 -7 +8 EOF cat << "EOF" > patch.mod --- /tmp/a 2019-11-28 12:34:20.222622166 +0000 +++ /tmp/b 2019-11-28 12:34:51.932803492 +0000 @@ -1,7 +1,7 @@ 4 5 6 -7 +8 EOF ${REDIFF} patch.orig patch.mod > patch-rediffed || exit 1 cmp - patch-rediffed << "EOF" || exit 1 --- /tmp/a 2019-11-28 12:34:20.222622166 +0000 +++ /tmp/b 2019-11-28 12:34:51.932803492 +0000 @@ -4,4 +4,4 @@ 4 5 6 -7 +8 EOF patchutils-0.4.2/tests/revert1/000077500000000000000000000000001370426545100164365ustar00rootroot00000000000000patchutils-0.4.2/tests/revert1/run-test000077500000000000000000000005431370426545100201470ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir cat << EOF > dir/file.orig a b c EOF cat << EOF > dir/file a b EOF cat << EOF > patch2 EOF ${DIFF} -u dir/file.orig dir/file > patch1 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 cd dir ${PATCH} < ../patch1-2 || exit 1 cd .. cmp dir/file.orig dir/file || exit 1 patchutils-0.4.2/tests/revert2/000077500000000000000000000000001370426545100164375ustar00rootroot00000000000000patchutils-0.4.2/tests/revert2/run-test000077500000000000000000000006131370426545100201460ustar00rootroot00000000000000#!/bin/sh . ${top_srcdir-.}/tests/common.sh mkdir dir cat << EOF > dir/file.orig a b c d e f g h i j k l m EOF cat << EOF > dir/file A b c d e f g h i j k l EOF cat << EOF > patch2 EOF ${DIFF} -u dir/file.orig dir/file > patch1 ${INTERDIFF} patch1 patch2 2>errors > patch1-2 || exit 1 [ -s errors ] && exit 1 cd dir ${PATCH} < ../patch1-2 || exit 1 cd .. cmp dir/file.orig dir/file || exit 1 patchutils-0.4.2/tests/select1/000077500000000000000000000000001370426545100164065ustar00rootroot00000000000000patchutils-0.4.2/tests/select1/run-test000077500000000000000000000014371370426545100201220ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Unified format, filename pattern but no selector . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- a.orig +++ a @@ -1 +1 @@ -a +b --- b.orig +++ b @@ -1 +1 @@ -a +b --- c.orig +++ c @@ -1 +1 @@ -a +b EOF ${FILTERDIFF} -i b selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 --- b.orig +++ b @@ -1 +1 @@ -a +b EOF cat << EOF > patterns no match EOF ${FILTERDIFF} -I patterns selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 EOF cat << EOF > patterns not-a b not-c EOF ${FILTERDIFF} -I patterns selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 --- b.orig +++ b @@ -1 +1 @@ -a +b EOF patchutils-0.4.2/tests/select10/000077500000000000000000000000001370426545100164665ustar00rootroot00000000000000patchutils-0.4.2/tests/select10/run-test000077500000000000000000000015401370426545100201750ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Unified format, filename exclude pattern but no selector . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- a.orig +++ a @@ -1 +1 @@ -a +b --- b.orig +++ b @@ -1 +1 @@ -a +b --- c.orig +++ c @@ -1 +1 @@ -a +b EOF ${FILTERDIFF} -x b selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 --- a.orig +++ a @@ -1 +1 @@ -a +b --- c.orig +++ c @@ -1 +1 @@ -a +b EOF cat << EOF > patterns no match EOF ${FILTERDIFF} -X patterns selected 2>errors || exit 1 [ -s errors ] && exit 1 cmp patch selected || exit 1 cat << EOF > patterns not-a b not-c EOF ${FILTERDIFF} -X patterns selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 --- a.orig +++ a @@ -1 +1 @@ -a +b --- c.orig +++ c @@ -1 +1 @@ -a +b EOF patchutils-0.4.2/tests/select11/000077500000000000000000000000001370426545100164675ustar00rootroot00000000000000patchutils-0.4.2/tests/select11/run-test000077500000000000000000000020441370426545100201760ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Context format, filename exclude pattern but no selector . ${top_srcdir-.}/tests/common.sh cat << EOF > patch *** a.orig --- a *************** *** 1 **** ! a --- 1 ---- ! b *** b.orig --- b *************** *** 1 **** ! a --- 1 ---- ! b *** c.orig --- c *************** *** 1 **** ! a --- 1 ---- ! b EOF ${FILTERDIFF} -x b selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 *** a.orig --- a *************** *** 1 **** ! a --- 1 ---- ! b *** c.orig --- c *************** *** 1 **** ! a --- 1 ---- ! b EOF cat << EOF > patterns no match EOF ${FILTERDIFF} -X patterns selected 2>errors || exit 1 [ -s errors ] && exit 1 cmp patch selected || exit 1 cat << EOF > patterns not-a b not-c EOF ${FILTERDIFF} -X patterns selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 *** a.orig --- a *************** *** 1 **** ! a --- 1 ---- ! b *** c.orig --- c *************** *** 1 **** ! a --- 1 ---- ! b EOF patchutils-0.4.2/tests/select2/000077500000000000000000000000001370426545100164075ustar00rootroot00000000000000patchutils-0.4.2/tests/select2/run-test000077500000000000000000000016531370426545100201230ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Context format, filename pattern but no selector . ${top_srcdir-.}/tests/common.sh cat << EOF > patch *** a.orig --- a *************** *** 1 **** ! a --- 1 ---- ! b *** b.orig --- b *************** *** 1 **** ! a --- 1 ---- ! b *** c.orig --- c *************** *** 1 **** ! a --- 1 ---- ! b EOF ${FILTERDIFF} -i b selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 *** b.orig --- b *************** *** 1 **** ! a --- 1 ---- ! b EOF cat << EOF > patterns no match EOF ${FILTERDIFF} -I patterns selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 EOF cat << EOF > patterns not-a b not-c EOF ${FILTERDIFF} -I patterns selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 *** b.orig --- b *************** *** 1 **** ! a --- 1 ---- ! b EOF patchutils-0.4.2/tests/select3/000077500000000000000000000000001370426545100164105ustar00rootroot00000000000000patchutils-0.4.2/tests/select3/run-test000077500000000000000000000006651370426545100201260ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Unified format, line selector but no filename pattern . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- a.orig +++ a @@ -1 +1 @@ -a +b --- b.orig +++ b @@ -2 +2 @@ -a +b --- c.orig +++ c @@ -3 +3 @@ -a +b EOF ${FILTERDIFF} --lines=2 selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 --- b.orig +++ b @@ -2 +2 @@ -a +b EOF patchutils-0.4.2/tests/select4/000077500000000000000000000000001370426545100164115ustar00rootroot00000000000000patchutils-0.4.2/tests/select4/run-test000077500000000000000000000010451370426545100201200ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Context format, line selector but no filename pattern . ${top_srcdir-.}/tests/common.sh cat << EOF > patch *** a.orig --- a *************** *** 1 **** ! a --- 1 ---- ! b *** b.orig --- b *************** *** 2 **** ! a --- 2 ---- ! b *** c.orig --- c *************** *** 3 **** ! a --- 3 ---- ! b EOF ${FILTERDIFF} --lines=2 selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 *** b.orig --- b *************** *** 2 **** ! a --- 2 ---- ! b EOF patchutils-0.4.2/tests/select5/000077500000000000000000000000001370426545100164125ustar00rootroot00000000000000patchutils-0.4.2/tests/select5/run-test000077500000000000000000000007031370426545100201210ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Unified format, --hunks but no -i or -x. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- a.orig +++ a @@ -1 +1 @@ -a +b --- b.orig +++ b @@ -2 +2,2 @@ -a +b +c @@ -50 +51 @@ -a +b --- c.orig +++ c @@ -3 +3 @@ -a +b EOF ${FILTERDIFF} --hunks=2 selected 2>errors || exit 2 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 --- b.orig +++ b @@ -50 +50 @@ -a +b EOF patchutils-0.4.2/tests/select6/000077500000000000000000000000001370426545100164135ustar00rootroot00000000000000patchutils-0.4.2/tests/select6/run-test000077500000000000000000000010771370426545100201270ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Context format, --hunks but no -i or -x . ${top_srcdir-.}/tests/common.sh cat << EOF > patch *** a.orig --- a *************** *** 1 **** ! a --- 1 ---- ! b *** b.orig --- b *************** *** 2 **** ! a --- 2,3 ---- ! b + c *** 50 **** ! a --- 51 ---- ! b *** c.orig --- c *************** *** 3 **** ! a --- 3 ---- ! b EOF ${FILTERDIFF} --hunks=2 selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 *** b.orig --- b *************** *** 50 **** ! a --- 50 ---- ! b EOF patchutils-0.4.2/tests/select7/000077500000000000000000000000001370426545100164145ustar00rootroot00000000000000patchutils-0.4.2/tests/select7/run-test000077500000000000000000000007251370426545100201270ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Unified format, filename pattern and hunk selector . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- a.orig +++ a @@ -1 +1 @@ -a +b --- b.orig +++ b @@ -2 +2,2 @@ -a +b +c @@ -50 +51 @@ -a +b --- c.orig +++ c @@ -3 +3 @@ -a +b EOF ${FILTERDIFF} -i b --hunks=1 selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 --- b.orig +++ b @@ -2 +2,2 @@ -a +b +c EOF patchutils-0.4.2/tests/select8/000077500000000000000000000000001370426545100164155ustar00rootroot00000000000000patchutils-0.4.2/tests/select8/run-test000077500000000000000000000007121370426545100201240ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Unified format, --as-numbered-lines=before . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- a.orig +++ a @@ -1 +1 @@ -a +b --- b.orig +++ b @@ -2 +2,2 @@ -a +b +c @@ -50 +51 @@ -a +b --- c.orig +++ c @@ -3 +3 @@ -a +b EOF ${FILTERDIFF} --as-numbered-lines=before -i b -#1 selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 --- b.orig 2 :a EOF patchutils-0.4.2/tests/select9/000077500000000000000000000000001370426545100164165ustar00rootroot00000000000000patchutils-0.4.2/tests/select9/run-test000077500000000000000000000007101370426545100201230ustar00rootroot00000000000000#!/bin/sh # This is a filterdiff(1) testcase. # Test: Unified format, --as-numbered-lines=after . ${top_srcdir-.}/tests/common.sh cat << EOF > patch --- a.orig +++ a @@ -1 +1 @@ -a +b --- b.orig +++ b @@ -2 +2,2 @@ -a +b +c @@ -50 +51 @@ -a +b --- c.orig +++ c @@ -3 +3 @@ -a +b EOF ${FILTERDIFF} --as-numbered-lines=after -i b -#1 selected 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - selected || exit 1 +++ b 2 :b 3 :c EOF patchutils-0.4.2/tests/soak-test000077500000000000000000000006661370426545100167160ustar00rootroot00000000000000#!/bin/sh set -x set -e rm -rf linux tar zxf ~/download/linux-2.5.0.tar.gz ( cd linux ; patch -sp1 < ../patch-2.5.1-pre3 ) for n in 3 4 # 5 6 7 8 9 10 11 12 do ../interdiff -U0 patch-2.5.1-pre$n \ patch-2.5.1-pre$((1+$n)) | (cd linux; patch -sp1) rm -rf staging mkdir staging (cd staging; tar zxf ~/download/linux-2.5.0.tar.gz) cat patch-2.5.1-pre$((1+$n)) | \ (cd staging/linux; patch -sp1) diff -ur linux staging/linux done patchutils-0.4.2/tests/splitdiffD/000077500000000000000000000000001370426545100171365ustar00rootroot00000000000000patchutils-0.4.2/tests/splitdiffD/run-test000077500000000000000000000006241370426545100206470ustar00rootroot00000000000000#!/bin/sh # This is a splitdiff(1) testcase. # Test: See if -D works. . ${top_srcdir-.}/tests/common.sh mkdir dir dir.orig echo a > dir.orig/a echo A > dir/a echo b > dir.orig/b echo B > dir/b ${DIFF} -uN dir.orig dir > diff ${SPLITDIFF} -a -D split diff 2>errors >output || exit 1 [ -s errors ] && exit 1 [ -d split ] || exit 1 [ -f split/dir_a.patch ] || exit 1 [ -f split/dir_b.patch ] || exit 1 patchutils-0.4.2/tests/stdin/000077500000000000000000000000001370426545100161675ustar00rootroot00000000000000patchutils-0.4.2/tests/stdin/run-test000077500000000000000000000012551370426545100177010ustar00rootroot00000000000000#!/bin/sh # This is an interdiff(1) testcase. # Test: Test taking files in on stdin. . ${top_srcdir-.}/tests/common.sh cat << EOF > orig a b c EOF cat << EOF > new1 a b EOF cat << EOF > new2 a b d EOF ${DIFF} -u orig new1 > patch1 ${DIFF} -u orig new2 > patch2 ${INTERDIFF} patch1 patch2 2>errors > patch1-2.good || exit 1 [ -s errors ] && exit 1 ${INTERDIFF} patch1 - < patch2 2>errors > patch1-2.1 || exit 1 [ -s errors ] && exit 1 ${INTERDIFF} - patch2 < patch1 2>errors > patch1-2.2 || exit 1 [ -s errors ] && exit 1 cmp patch1-2.good patch1-2.1 || exit 1 cmp patch1-2.good patch1-2.2 || exit 1 # 2 stdins fail: ${INTERDIFF} - - < patch1 2>errors > patch1-1 && exit 1 || true patchutils-0.4.2/tests/trimcontext1/000077500000000000000000000000001370426545100175075ustar00rootroot00000000000000patchutils-0.4.2/tests/trimcontext1/run-test000077500000000000000000000010351370426545100212150ustar00rootroot00000000000000#!/bin/sh # This is a rediff(1) testcase. # Test: Trim context from beginning and end of hunk. . ${top_srcdir-.}/tests/common.sh cat << EOF > original-patch --- file.orig +++ file @@ -6,7 +6,7 @@ trim me blah blah -not +important blah blah trim me EOF sed -e '/^ trim me$/d' original-patch > edited-patch ${REDIFF} original-patch edited-patch 2>errors >rediffed-patch || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - rediffed-patch || exit 1 --- file.orig +++ file @@ -7,5 +7,5 @@ blah blah -not +important blah blah EOF patchutils-0.4.2/tests/trimlast1/000077500000000000000000000000001370426545100167665ustar00rootroot00000000000000patchutils-0.4.2/tests/trimlast1/run-test000077500000000000000000000010511370426545100204720ustar00rootroot00000000000000#!/bin/sh # This is an interdiff(1) testcase. # Test: Final hunk should retain 'earlier' context. # https://fedorahosted.org/patchutils/ticket/32 . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- file.orig +++ file @@ -1,7 +1,7 @@ 1 2 3 -3 +4 5 6 7 EOF cat < patch2 --- file.orig +++ file @@ -1,8 +1,9 @@ 1 2 3 -3 +4 5 6 7 8 +9 EOF ${INTERDIFF} patch1 patch2 > patch1-2 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - patch1-2 || exit 1 diff -u file file --- file +++ file @@ -6,3 +6,4 @@ 6 7 8 +9 EOF patchutils-0.4.2/tests/trimlast2/000077500000000000000000000000001370426545100167675ustar00rootroot00000000000000patchutils-0.4.2/tests/trimlast2/run-test000077500000000000000000000010701370426545100204740ustar00rootroot00000000000000#!/bin/sh # This is an combinediff(1) testcase. # Test: Final hunk should retain 'earlier' context. # https://fedorahosted.org/patchutils/ticket/32 . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- file.orig +++ file @@ -1,7 +1,7 @@ -0 +1 2 3 4 5 6 7 EOF cat < patch2 --- file.orig +++ file @@ -6,3 +6,4 @@ 6 7 8 +9 EOF ${COMBINEDIFF} patch1 patch2 > patch12 2>errors || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - patch12 || exit 1 diff -u file file --- file +++ file @@ -1,4 +1,4 @@ -0 +1 2 3 4 @@ -6,3 +6,4 @@ 6 7 8 +9 EOF patchutils-0.4.2/tests/unline1/000077500000000000000000000000001370426545100164215ustar00rootroot00000000000000patchutils-0.4.2/tests/unline1/run-test000077500000000000000000000006321370426545100201310ustar00rootroot00000000000000#!/bin/sh # This is an interdiff(1) testcase. . ${top_srcdir-.}/tests/common.sh cat << EOF > patch1 --- file.orig +++ file @@ -1 +1 @@ -a +A EOF cat << EOF > patch2 --- file.orig +++ file @@ -10 +10 @@ -a +A EOF ${INTERDIFF} patch1 patch2 > patch1-2 2>errors || exit 1 [ -s errors ] && exit 1 cmp - patch1-2 << EOF || exit 1 diff -u file file --- file +++ file @@ -1 +1 @@ -A +a @@ -10 +10 @@ -a +A EOF patchutils-0.4.2/tests/unwrapdiff1/000077500000000000000000000000001370426545100172745ustar00rootroot00000000000000patchutils-0.4.2/tests/unwrapdiff1/run-test000077500000000000000000000017561370426545100210140ustar00rootroot00000000000000#!/bin/sh # This is an unwrapdiff(1) testcase. # Test: To see if it works at all. . ${top_srcdir-.}/tests/common.sh cat < patch1 --- file date wrapped +++ file date wrapped @@ -1 +1 @@ -long line that wraps because it is so long +other line EOF ${UNWRAPDIFF} patch1 > patch1-unwrapped || exit 1 cat < patch2 --- file +++ file @@ -1,3 +1,3 @@ does this work? unchanged -these two lines are changed -and this one has a line of **************** ********s +This is changed. +So is this one but this wrap is ambiguous. EOF ${UNWRAPDIFF} patch2 > patch2-unwrapped || exit 1 cat < diff --- file1 +++ file1 @@ -1,2 +1,2 @@ -A +a EOF # When detecting whitespace damage in the input, an error should be # written and the program should terminate with a non-zero exit code. ${INTERDIFF} -qp1 diff diff 2>errors && exit 1 [ -s errors ] || exit 1