summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2014-02-25 12:48:04 -0400
committerJoey Hess <joey@kitenet.net>2014-02-25 12:48:04 -0400
commitbf933867dce7211e116ef27cad7c7fa7bf49f648 (patch)
tree476ae0455b673e49bf0ea73bc20ce725c595a4ee
parentc7854d2734db2af11ccaf5282b7f22398ed6301b (diff)
downloadgit-repair-bf933867dce7211e116ef27cad7c7fa7bf49f648.tar.gz
handle swap with self case
-rw-r--r--Git/Destroyer.hs18
1 files changed, 10 insertions, 8 deletions
diff --git a/Git/Destroyer.hs b/Git/Destroyer.hs
index a84bc60..57d8ad5 100644
--- a/Git/Destroyer.hs
+++ b/Git/Destroyer.hs
@@ -60,7 +60,7 @@ instance Arbitrary Damage where
- are enumerated, sorted, and this is used as an index
- into the list. (Wrapping around if higher than the length.) -}
data FileSelector = FileSelector Int
- deriving (Read, Show)
+ deriving (Read, Show, Eq)
instance Arbitrary FileSelector where
arbitrary = FileSelector <$> oneof
@@ -129,13 +129,15 @@ applyDamage ds r = do
ScrambleFileMode s mode ->
withfile s $ \f ->
setFileMode f mode
- SwapFiles a b ->
- withfile a $ \fa ->
- withfile b $ \fb ->
- withTmpFile "swap" $ \tmp _ -> do
- moveFile fa tmp
- moveFile fb fa
- moveFile tmp fa
+ SwapFiles a b
+ | a == b -> noop
+ | otherwise ->
+ withfile a $ \fa ->
+ withfile b $ \fb ->
+ withTmpFile "swap" $ \tmp _ -> do
+ moveFile fa tmp
+ moveFile fb fa
+ moveFile tmp fa
where
-- A broken .git/config is not recoverable.
skipped f = f `elem` [ "config" ]