Compare commits
	
		
			No commits in common. "4499144a4dedd5d568878e75fa8d82261c2c374d" and "259ad6101b71e764459171122a3915ace74f6590" have entirely different histories.
		
	
	
		
			4499144a4d
			...
			259ad6101b
		
	
		
							
								
								
									
										25
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										25
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							|  | @ -8,26 +8,17 @@ on: | ||||||
| 
 | 
 | ||||||
| jobs: | jobs: | ||||||
|   build: |   build: | ||||||
|     name: Build ${{ github.ref_name }} OS:${{ matrix.os }} GHC:${{ matrix.ghc }} |     runs-on: ubuntu-latest | ||||||
|     runs-on: ${{ matrix.os }} |  | ||||||
|     strategy: |  | ||||||
|       matrix: |  | ||||||
|         os: [ubuntu-22.04, macos-15] |  | ||||||
|         ghc: |  | ||||||
|           - "9.6" |  | ||||||
|           - "9.12" |  | ||||||
|     steps: |     steps: | ||||||
|       - uses: actions/checkout@v4 |       - uses: actions/checkout@v4 | ||||||
|  |         with: | ||||||
|  |           submodules: recursive | ||||||
|       - uses: haskell-actions/setup@v2 |       - uses: haskell-actions/setup@v2 | ||||||
|         with: |         with: | ||||||
|           ghc-version: ${{ matrix.ghc }} |           ghc-version: '9.4' | ||||||
|       - name: build |       - run: | | ||||||
|         run: | |           cabal build | ||||||
|           mkdir dist |           xz -9 < `cabal exec which werge` > werge-${{ github.ref_name }}-`uname -m`.xz | ||||||
|           cabal install exe:werge --install-method=copy --overwrite-policy=always --installdir=dist |  | ||||||
|           strip dist/werge |  | ||||||
|           mv dist/werge dist/werge-${{ github.ref_name }}_${{ matrix.os }}_ghc-${{ matrix.ghc }} |  | ||||||
|           xz dist/werge-* |  | ||||||
|       - uses: softprops/action-gh-release@v2 |       - uses: softprops/action-gh-release@v2 | ||||||
|         with: |         with: | ||||||
|           files: dist/werge-*.xz |           files: werge-*.xz | ||||||
|  |  | ||||||
							
								
								
									
										45
									
								
								Main.hs
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								Main.hs
									
									
									
									
									
								
							|  | @ -30,16 +30,13 @@ data Op | ||||||
|   | Add |   | Add | ||||||
|   deriving (Show, Eq) |   deriving (Show, Eq) | ||||||
| 
 | 
 | ||||||
| pdiff' :: [String] -> [(Op, Tok)] | pdiff :: FilePath -> IO [(Op, Tok)] | ||||||
| pdiff' = map go | pdiff path = map go . lines <$> readFile path | ||||||
|   where |   where | ||||||
|     go ('-':s) = (Del, s) |     go ('-':s) = (Del, s) | ||||||
|     go (' ':s) = (Keep, s) |     go (' ':s) = (Keep, s) | ||||||
|     go ('+':s) = (Add, s) |     go ('+':s) = (Add, s) | ||||||
|     go _ = error "unexpected contents in diff" |     go _ = error "unexpected output from diff" | ||||||
| 
 |  | ||||||
| pdiff :: FilePath -> IO [(Op, Tok)] |  | ||||||
| pdiff path = pdiff' . lines <$> readFile path |  | ||||||
| 
 | 
 | ||||||
| data Merged | data Merged | ||||||
|   = Ok [String] |   = Ok [String] | ||||||
|  | @ -289,21 +286,6 @@ format Config {..} h = go False | ||||||
|             [cfgLabelStart, Toks.glue o, cfgLabelDiff, Toks.glue n, cfgLabelEnd] |             [cfgLabelStart, Toks.glue o, cfgLabelDiff, Toks.glue n, cfgLabelEnd] | ||||||
|       go True xs |       go True xs | ||||||
| 
 | 
 | ||||||
