Commit ac1a9bc2 authored by Jari Aalto's avatar Jari Aalto

New upstream version 0.0+20160815+git13c5941

parent 2b99115b
*.patch*
#!/usr/bin/make -f
#
# Copyright
#
# Copyright (C) 2014 Jari Aalto <jari.aalto@cante.net>
#
# License
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Description
#
# A Ruby program. Nothing to compile
ifneq (,)
This makefile requires GNU Make.
endif
PACKAGE = splitpatch
VERSION =
DESTDIR =
prefix = /usr
exec_prefix = $(prefix)
man_prefix = $(prefix)/share
mandir = $(man_prefix)/man
bindir = $(exec_prefix)/bin
sharedir = $(prefix)/share
BINDIR = $(DESTDIR)$(bindir)
DOCDIR = $(DESTDIR)$(sharedir)/doc
# 1 = regular, 5 = conf, 6 = games, 8 = daemons
MANDIR = $(DESTDIR)$(mandir)
MANDIR1 = $(MANDIR)/man1
INSTALL = /usr/bin/install
INSTALL_BIN = $(INSTALL) -m 755
INSTALL_DATA = $(INSTALL) -m 644
INSTALL_SUID = $(INSTALL) -m 4755
SRCS = $(PACKAGE).rb
all: doc
clean:
# clean
-rm -f *[#~] *.\#*
$(MAKE) -C man $@
distclean: clean
realclean: clean
doc:
$(MAKE) -C man all
install-man: doc
# install-man
$(INSTALL_BIN) -d $(MANDIR1)
$(INSTALL_DATA) man/*.1 $(MANDIR1)
install-bin:
# install-bin
$(INSTALL_BIN) -d $(BINDIR)
$(INSTALL_BIN) $(PACKAGE).rb $(BINDIR)/$(PACKAGE)
install: install-bin install-man
.PHONY: all doc
.PHONY: clean distclean realclean install install-bin install-man
# End of file
......@@ -4,5 +4,12 @@ splitpatch
A utility to split a diff patch into separate sections
For full details on how to use the utility see:
http://www.clearchain.com/blog/posts/splitting-a-patch
Upstream sources maintained at:
https://github.com/jaalto/splitpatch
Team upstream:
Maintainer <jari.aalto@cante.net>
Original Developer <peter.hutterer@who-t.net>
Original Developer <Benjamin.Close@clearchain.com>
#!/usr/bin/make -f
#
# Copyright
#
# Copyright (C) 2014 Jari Aalto <jari.aalto@cante.net>
#
# License
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Description
#
# Generate manual page form Perl POD file.
PACKAGE = splitpatch
all:
$(MAKE) -f pod2man.mk PACKAGE=$(PACKAGE) makeman
clean:
rm -f *.1
.PHONY: all
# End of file
# pod2man.mk -- Makefile portion to convert *.pod files to manual pages
#
# Copyright information
#
# Copyright (C) 2008-2013 Jari Aalto
#
# License
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Description
#
# Convert *.pod files to manual pages. Write this to 'install'
# target:
#
# install: build $(MANPAGE)
ifneq (,)
This makefile requires GNU Make.
endif
# This variable *must* be set when calling
PACKAGE ?= package
RELEASE ?= $(PACKAGE)
# Optional variables to set
MANSECT ?= 1
PODCENTER ?= $$(date "+%Y-%m-%d")
# Directories
MANSRC =
MANDEST = $(MANSRC)
MANPOD = $(MANSRC)$(PACKAGE).$(MANSECT).pod
MANPAGE = $(MANDEST)$(PACKAGE).$(MANSECT)
POD2MAN = pod2man
POD2MAN_FLAGS = --utf8
makeman: $(MANPAGE)
$(MANPAGE): $(MANPOD)
# make target - create manual page from a *.pod page
podchecker $(MANPOD)
LC_ALL=C $(POD2MAN) $(POD2MAN_FLAGS) \
--center="$(PODCENTER)" \
--name="$(PACKAGE)" \
--section="$(MANSECT)" \
--release="$(RELEASE)" \
$(MANPOD) \
> $(MANPAGE) && \
rm -f pod*.tmp
# End of of Makefile part
# Copyright
#
# Copyright (C) 2013-2014 Jari Aalto
#
# License
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Description
#
# To learn what TOP LEVEL sections to use in manual page,
# see POSIX/Susv standard about "Utility Description Defaults" at
# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap01.html#tag_01_11
#
# This manual page in Perl POD format. Read more at
# http://perldoc.perl.org/perlpod.html or run command:
#
# perldoc perlpod | less
#
# To check the syntax:
#
# podchecker *.pod
#
# To create manual:
#
# pod2man PROGRAM.N.pod > PROGRAM.N
=pod
=head1 NAME
splitpatch - split a patch up into files or hunks
=head1 SYNOPSIS
splitpatch [options]
=head1 DESCRIPTION
Divide a patch or diff file into pieces. The split can made by file
or by hunk basis. This makes is possible to separate changes that
might not be desirable, or assemble a patch into more coherent set
of changes.
The hunk option makes it possible to compare similar patches on a
hunk-by-hunk basis using a tool like interdiff(1) from the patchutils package.
=head1 OPTIONS
=over 4
=item B<-H, --hunk, --hunks>
Split patch by hunks instead of the default: by file.
=item B<-h, --help>
Display help and exit
=item B<-V, --version>
Output version information and exit.
=back
=head1 EXAMPLES
Have you ever been working on code, gone off on a side tangent and
then realized you don't have a patch for the original issue you
set out to address? When you run C<diff -u> or some other diff command,
you discover that you have made multiple sets of changes; some
you want to submit, others you don't. What you really want to do is
break those changes apart and apply only the ones you want. This is
where splitpatch comes into play, breaking up the patch by source file:
splitpatch changes.patch
Or to split the patch file into individual hunks which can later be
applied using the patch(1) command:
splitpatch --hunks changes.patch
=head1 ENVIRONMENT
None.
=head1 FILES
The B<--hunk> option writes sequentially numbered files in the current
directory named for the source file to be patched followed by the
sequence number: C<*-NNN.patch>.
Otherwise, the split patch files are named by the source file being
patched.
=head1 STANDARDS
None.
=head1 AVAILABILITY
https://github.com/benjsc/splitpatch
=head1 SEE ALSO
dehtmldiff(1)
editdiff(1)
filterdiff(1)
fixcvsdiff(1)
flipdiff(1)
grepdiff(1)
interdiff(1)
lsdiff(1)
patch(1)
recountdiff(1)
rediff(1)
splitdiff(1)
unwrapdiff(1)
wiggle(1)
=head1 AUTHORS
Program was written by Peter Hutterer <peter.hutterer@who-t.net>,
Benjamin Close <Benjamin.Close@clearchain.com>. Enhancements by
Jari Aalto <jari.aalto@cante.net>.
This manual page was written by Jari Aalto <jari.aalto@cante.net>.
Released under license GNU GPL version 2 or (at your option) any later
version. For more information about the license, visit
<http://www.gnu.org/copyleft/gpl.html>.
=cut
......@@ -2,7 +2,9 @@
#
# Copyright
#
# Copyright (C) 2007 Peter Hutterer <peter@cs.unisa.edu.au>
# Copyright (C) 2014 Jari Aalto <jari.aalto@cante.net>
# Copyright (C) 2007-2014 Peter Hutterer <peter.hutterer@who-t.net>
# Copyright (C) 2007-2014 Benjamin Close <Benjamin.Close@clearchain.com>
#
# License
#
......@@ -21,6 +23,11 @@
#
# Description
#
PROGRAM = "splitpatch"
MYVERSION = 1.0
LICENSE = "GPL-2+" # See official acronyms: https://spdx.org/licenses/
HOMEPAGE = "https://github.com/jaalto/splitpatch"
# Splitpatch is a simple script to split a patch up into
# multiple patch files. If the --hunks option is provided on the
# command line, each hunk gets its own patchfile.
......@@ -43,10 +50,12 @@ class Splitter
if File.exists?(filename)
puts "File #{filename} already exists. Renaming patch."
appendix = 0
while File.exists?("#{filename}.#{appendix}")
zero = appendix.to_s.rjust(3, '0')
while File.exists?("#{filename}.#{zero}")
appendix += 1
zero = appendix.to_s.rjust(3, '0')
end
filename << ".#{appendix}"
filename << ".#{zero}"
end
return open(filename, "w")
end
......@@ -66,7 +75,7 @@ class Splitter
def splitByFile
legacy = false
outfile = nil
stream = open(@filename)
stream = open(@filename, 'rb')
until (stream.eof?)
line = stream.readline
......@@ -102,7 +111,7 @@ class Splitter
def splitByHunk
legacy = false
outfile = nil
stream = open(@filename)
stream = open(@filename, 'rb')
filename = ""
counter = 0
header = ""
......@@ -134,7 +143,9 @@ class Splitter
if (outfile)
outfile.close_write
end
hunkfilename = "#{filename}.#{counter}.patch"
zero = counter.to_s.rjust(3, '0')
hunkfilename = "#{filename}.#{zero}.patch"
outfile = createFile(hunkfilename)
counter += 1
......@@ -150,37 +161,92 @@ class Splitter
end
def help
puts <<EOF
SYNOPSIS
#{PROGRAM} [options] FILE.patch
######################## MAIN ########################
if ARGV.length < 1 or ARGV.length > 3
puts "Wrong parameter. Usage: splitpatch.rb [--fullname] [--hunks] <patchfile>"
exit 1
elsif ARGV[0] == "--help"
puts "splitpatch splits a patch that is supposed to patch multiple files"
puts "into a set of patches."
puts "Currently splits unified diff patches."
puts "If the --hunk option is given, a new file is created for each hunk."
puts "If the --fullname option is given, new files are named using the"
puts "full path of the patch to avoid duplicates in large projects."
exit 1
else
s = Splitter.new(ARGV[-1])
if s.validFile?
if ARGV[0] == "--fullname" or ARGV[1] == "--fullname"
s.fullname(true)
end
OPTIONS
-h,--help
-H,--hunk
-V,--version
if ARGV[0] == "--hunks" or ARGV[1] == "--hunks"
s.splitByHunk
else
s.splitByFile
end
else
puts "File does not exist or is not readable"
DESCRIPTION
Split the patch up into files or hunks
Divide a patch or diff file into pieces. The split can made by file
or by hunk basis. This makes it possible to separate changes that
might not be desirable or assemble the patch into a more coherent set
of changes. See e.g. combinediff(1) from patchutils package.
Note: only patches in unified format are recognized.
AUTHORS
Peter Hutterer (orig. Author) <peter.hutterer@who-t.net>
Benjamin Close (orig. Author) <Benjamin.Close@clearchain.com>
Jari Aalto (Maintainer) <jari.aalto@cante.net>"
Homepage: #{HOMEPAGE}
EOF
end
def version
puts "#{MYVERSION} #{LICENSE} #{HOMEPAGE}"
end
def parsedOptions
if ARGV.length < 1 or ARGV.length > 2
puts "ERROR: missing argument. See --help."
exit 1
end
opts = {}
opt = ARGV[0]
case opt
when /^-h$/, /--help/
opts[:help] = true
when /^-H$/, /--hunks?/
opts[:hunk] = true
when /^-V$/, /--version/
opts[:version] = true
when /^-/
puts "ERROR: Unknown option: #{opt}. See --help."
exit 1
end
opts[:file] = ARGV[-1]
return opts
end
def main
opts = parsedOptions
if opts[:help]
help
exit
end
if opts[:version]
version
exit
end
s = Splitter.new(opts[:file])
if !s.validFile?
puts "File does not exist or is not readable: #{opts[:file]}"
end
if opts[:hunk]
s.splitByHunk
else
s.splitByFile
end
end
main
# End of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment