How to create a patch file on windows? - patch

On windows, I have two source files and want to create a patch with difference, like this one.
But I'm unsure, what format this patch is and what app to use in order to create it? GNU diff output is very different from the patch I can see in the link above.

Try WinMerge. You'll find a patch generator in the "Tools" menu.

Thanks, PhiLho & Lukáš! The diff program from UnxUtils works great under Windows 7 to generate the patch file:
diff -u oldfile newfile >patchfile
Likewise, the patch program from UnxUtils works great to apply the patch:
patch -u oldfile patchfile

The output format is called "unified diff", it can be generated using diff -u.

WinMerge is the best tool for windows.
To create a patch file, you need to do the following:
File>Open
-- Here you open the files for which you are generating patch file.
Tools>Generate Patch
-- Here you specify the path where to save the patch file. And WinMerge will save patch file for you.

WinMerge (http://winmerge.org/) is what you need. You also can compare whole file trees with this tool, which is an absolute must-have for some people.

The UnxUtils package offers lot of useful Unix tools for Windows, with a minimal impact on Windows installation (unzip, add location to path, use it).
It has a diff.exe

In Beyond Compare 4 you can generate a unified diff by selecting the 'Session' > 'Text Compare Report...' menu item and then selecting 'Patch' for the layout and 'Unified diff' for the patch style. Then save the output to file, or to the clipboard.

I've also made a tool to generate patch files (like WinMerge html format) between two sets of changesets/folders/commits (as a zip downloaded from github or azure or just folders sitting in your drive) since currently WinMerge does NOT support path file generation from command-line to support automation.
use it like:
python diff_generator.py --c1 "path_to_file1.zip" --c2 "path_to_file2.zip" [--git]
or
python diff_generator.py --c1 "path_to_folder1" --ddc1 --c2 "path_to_folder2" --ddc2

Related

How can I set `path.expand` to begin at my working directory?

I'm using a Mac. The path.expand function is several folders removed from my desired working directory. For example:
path.expand('~')
[1] "/Users/my.name"
I'd like to change it to something like this:
path.expand('~')
[1] "/Users/my.name/drive/R/project/sub.folder"
How can I go about this?
Thank you.
The tilde is, in all unix-sen (including macos), special in that it refers to what the operating system considers the home directory (via the env var HOME).
There are two types of answers to this. Can it be done? Perhaps, sure even. Should it be done? There will likely be unintended consequences (that may be hard to troubleshoot and/or workaround), so likely not.
This works on my ubuntu box:
me#mybox:/some/path$ Rscript -e 'Sys.getenv("HOME")'
[1] "/home/me"
me#mybox:/some/path$ HOME=/tmp/ Rscript -e 'Sys.getenv("HOME")'
[1] "/tmp/"
me#mybox:/some/path$ Rscript -e 'Sys.setenv(HOME="/tmp/");Sys.getenv("HOME")'
[1] "/tmp/"
(This notably does not work as well on Windows ... which is not very unix-y of it!)
So you can try overriding it with either:
Sys.setenv(HOME = "/Users/my.name/drive/R/project/sub.folder"), or
Set the HOME variable in your working environment before starting R.
This might have unintended consequences. For instance, R looks for ~/.Rprofile, and git and commands look for ~/.gitconfig and such.
My recommended way-ahead would be to define a variable and change there. If you use RStudio, then its "Projects" can always start you in the correct directory. If not and you still want this "special directory" available to you, perhaps add this to your /Users/username/.Rprofile (in your "actual" homedir)
.specialdir <- "/Users/my.name/drive/R/project/sub.folder"
and, whenever you need to go there, use file.expand(.specialdir). One side-effect of this is that any of your code, functions, reports, whatever that use this will no longer be reproducible.
A way to easily reference your files without needing to change the HOME directory is to use the here package. This basically uses a heuristic to find the right working directory based on where your script is. Normally it looks for RStudio Project files (.rproj) or for a .git file if your working directory is a git repository. It's easy to use and robust to moving machines or accidental use of setwd, or even forgetting to set HOME on a different machine/profile.
If your data file some_data.csv above is stored in /Users/my.name/drive/R/project/sub.folder/some_data.csv, where project is the root folder for the project:
here::here()
[1] "/Users/my.name/drive/R/project"
here::here("sub.folder", "some_data.csv")
[1] "/Users/my.name/drive/R/project/sub.folder/some_data.csv"
and you can use it as a drop in replacement for the path, as in:
data <- read_csv(here::here("sub.folder", "some_data.csv"))

Atom: how to diff two files using split-diff

It compares my file to the latest version checked into git. How do I compare two files?
You need to use a package. I use split-diff which compares files in tow panes side by side. You need to open each file in a custom pane and then invoke command split-diff:toggle. See package documentation for more info.
Or you may use compare-files package showing a diff of two files

qt-linguist- Merging .ts files

I am translating the GUI of QGIS desktop software.
The current developing version is on transifex platform from which it can be extracted the corresponding .ts file.
the older versions of QGIS are archived on github.
I'd like to insert the missing strings translated in the newer version in the older version. Also some strings have been corrected in the new version and I'd like to replace them in the older.
I used lconvert in this form:
lconvert -i 2.18.ts 2.99.ts -o total.ts
But QT Linguist warns that in total.ts there are duplicated strings.
Is it possible to insert in the older version (2.18) only the strings that are the same from the newer (2.99)?
I ran three years ago with the ts-tools from Qt4 into the same problem.
The manual says that the call of lconvert (just like you laid it out) will merge the content (means: the translations from two sources) into a new file. And I expected "merge" to work like "make a superset out of both". But it did not.
I wrote myself a bash-script to merge it in a way I want to. Will try to find the file this evening.
(I know, right now the answer is - beside confirming the error - not helpful.)

Where is convert in ImageMagick?

I just spent an infuriating day trying to make a gif out of a series of jpg files in R. I installed ImageMagick to run the following code:
system("convert -delay 40 *.png example_4.gif")
but I get the following error message:
Warning message:
running command 'convert -delay 40 *.png example_4.gif' had status 4
which looks like a path error. Now I've looked for convert in the Imagemagick download and can't see it anywhere. Does anyone know where it is?
Alternately, is there another easier method of making a gif from a series of jpegs in R that isn't ridiculously long?
Thanks
Three options:
Consider using the magick R package instead of using system().
Change your script from convert ... to magick convert ....
Re-install imagemagick, and enable the "Install legacy utilities (e.g. convert)" option.
This change has been around since 7.0.1 (now up to 7.0.7), and is discussed in their porting guide, specifically in the section entitled "Command Changes".
Philosophically, I prefer to not install the legacy utilities, mostly because it can cause some confusion with command names. For instance, the non-ImageMagick convert.exe in windows tries to convert a filesystem ... probably not what you want to accidentally trigger (there is a very low chance that you could get the arguments right to actually make a change, but it's still not 0). The order of directories in your PATH will dictate which you are calling.
EDITs:
From comments, it seems like the difference between "static" and "dll" installers might disable the option to install legacy utilities such as convert.exe. So you can either switch to the "dll" to get the legacy option, or you are restricted to options 1 (magick R package) and 2 ("magick convert ...").
From further comments (thanks to fmw42 and MarkSetchell), it is clear that the old convert.exe and the current legacy mode of magick.exe convert are not the same as the currently recommended magick.exe (without "convert"); the first two are legacy and compatibility modes, but they do not accept all arguments currently supported by magick-alone. So the use of "convert" anywhere in the command should indicate use of v6, not the current v7. This answer is then merely a patch for continued use of the v6 mechanisms; one could argue a better solution would be to use magick.exe's v7 interface, completely removing the "convert" legacy mode.

How does one compile single file Xcode 4?

While I used to compile a single source file with Cmd+K in prior versions of Xcode, how does one do the same in Xcode 4? (Note that this is different than preprocessing or showing the disassembly of the file.) If compiling from a command line is proposed then it must be such that the project's settings, include paths, preprocessor definitions, etc., are all included.
An example use case is where I make a header file change but only want to test the change's effect with respect to a single source file, not all of the files that depend upon that header.
The command has been moved to the Perform Action submenu. Look under
Product > Perform Action > Compile filename.cpp
To assign Cmd+K to it, go to
File > Preferences > Key Bindings > Product Menu group
and you'll find Compile File where you can assign a key. Cmd+K is assigned to Clear Console now by default, so be sure to remove that binding to avoid conflicts.
One way that I have found to do this is to using the following menu commands:
Product -> Generate Output -> Generate Preprocessed File
Product -> Generate Output -> Generate Assembly File
This may not be exactly what you want, but it will compile the single file.
When you build a project, xcode runs compilation command. You can check the log, search for your file and copy paste that command on Terminal. It'll compile only the file for which you copy/pasted on the terminal.
If your file is C (or C++) file, then simply open your terminal, go to the folder in which the file resides and type
gcc -o outputFile inputFile.c
I am not familar with Objective-c that much, but GCC might work since it's only a superset of C, just like C++.
Hope that was helpful :)
The keyboard shortcut Cmd+K on Xcode 3 and before has been remapped to Cmd+B on Xcode 4
Along the same lines, Cmd+Return was remapped to Cmd+R (in case you ever used that)
The common requirement for single file compilation is checking it for syntax errors. (atleast for me). Since xcode4 highlights syntax errors as you type. It seems apple removed that feature.

Resources