| fmtPatch :: Config -> Handle -> Handle -> IO () |  | ||||||
| fmtPatch cfg out h = hGetContents h >>= go . lines |  | ||||||
|   where |  | ||||||
|     go all@(l:ls) |  | ||||||
|       | patchLine l = do |  | ||||||
|         let (p, ls') = span patchLine all |  | ||||||
|         format cfg out . chunks $ pdiff' p |  | ||||||
|         go ls' |  | ||||||
|       | otherwise = hPutStrLn out l >> go ls |  | ||||||
|     go [] = pure () |  | ||||||
|     patchLine (' ':_) = True |  | ||||||
|     patchLine ('-':_) = True |  | ||||||
|     patchLine ('+':_) = True |  | ||||||
|     patchLine _ = False |  | ||||||
| 
 |  | ||||||
| runCmd :: Command -> Config -> IO () | runCmd :: Command -> Config -> IO () | ||||||
| runCmd CmdDiff3 {..} cfg = | runCmd CmdDiff3 {..} cfg = | ||||||
|   withSystemTempDirectory "werge-diff3" $ \workdir -> do |   withSystemTempDirectory "werge-diff3" $ \workdir -> do | ||||||
|  | @ -361,21 +343,12 @@ runCmd CmdDiff {..} cfg = do | ||||||
| runCmd CmdPatch {..} cfg = do | runCmd CmdPatch {..} cfg = do | ||||||
|   withSystemTempDirectory "werge-patch" $ \workdir -> do |   withSystemTempDirectory "werge-patch" $ \workdir -> do | ||||||
|     let f = workdir </> "file" |     let f = workdir </> "file" | ||||||
|     case patchTarget of |     bracketFile patchMy ReadMode $ \h -> hSplitToFile cfg h f | ||||||
|       Just patchMy -> do |     _ <- runPatch f stdin | ||||||
|         bracketFile patchMy ReadMode $ \h -> hSplitToFile cfg h f |     conflicted <- pmerge f >>= format cfg stdout -- TODO try to resolve more? | ||||||
|         _ <- |     if conflicted | ||||||
|           case patchInput of |       then exitWith (ExitFailure 1) | ||||||
|             Nothing -> runPatch f stdin |       else exitSuccess | ||||||
|             Just path -> bracketFile path ReadMode $ runPatch f |  | ||||||
|         conflicted <- pmerge f >>= format cfg stdout -- TODO try to resolve more? |  | ||||||
|         if conflicted |  | ||||||
|           then exitWith (ExitFailure 1) |  | ||||||
|           else exitSuccess |  | ||||||
|       Nothing -> do |  | ||||||
|         case patchInput of |  | ||||||
|           Nothing -> fmtPatch cfg stdout stdin |  | ||||||
|           Just path -> bracketFile path ReadMode $ fmtPatch cfg stdout |  | ||||||
| runCmd CmdBreak cfg = hSplit cfg stdin stdout | runCmd CmdBreak cfg = hSplit cfg stdin stdout | ||||||
| runCmd CmdGlue _ = getContents >>= putStr . Toks.glue . Toks.fromFile | runCmd CmdGlue _ = getContents >>= putStr . Toks.glue . Toks.fromFile | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										21
									
								
								Opts.hs
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								Opts.hs
									
									
									
									
									
								
							|  | @ -229,8 +229,7 @@ data Command | ||||||
|       , diffUnified :: Maybe Int |       , diffUnified :: Maybe Int | ||||||
|       } |       } | ||||||
|   | CmdPatch |   | CmdPatch | ||||||
|       { patchTarget :: Maybe FilePath |       { patchMy :: FilePath | ||||||
|       , patchInput :: Maybe FilePath |  | ||||||
|       } |       } | ||||||
|   | CmdBreak |   | CmdBreak | ||||||
|   | CmdGlue |   | CmdGlue | ||||||
|  | @ -295,21 +294,7 @@ cmdDiff = do | ||||||
| 
 | 
 | ||||||
| cmdPatch :: Parser Command | cmdPatch :: Parser Command | ||||||
| cmdPatch = do | cmdPatch = do | ||||||
|   patchTarget <- |   patchMy <- strArgument $ metavar "MYFILE" <> help "File to be modified" | ||||||
|     asum |  | ||||||
|       [ Just <$> strArgument (metavar "MYFILE" <> help "File to be patched") |  | ||||||
|       , flag' Nothing |  | ||||||
|           $ long "format" |  | ||||||
|               <> short 'f' |  | ||||||
|               <> help |  | ||||||
|                    "Do not patch anything, only format the patch using conflict marks on joined tokens" |  | ||||||
|       ] |  | ||||||
|   patchInput <- |  | ||||||
|     optional . strOption |  | ||||||
|       $ long "patch" |  | ||||||
|           <> short 'p' |  | ||||||
|           <> metavar "PATCH" |  | ||||||
|           <> help "File with the patch (default: stdin)" |  | ||||||
|   pure CmdPatch {..} |   pure CmdPatch {..} | ||||||
| 
 | 
 | ||||||
| -- TODO have some option to output the (partially merged) my/old/your files so | -- TODO have some option to output the (partially merged) my/old/your files so | ||||||
|  | @ -329,7 +314,7 @@ cmd = | ||||||
|             $ progDesc "Find differences between two files" |             $ progDesc "Find differences between two files" | ||||||
|         , command "patch" |         , command "patch" | ||||||
|             $ info cmdPatch |             $ info cmdPatch | ||||||
|             $ progDesc "Modify a file using a patch from `diff'" |             $ progDesc "Apply a patch from `diff' to file" | ||||||
|         , command "break" |         , command "break" | ||||||
|             $ info (pure CmdBreak) |             $ info (pure CmdBreak) | ||||||
|             $ progDesc "Break text to tokens" |             $ progDesc "Break text to tokens" | ||||||
|  |  | ||||||
|  | @ -279,15 +279,12 @@ Available options: | ||||||
| 
 | 
 | ||||||
| #### Patching files in place | #### Patching files in place | ||||||
| ``` | ``` | ||||||
| Usage: werge patch (MYFILE | (-f|--format)) [-p|--patch PATCH] | Usage: werge patch MYFILE | ||||||
| 
 | 
 | ||||||
|   Modify a file using a patch from `diff' |   Apply a patch from `diff' to file | ||||||
| 
 | 
 | ||||||
| Available options: | Available options: | ||||||
|   MYFILE                   File to be patched |   MYFILE                   File to be modified | ||||||
|   -f,--format              Do not patch anything, only format the patch using |  | ||||||
|                            conflict marks on joined tokens |  | ||||||
|   -p,--patch PATCH         File with the patch (default: stdin) |  | ||||||
|   -h,--help                Show this help text |   -h,--help                Show this help text | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| cabal-version:   3.0 | cabal-version:   3.0 | ||||||
| name:            werge | name:            werge | ||||||
| version:         0.2.0.0 | version:         0.1.0.0 | ||||||
| synopsis:        mergetool for mangled-up bite-size changes | synopsis:        mergetool for mangled-up bite-size changes | ||||||
| license:         GPL-3.0-or-later | license:         GPL-3.0-or-later | ||||||
| license-file:    LICENSE | license-file:    LICENSE | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue