Can't apply unified diff patch on Solaris - diff

For example, if I have two files:
file1:
This is file 1
and file2:
This is file 2
and create patch with the following command:
diff -u file1 file2 > files.patch
result is:
--- file1 Fri Aug 13 17:53:28 2010
+++ file2 Fri Aug 13 17:53:38 2010
## -1,1 +1,1 ##
-This is file 1
+This is file 2
Then if I try to apply this patch on Solaris with patch command:
patch -u -i files.patch
it hangs on:
Looks like a unified context diff.
File to patch:
1. Is there a way to use Solaris native patch command with unified diffs?
2. Which diff format is considered most portable if it's not possible to apply unified format?
Update:
I've found answer on the first part of my question. Seems that patch on Solaris hangs if the second file (file2 in this case) exists in the same folder as the first one (file1). For example, the following quite common diff:
--- a/src/file.src Sat Aug 14 23:07:29 2010
+++ b/src/file.src Sat Aug 14 23:07:37 2010
## -1,2 +1,1 ##
-1
-
+2
will not work with quite common patch command:
patch -p1 -u -d a < file.patch
while the following diff (note second file is renamed):
--- a/src/file.src Sat Aug 14 23:07:29 2010
+++ b/src/file_new.src Sat Aug 14 23:07:37 2010
## -1,2 +1,1 ##
-1
-
+2
will work perfectly.
For the second part of my question see accepted answer below.

On Solaris /usr/bin/patch is an old version required to comply with some ancient standards.
A modern version of GNU patch is provided as /usr/bin/gpatch on Solaris 8 and later.

diff -cr old.new new.txt > patch.txt
gpatch -p0 < patch.txt
Works perfectly for me (using gpatch)

Single Unix v2 and v3 both support context diffs but not unified diffs, so for better portability you should use context diffs (-c option to diff and patch).
On older Solaris releases (pre-10, I think), you need to make sure that /usr/xpg4/bin is before /usr/bin in your $PATH, otherwise you may get compatibility versions of some utilities instead of standard ones.

Related

Update package version (openocd) in buildroot

I'm working in a project that uses buildroot-2012.11 to generate a Linux image for an embedded system.
I need to configure openocd for a JTAG debugger that uses an FTDI chip (FT2232D).
I realized that this buildroot version integrate openocd-0.5.0 and the latest openocd release is 0.9.0. I'm interested in updating to this version since I want to use ftdi interface driver instead of ft2232 (deprecated).
I tried to accomplish that by modifying /package/openocd/openocd.mk on the lines:
OPENOCD_VERSION:=0.9.0
OPENOCD_CONF_OPT += --enable-ftdi
The new openocd files where downloaded successfully but when it tries to install it and apply openocd-0001-fix-cross-compilation-host-libsub-was-used-before.patch I got:
Applying openocd-0001-fix-cross-compilation-host-libsub-was-used-before.patch using patch:
can't find file to patch at input line 17
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|From 3728c4af7f6303ccedab56ec220797f8f290580e Mon Sep 17 00:00:00 2001
|From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj#jcrosoft.com>
|Date: Wed, 10 Aug 2011 00:17:29 +0800
|Subject: [PATCH] fix cross compilation: host libsub was used before
|
|tested in buildroot
|
|Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj#jcrosoft.com>
|---
| configure.in | 7 +++++--
| 1 files changed, 5 insertions(+), 2 deletions(-)
|
|diff --git a/configure.in b/configure.in
|index dfa1e8f..cfe2218 100644
|--- a/configure.in
|+++ b/configure.in
--------------------------
File to patch: configure.in
configure.in: No such file or directory
If I skipped the patch the building process stop and I'm not able to generate the images.
I've doing some research on the internet and I couldn't find how to do this correctly.
Maybe one obvious solution could be updating the buildroot version but since there is a lot of other people development with the current version I'm not in a position of taking that decision right now.
I'll do appreciate any help.
Upgrade your Buildroot release. 2015.08 already has OpenOCD 0.8.0 and it should be trivial to update to 0.9.0. Plus you will benefit from the numerous improvements and updates that have been made between 2012.11 and 2015.08.

Wierd behavior of db2ls when run from directory containing spaces

