On 02/21/14 12:43, Laszlo Ersek wrote:
> This is a small hint for people who want to see the changes in .uni
> files (== UCS-2 encoded strings for HII forms) while using git. I've
> distilled it from <http://git-scm.com/docs/gitattributes> and I'm
> posting it to save others time.
> 
> (1) Add the following lines to your .git/info/attributes (the .uni one
> is imporant, the others are here just for completeness):
> 
> *.efi -diff
> *.EFI -diff
> *.uni diff=uni
> *.UNI diff=uni
> *.bin -diff
> *.BIN -diff
> *.raw -diff
> *.RAW -diff
> *.bmp -diff
> *.BMP -diff
> 
> (2) Then edit .git/config:
> 
> [diff "uni"]
>       textconv = iconv -f UCS-2 -t UTF-8
>       binary = true
> 
> (3) Profit! :)
> 
> Note that this only helps with *viewing* changes as patches. Git still
> won't help you resolve conflicts during rebases, it won't try to merge
> changes, and importantly it won't generate textual patches in
> git-format-patch. You'll also still need a UCS-2 compatible text editor
> that preserves the BOM (like "gedit") to edit .uni files.

Sorry for the self-followup, but I figured out how it can be made work
for merges too (cherry-pick, conflicts in rebase / merge etc.).

So, in addition to the above:

(4) modify .git/info/attributes like this (ie. add the "merge" attribute
for *.uni files):

*.uni diff=uni merge=uni
*.UNI diff=uni merge=uni

(5) append to .git/config:

[merge "uni"]
        name = merge driver for UCS-2 encoded text files
        driver = uni-merge %O %A %B

(6) Place the attached "uni-merge" script on your PATH (and make it
executable).

(7) Profit more! :)

Thanks
Laszlo
#!/bin/bash

# Merge UCS-2 encoded text files.
# This is a git-merge driver. It will overwrite "$MINE".
#
# Exit status:
# 0 -- no conflicts
# 1 -- conflicts
# 2 -- trouble

OLD="$1"
MINE="$2"
YOURS="$3"

# Set safe defaults for the trap handler.
OLD_UTF8=
MY_UTF8=
YOUR_UTF8=
NEW_UTF8=
EX=2

trap 'rm -f -- "$OLD_UTF8" "$MY_UTF8" "$YOUR_UTF8" "$NEW_UTF8"; exit $EX' EXIT
set -e -u -C

OLD_UTF8=$(mktemp)
iconv --from UCS-2 --to UTF-8 <"$OLD" >>"$OLD_UTF8"

MY_UTF8=$(mktemp)
iconv --from UCS-2 --to UTF-8 <"$MINE" >>"$MY_UTF8"

YOUR_UTF8=$(mktemp)
iconv --from UCS-2 --to UTF-8 <"$YOURS" >>"$YOUR_UTF8"

NEW_UTF8=$(mktemp)
set +e
diff3 --merge --label=mine --label=old --label=yours -- \
    "$MY_UTF8" "$OLD_UTF8" "$YOUR_UTF8" >>"$NEW_UTF8"
DIFFRET=$?
set -e

if [ 0 -ne "$DIFFRET" ] && [ 1 -ne "$DIFFRET" ]; then
  exit
fi

iconv --from UTF-8 --to UCS-2 <"$NEW_UTF8" >|"$MINE"
EX=$DIFFRET
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to