I have a patch file for some software (Magento) and want to apply it to my current project.
The patch file contains also references to files in the var/packages folder which I do not want (I deleted this folder in my installation).
When applying this patch file (patch -p1 < the.patch), I get lots of warnings like:
The next patch would delete the file var/package/Foo_Bar.1.7.0.0.xml,
which does not exist! Assume -R? [n] ^C
Is there any way to tell the patch command to just ignore patches for this folder?
You can use the “filterdiff” utility – http://man.cx/filterdiff – from http://packages.debian.org/patchutils to do that.
Otherwise, just pressing Enter a lot will also help ;-)
You can use filterdiff from the patchutils package.
-x *PATTERN*, --exclude=*PATTERN*
Exclude files matching PATTERN. All other lines in the input are displayed.
So for your example
filterdiff -p1 -x 'var/packages/*' < the.patch | patch -p1
Alternatively you can manually edit the patch to remove the unwanted files, but this make take some time if it's very large.
Related
I would like to write a script that restores a file, but preserving the changes that may be done after the backout file is created.
With more details: at some moment I create a backup of a file (file_orig). Do some changes to the original file as well(file_my_changes). After that, the original file can be changed again (file_additional_changes), but after the restore I want to have the backup file, plus the additional changes (file_orig + file_addtional_changes). In general backing out my changes only.
I am talking about grub.cfg file, so the expected possible changes will be adding or removing parts of a line.
Is it possible this to be done with a bash script?
I have 2 ideas:
Add some comments above the lines I am going to change, and then before the resotore if the line differ from the one from the backed out file, to read the comment, which will tell me what exactly to remove from the line;
If there is a way to display only the part of the line that differs from the file_orig and file_additional_changes, then to replace this line with the line from file_orig + the part that differs. But I am not sure if this is possible to be done at all.
Example"
line1: This is line1
line2: This is another line1
Is it possible to display only "another"?
Of course any other ideas are welcome!
Thank you!
Unclear, but perhaps if you're using a bash script you could run a diff on the 2 edited file and the last one and save that output someplace that you want to keep it? That would mean you have a copy of the changes.
Or just use git like everybody else.
One possibility would be to use POSIX commands patch and
diff.
Create the backup:
cp operational-file operational-file.001
Edit the operational file.
Create a patch from the differences:
diff -u operational-file.001 operational-file > operational-file.patch001
Copy the operational file again.
cp operational-file operational-file.002
Edit the operational file again.
Create a new patch
diff -u operational-file.002 operational-file > operational-file.patch002
If you need to recover but skip the changes from patch.001, then:
cp operational-file.001 operational-file
patch -i patch.002
This would apply just the second set of changes to the original file, as log as there's no overlap.
Consider using a version control system to keep records of the file changes. Consider using date/time stamps instead of version numbers on the file names.
Append Problem
I am trying to read rules from a file and in a bash script set the rules, for this to work I need to append the svn:ignore rules to the directory.
I have an example set of data:
/js/blank.html
/js/index.php
/js/spacer.gif
If I try to run svn propedit svn:ignore js/ < "blank.html" or echo "test" | svn propedit svn:ignore js/ I get the following error:
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: preserving files...
Vim: Finished.
svn: E200012: system('/usr/bin/editor svn-prop.tmp') returned 256
Is it possible to append rules to svn:ignore?
Alternatives
I know you can use propset to set a list of rules, one per line as per Ignore multiple specific files with svn but that is not the behaviour I am looking for as I would have to order my list in bash some how and make sure I do not overwrite any existing changes.
Interestingly this came up in 2005 but there was no outcome, maybe I should track him down.
If anyone knows how to use propset to append that would be useful too.
Thanks
proplist
I am automating these additions from a file, so I want to ignore all of these apart from local.xml.sample
ls -h errors/
404.php default enterprise processor.php
503.php design.xml local.xml.sample report.php
My propedit rules:
.htaccess
404.php
503.php
design.php
processor.php
report.php
design.xml
Proplist output:
svn proplist errors
Properties on 'errors':
svn:ignore
There are more complex examples I can give, but the baseline is that I am trying to automate all rules from a single file to create a reliable way of ignore all core files of a software package from my repository. I know I am using the wrong tool for the job, but management is management, I feel like I am hitting a nail with a piece of paper.
I have 3 files.
f1.java
f1rev1.java
f1rev2.java
What I want to do is get the diff between "f1.java" and "f1rev1.java" and apply that diff to "f1rev2.java" without considering the diff between f1.java and f1rev2.java.
Is there any tool or libraries that I can use to achieve this?
Any language would be fine.
Note - I studies about diff3 algorithm. There it compares both f1.java with f1rev1.java and f1.java with f1rev2.java
I don't want to consider about the diff between f1 and f1rev2.
You did not specify your platform (Hint: use an appropriate tag!).
On UNIX-based platforms, you can use the tools diff and patch to achieve what you want to do.
Use diff -u f1.java f1rev1.java > rev1.patch to create a patch
Apply the patch via patch f1rev2.java rev1.patch to the other source file
As you can see, it is easy as cake. Only the differences contained in the patch will be played on the other file. Note that this only works if the patch is compatible with it. You can read the patch file with less to see the changes to be applied.
On a Windows system, you can do the same procedure as outlined here:
How do I apply a diff patch on Windows?
Sadly, but as expected, it is much more time-consuming. Consider the use of MinGW: Apply a patch file in Windows using Mingw or Cygwin.
A Day with Winrar
All I wanted to do was exclude folders and their contents using wildcards, and even after reading the docs, it turned into a guessing game...
So my test bed looks like:
C:\!tmp1\f1
C:\!tmp1\f1\f1.txt
C:\!tmp1\f1\a
C:\!tmp1\f1\a\a.txt
C:\!tmp1\f2
C:\!tmp1\f2\f2.txt
C:\!tmp1\f2\a
C:\!tmp1\f2\a\a.txt
And I am executing:
C:\>"c:\program files\winrar\winrar.exe" a -r !tmp1.rar !tmp1
which gives me a rar with !tmp1 as the root (sole top level folder).
The exclude switch is -x<filepathpattern> and may be included multiple times.
So, given that we want to exclude f2, and all its subcontents...
-x*\f2\*
removes the contents, but leaves f2
-xf2
does nothing - includes all
-x\f2
does nothing - includes all
-x*\f2
does nothing - includes all (now I'm mad), so surely it must be..
-x\f2\
nope, does nothing - includes all. So it has GOT to be...
-x*\f2\
hell no, does nothing - includes all. and I already know that
-x*\f2\*
removes the contents, but leaves f2. Onward we go...
-x*f2\
does nothing - includes all. Grrrr. Aha! how about...
-x!tmp1\f2\
nope, does nothing - includes all. WTF. Alright, So it has GOT to be...
-x!tmp1\f2
Holy moly, it worked! Hmmm, then how come....
-x*\f2
does not work? This was the little demon that sent me down this crazed path to begin with and should have worked!
Given all that, do I dare try to go after */a/* directories, removing contents and the dirs?
-x*\a
does not work, of course, does nothing.
-x*\*\a
does not work, of course, does nothing.
-x!tmp1\*\a
nope. But...
-x*\a\*
removes contents of both dirs, but leaves the folders. So, in desperation I can use the -ed switch which will not store empty folders, but this is a broad hack, I want to eliminate the folders specified not all empty folders.
With my animosity growing toward winrar, I am passing the baton of information forward with an eye to that glorious day when we will know how to specifically exclude a folder and its contents using wildcards and not using the -ed switch.
(Quite old question but still may be relevant)
Maybe what you simply needed was this :
-x*\f2 -x*\f2\*
two exclude switches, should remove directory f2 and all its contents.
An even older question by now, but came across this question so I reproduced your folder structure and, at least nowadays (Winrar 5.11, not the latest but quite new), this works:
-x*\f2
So the whole command line is:
"C:\Program Files\WinRAR\Rar.exe" a -m5 -s !tmp1.rar !tmp1 -x*\f2
And this is what is stored in the .rar file:
!tmp1\f1\a\a.txt
!tmp1\f1\f1.txt
!tmp1\f1\a
!tmp1\f1
!tmp1
Similarly, if you use -x*\a, all a folders are excluded, storing this:
!tmp1\f1\f1.txt
!tmp1\f2\f2.txt
!tmp1\f1
!tmp1\f2
!tmp1
Finally, combining both parameters (-x*\f2 -x*\a), you get this:
!tmp1\f1\f1.txt
!tmp1\f1
!tmp1
To manage large list of files to be excluded, you can create text fie and write all excluded files/folders relative to the source folder:
1) create file list.txt, write the name of excluded files/folders
note: * refer to the source, all files/folders are relative to the source folder
*\f2
*\f3
2) Run the command
rar a -r -x#list.txt target.rar source-folder
Scenario: I use a simple function to minify and compress JS files during the deployment like this:
for i in public/js/*.js; do uglifyjs --overwrite --no-copyright "$i"; done
The problem with this approach is that it minifies and overwrites original files. I would like to somehow introduce a versioning of minified JS and CSS files.
Let's say I have a variable with the version: "123". How to modify my script to write files with this version? It should work with CSS and JS files like this:
style.css -> style.123.css
script.js -> script.123.js
Something like this?
VERSION=123; for i in public/js/*.js; do REV=${i/%.js/.${VERSION}.js}; cp "${i}" "${REV}"; uglifyjs --overwrite --no-copyright "${REV}"; done
REV=${i/%.js/.${VERSION}.js} replaces the last occurrence of ".js" by ".123.js".
should work in sh too:
VERSION=321; for i in public/js/*.js; do NEW=$(echo $i | sed s/\\./.$VERSION./) ; cp $i $NEW; uglifyjs --overwrite --no-copyright $NEW; done
This is a silly approach. Use a version control tool for versioning your sources.
But of course, you're right not to want to modify the files in place.
Call your source files foo.src.js (or whatever). (Keep the last suffix .js so your editor recognizes the language). Then have a build step which produces foo.js. When you're developing you can have a "null compile" step which just copies foo.src.js to foo.js. When you make a release, then the copy step is changed to do the uglifyjs instead of a copy. Either way, you never edit the generated foo.js by hand, of course, even when it is just a copy. You might want to, instead of just copying, add a comment on top "generated file, do not edit".
The exact details are up to you. You could have foo.js be the name of the original source file and foo.u.js be the uglified one as long as you refer to the right names when loading.