I am facing a strange issue with getting the db2 version using db2ls.
Below are 2 instances of db2ls execution
[root#dummy 6]# cd /tmp
[root#dummy tmp]# db2ls
Install Path Level Fix Pack Special Install Number Install Date Installer UID
---------------------------------------------------------------------------- -----------------------------------------
/opt/ibm/db2/V10.5 10.5.0.3 3 Tue Mar 10 01:38:53 2015 PDT 0
[root#dummy tmp]# mkdir test\ dir
[root#dummy tmp]# cd test\ dir/
[root#dummy test dir]# db2ls
/usr/local/bin/db2ls: line 43: cd: /tmp/test: No such file or directory
Install Path Level Fix Pack Special Install Number Install Date Installer UID
---------------------------------------------------------------------------------------------------------------------
/opt/ibm/db2/V10.5 10.5.0.3 3 Tue Mar 10 01:38:53 2015 PDT 0
It looks like db2ls is having issues when executed from a directory having spaces. Is this a known issue? I could not find any documentation for this. I am trying to circumvent this problem by using db2ls 2>/dev/null.
If there is a more efficient way please let me know.
http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.qb.server.doc/doc/t0023683.html
for DB2 installation paths it says
DB2 installation paths have the following rules:
Can include lowercase letters (a-z), uppercase letters (A-Z), and the underscore character ( _ )
Cannot exceed 128 characters
Cannot contain spaces
Cannot contain non-English characters
Reading statements like this are always a warning sign not to use spaces in paths in general. BTW, shell scripts don't play well with spaces in paths which is for me a good reason to avoid spaces in general.

Perl: strange behaviour of glob with files greater than 2 GB

I'm simply trying to get a list of filenames given a path with wildcard.
my $path = "/foo/bar/*/*.txt";
my #file_list = glob($path);
foreach $current_file (#file_list) {
print "\n- $current_file";
}
Mostly this works perfectly, but if there's a file greater than 2GB, somewhere in one of the /foo/bar/* subpaths, the glob returns an empty array without any error or warning.
If I remove the file file or add a character/bracket sequence like this:
my $path = "/foo/bar/*[0-9]/*.txt";
or
my $path = "/foo/bar/*1/*.txt";
then the glob works again.
UPDATE:
Here's an example (for a matter of business policy I had to mask the pathname):
[root]/foo/bar # ls -lrt
drwxr-xr-x 2 root system 256 Oct 11 2006 lost+found
drwxr-xr-x 2 root system 256 Dec 27 2007 abc***
drwxr-xr-x 2 root system 256 Nov 12 15:32 cde***
-rw-r--r-- 1 root system 2734193149 Nov 15 05:07 archive1.tar.gz
-rw-r--r-- 1 root system 6913743 Nov 16 05:05 archive2.tar.gz
drwxr-xr-x 2 root system 256 Nov 16 10:00 fgh***
[root]/foo/bar # /home/user/test.pl
[root]/foo/bar #
Removing the >2GB file (or globbing with "/foo/bar/[acf]/" istead of "/foo/bar//")
[root]/foo/bar # ls -lrt
drwxr-xr-x 2 root system 256 Oct 11 2006 lost+found
drwxr-xr-x 2 root system 256 Dec 27 2007 abc***
drwxr-xr-x 2 root system 256 Nov 12 15:32 cde***
-rw-r--r-- 1 root system 6913743 Nov 16 05:05 archive2.tar.gz
drwxr-xr-x 2 root system 256 Nov 16 10:00 fgh***
[root]/foo/bar # /home/user/test.pl
- /foo/bar/abc***/heapdump.phd.gz
- /foo/bar/cde***/javacore.txt.gz
- /foo/bar/fgh***/stuff.txt
[root]/foo/bar #
Any suggestion?
I'm working with:
Perl 5.8.8
Aix 5.3
The filesystem is a local jfs.
In the absence of a proper answer you're going to want a work-around. I'm guessing you've hit some platform-specific bug in the glob() implementation of 5.8.8
I had a quick look at the source on CPAN but my C is too rusty to spot anything useful.
There have been lots of changes to that module though, so a bug may well have been reported and fixed. You're not even on the last release of 5.8 - there's a 5.8.9 out there which mentions updates to AIX compatibility and File::Glob.
I'd test this by installing local::lib if you haven't already and then perhaps cpanm and try updating File::Glob - see what that does. You might need to download the files by hand from e.g. here
If that solves the problem then you can either deploy updates to the required systems, or you'll have to re-implement the bits of glob() you want. Which is going to depend on how complex your patterns get.
If it doesn't solve the problem then at least you'll be able to stick some printf's into the code and see what it's doing.
Hopefully someone will post a real answer and make this redundant about 5 minutes after I click "Post Your Answer" though.
I've never used the new Glob function before, so i cant comment on benefits/problems, but it seems quite a lot of people have had issues using it: see => https://stackoverflow.com/search?q=perl+glob&submit=search for some questions and possible solutions.
IF you don't mind trying out something else:
Here is my tried and tested 'old school' perl solution i have used in countless projects:
my $path = "/foo/bar/";
my #result_array = qx(find $path -iname '*.txt'); #run the system find command
If you - for whatever reason prefer not to run a system command from within your script, then lookup the built in Find::Perl Module instead: http://search.cpan.org/~dom/perl-5.12.5/lib/File/Find.pm
good luck

Mercurial: diff file

I'm actually trying something simple, but I get strange results:
I want to compare the current version of a file with a specific revision.
In NetBeans 6.9.1 I didn't find any such function. I can only call the history and then diff between successive revisions. Am I missing something?
I tried with the command line tool (Linux):
hg diff --rev 527 pom.xml
But I get:
diff -r 1018d7890ea1 pom.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pom.xml Sun Jan 30 22:45:28 2011 +0000
## -0,0 +1,167 ##
+
followed only by "+" lines.
How can I get the diff I want? How can I get this diff with NetBeans (or otherwise with another graphical diff tool)?
You usage of the command-line tool looks correct. However the output
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
Indicates that the file you want to diff did not yet exist in the revision you chose.
Addendum:
In the comments you mention the file was renamed and you need to use -g
You can enable -g for all diffs by adding:
[diff]
git=1
to your .hgrc file (usually located in your home directory)
hg diff -r revision1:revision2 file
Where revision1 and revision2 can be a tag, changeset etc.
By default, your revision2 should be "tip" (without quotes) if you want to compare a revision to the current one.

What other repository systems have cvs's -D (date) option?

I recently stumbled upon a cool feature in CVS where you can name revisions by date, e.g.:
# List changes made between the latest revision 24 hours ago and now
cvs diff -D "1 day ago"
Do any other repository systems (e.g. Git, SVN, Bazaar, Mercurial, etc.) have an option like this?
Subversion has a similar feature. For example:
svn diff -r {2010-07-31}
The syntax is explained in http://svnbook.red-bean.com/en/1.5/svn.tour.revs.specifiers.html#svn.tour.revs.dates
Mercurial has a wide range of date formats: http://www.selenic.com/mercurial/hg.1.html#date-formats, though maybe not "1 day ago".
This subversion bug report indicates that Subversion can't do it natively, but does offer a tip on using date to do it:
(2) Whilst Subversion doesn't understand -r "{3 days ago}", date can
help out there too: -r "{date -Is -d '3 days ago'}".
(answering my own question)
git log supports dates for filtering before or after given times. Example:
git log --after='july 17 2010' --before='july 31 2010'
Here's a shell script that makes it a little easier to list ranges of commits, but it also uses a terser format than git log's default:
#!/bin/sh
# git-changes
FORMAT='%cd%x09%h%n%x09%s%n'
CMD="git log --format=format:$FORMAT"
case $# in
0 )
$CMD ;;
1 )
$CMD "--after=`date -d "$1"`" ;;
2 )
$CMD "--after=`date -d "$1"`" --before="`date -d "$2"`";;
esac
Note: I wrapped the date arguments with the date command, since git treats 'July 17' as a few hours off from 'July 17 2010' for some reason.
Usage:
git-changes # Same as git log, but more terse
git-changes 'yesterday' # List all commits from 24 hours ago to now
git-changes 'jul 17' 'aug 1' # List all commits after July 17 at midnight
# and before August 1 at midnight.
Sample output of git-changes 'jul 17' 'aug 1':
Sat Jul 31 23:43:47 2010 -0400 86a6727
* Moved libcurl into project directory as static lib.
Sat Jul 31 20:04:24 2010 -0400 3a4eb10
* Added configuration file support.
Sat Jul 31 17:44:53 2010 -0400 aa2046b
* Fixed truncation bug in bit parser.
Sat Jul 17 00:10:57 2010 -0400 99e8124
* Added support for more bits.
Now, to see all changes introduced by commit 99e8124, type git show 99e8124. To see all changes since revision 99e8124 (not including that commit itself), type git diff 99e8124.