From 52ef1b34057e759d4a0228f939181e238289e4a3 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 4 Jul 2016 08:37:33 -0700 Subject: [PATCH] hg-fast-export.sh: let git manage the marks Ever since Git 1.5.1, "git fast-import" has supported an "--import-marks" command and allowed the same file name to be used without conflict for both the "--import-marks" and "--export-marks" options. Therefore get rid of the kludgey code that exports to a temp file and then attempts to combine the old and the new with uniq etc. etc. By allowing Git to handle this the code is much simpler, Git always knows about all the marks and there's no concern about the input to the 'uniq' command not being in sorted order. However, do export the marks to a different file so that in the unlikely event of a disk full error where "git fast-import" fails to write the new "--export-marks" file, no marks are lost and on success just replace the old marks file with the new one. Signed-off-by: Kyle J. McKay --- hg-fast-export.sh | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/hg-fast-export.sh b/hg-fast-export.sh index ef0c0fc..54c627c 100755 --- a/hg-fast-export.sh +++ b/hg-fast-export.sh @@ -89,9 +89,10 @@ fi if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then touch "$GIT_DIR/$PFX-$SFX_MARKS" fi +rm -f "$GIT_DIR/$PFX-$SFX_MARKS.new" # cleanup on exit -trap 'rm -f "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"' 0 +trap 'rm -f "$GIT_DIR/$PFX-$SFX_MARKS.new"' 0 _err1= _err2= @@ -112,24 +113,17 @@ $( } | \ { _e2=0 - git fast-import $GFI_OPTS --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" 3>&- || _e2=$? + git fast-import \ + --import-marks="$GIT_DIR/$PFX-$SFX_MARKS" \ + --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.new" \ + $GFI_OPTS 3>&- || _e2=$? echo $_e2 >&3 } ) EOT exec 3>&- [ "$_err1" = 0 -a "$_err2" = 0 ] || exit 1 - -# move recent marks cache out of the way... -if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then - mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old" -else - touch "$GIT_DIR/$PFX-$SFX_MARKS.old" -fi - -# ...to create a new merged one -cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \ -| uniq > "$GIT_DIR/$PFX-$SFX_MARKS" +mv -f "$GIT_DIR/$PFX-$SFX_MARKS.new" "$GIT_DIR/$PFX-$SFX_MARKS" # save SHA1s of current heads for incremental imports # and connectivity (plus sanity checking) -- 2.11.4.GIT