add git-union-merge
This is a new git subcommand, that does a generic union merge operation
between two refs, storing the result in a branch. It operates efficiently
without touching the working tree. It does need to write out a temporary
index file, and may need to write out some other temp files as well.
This could be useful for anything that stores data in a branch,
and needs to merge changes into that branch without actually checking the
branch out. Since conflict handling can't be done without a working copy,
the merge type is always a union merge, which is fine for data stored in
log format (as git-annex does), or in non-conflicting files
(as pristine-tar does).
This probably belongs in git proper, but it will live in git-annex for now.
---
Plan is to move .git-annex/ to a git-annex branch, and use git-union-merge
to handle merging changes when pulling from remotes.
Some preliminary benchmarking using real .git-annex/ data indicates
that it's quite fast, except for the "git add" call, which is as slow
as "git add" tends to be with a big index.
2011-06-20 23:44:45 +00:00
|
|
|
{- git-union-merge program
|
|
|
|
-
|
|
|
|
- Copyright 2011 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
import System.Environment
|
|
|
|
|
2011-10-04 02:24:57 +00:00
|
|
|
import Common
|
2011-06-30 17:32:47 +00:00
|
|
|
import qualified Git.UnionMerge
|
2011-12-13 19:05:07 +00:00
|
|
|
import qualified Git.Config
|
|
|
|
import qualified Git.Construct
|
2011-12-13 19:22:43 +00:00
|
|
|
import qualified Git.Branch
|
2011-12-14 19:30:14 +00:00
|
|
|
import qualified Git.Index
|
2011-06-30 17:16:57 +00:00
|
|
|
import qualified Git
|
add git-union-merge
This is a new git subcommand, that does a generic union merge operation
between two refs, storing the result in a branch. It operates efficiently
without touching the working tree. It does need to write out a temporary
index file, and may need to write out some other temp files as well.
This could be useful for anything that stores data in a branch,
and needs to merge changes into that branch without actually checking the
branch out. Since conflict handling can't be done without a working copy,
the merge type is always a union merge, which is fine for data stored in
log format (as git-annex does), or in non-conflicting files
(as pristine-tar does).
This probably belongs in git proper, but it will live in git-annex for now.
---
Plan is to move .git-annex/ to a git-annex branch, and use git-union-merge
to handle merging changes when pulling from remotes.
Some preliminary benchmarking using real .git-annex/ data indicates
that it's quite fast, except for the "git add" call, which is as slow
as "git add" tends to be with a big index.
2011-06-20 23:44:45 +00:00
|
|
|
|
|
|
|
header :: String
|
2011-06-21 02:21:02 +00:00
|
|
|
header = "Usage: git-union-merge ref ref newref"
|
add git-union-merge
This is a new git subcommand, that does a generic union merge operation
between two refs, storing the result in a branch. It operates efficiently
without touching the working tree. It does need to write out a temporary
index file, and may need to write out some other temp files as well.
This could be useful for anything that stores data in a branch,
and needs to merge changes into that branch without actually checking the
branch out. Since conflict handling can't be done without a working copy,
the merge type is always a union merge, which is fine for data stored in
log format (as git-annex does), or in non-conflicting files
(as pristine-tar does).
This probably belongs in git proper, but it will live in git-annex for now.
---
Plan is to move .git-annex/ to a git-annex branch, and use git-union-merge
to handle merging changes when pulling from remotes.
Some preliminary benchmarking using real .git-annex/ data indicates
that it's quite fast, except for the "git add" call, which is as slow
as "git add" tends to be with a big index.
2011-06-20 23:44:45 +00:00
|
|
|
|
|
|
|
usage :: IO a
|
|
|
|
usage = error $ "bad parameters\n\n" ++ header
|
|
|
|
|
2011-06-21 20:08:09 +00:00
|
|
|
tmpIndex :: Git.Repo -> FilePath
|
2011-08-19 16:59:07 +00:00
|
|
|
tmpIndex g = Git.gitDir g </> "index.git-union-merge"
|
2011-06-21 20:08:09 +00:00
|
|
|
|
|
|
|
setup :: Git.Repo -> IO ()
|
2011-09-21 03:24:48 +00:00
|
|
|
setup = cleanup -- idempotency
|
2011-06-21 20:08:09 +00:00
|
|
|
|
|
|
|
cleanup :: Git.Repo -> IO ()
|
2012-01-10 19:36:54 +00:00
|
|
|
cleanup g = whenM (doesFileExist $ tmpIndex g) $ removeFile $ tmpIndex g
|
2011-06-21 20:08:09 +00:00
|
|
|
|
add git-union-merge
This is a new git subcommand, that does a generic union merge operation
between two refs, storing the result in a branch. It operates efficiently
without touching the working tree. It does need to write out a temporary
index file, and may need to write out some other temp files as well.
This could be useful for anything that stores data in a branch,
and needs to merge changes into that branch without actually checking the
branch out. Since conflict handling can't be done without a working copy,
the merge type is always a union merge, which is fine for data stored in
log format (as git-annex does), or in non-conflicting files
(as pristine-tar does).
This probably belongs in git proper, but it will live in git-annex for now.
---
Plan is to move .git-annex/ to a git-annex branch, and use git-union-merge
to handle merging changes when pulling from remotes.
Some preliminary benchmarking using real .git-annex/ data indicates
that it's quite fast, except for the "git add" call, which is as slow
as "git add" tends to be with a big index.
2011-06-20 23:44:45 +00:00
|
|
|
parseArgs :: IO [String]
|
|
|
|
parseArgs = do
|
|
|
|
args <- getArgs
|
2011-07-15 07:12:05 +00:00
|
|
|
if length args /= 3
|
add git-union-merge
This is a new git subcommand, that does a generic union merge operation
between two refs, storing the result in a branch. It operates efficiently
without touching the working tree. It does need to write out a temporary
index file, and may need to write out some other temp files as well.
This could be useful for anything that stores data in a branch,
and needs to merge changes into that branch without actually checking the
branch out. Since conflict handling can't be done without a working copy,
the merge type is always a union merge, which is fine for data stored in
log format (as git-annex does), or in non-conflicting files
(as pristine-tar does).
This probably belongs in git proper, but it will live in git-annex for now.
---
Plan is to move .git-annex/ to a git-annex branch, and use git-union-merge
to handle merging changes when pulling from remotes.
Some preliminary benchmarking using real .git-annex/ data indicates
that it's quite fast, except for the "git add" call, which is as slow
as "git add" tends to be with a big index.
2011-06-20 23:44:45 +00:00
|
|
|
then usage
|
|
|
|
else return args
|
|
|
|
|
2011-06-21 18:09:06 +00:00
|
|
|
main :: IO ()
|
|
|
|
main = do
|
improve type signatures with a Ref newtype
In git, a Ref can be a Sha, or a Branch, or a Tag. I added type aliases for
those. Note that this does not prevent mixing up of eg, refs and branches
at the type level. Since git really doesn't care, except rare cases like
git update-ref, or git tag -d, that seems ok for now.
There's also a tree-ish, but let's just use Ref for it. A given Sha or Ref
may or may not be a tree-ish, depending on the object type, so there seems
no point in trying to represent it at the type level.
2011-11-16 06:23:34 +00:00
|
|
|
[aref, bref, newref] <- map Git.Ref <$> parseArgs
|
2012-01-13 16:52:09 +00:00
|
|
|
g <- Git.Config.read =<< Git.Construct.fromCurrent
|
2012-01-10 19:36:54 +00:00
|
|
|
_ <- Git.Index.override $ tmpIndex g
|
2011-06-21 21:39:45 +00:00
|
|
|
setup g
|
2011-11-08 19:34:10 +00:00
|
|
|
Git.UnionMerge.merge aref bref g
|
2011-12-13 19:22:43 +00:00
|
|
|
_ <- Git.Branch.commit "union merge" newref [aref, bref] g
|
2011-06-21 21:39:45 +00:00
|
|
|
cleanup g
|