4

Is there a way to convert a darcs project with multiple branches (i.e., more than two darcs repositories containing different but related sets of patches) to a single git repository, so that each darcs repo is transferred to a distinct branch in the git repo?

Solutions considered:

(1) The darcs convert command offers two recipes for exporting darcs to git:

a. one-time export:

$ cd repo
$ git init ../mirror
$ darcs convert export | (cd ../mirror && git fast-import)

This converts only one repo, one branch.

b. incremental export using marksfiles (to maintain a git mirror of a darcs repository):

$ cd repo
$ git init ../mirror
$ touch ../mirror/git.marks
$ darcs convert export --read-marks darcs.marks --write-marks darcs.marks |
  (cd ../mirror && 
    git fast-import --import-marks=git.marks --export-marks=git.marks)

Using (b), if I had only one other darcs repo as a branch, I might hope to continue with

$ cd ../mirror
$ git branch branch1
$ git checkout branch1

$ cd ../repo
$ darcs pull ../repo-branch1

and then repeat the darcs convert export step.

But with two other branches, this does not seem likely to work, since pulling ../repo-branch2 would merge together the patches of branch1 and branch2.

(2) Darcs-bridge [2]. Incomplete, unmaintained since 2013, and "still named darcs-fast-convert", recommended only for a one-time conversion in either direction (darcs->git or git->darcs)

The darcs-bridge page itself [2] recommends using the 'darcs convert' command built into darcs 2.10.

However, it can handle branches (with some work):

See use-case 2 in [2]:

$ git init my_project_git
$ darcs-fastconvert export myproject myproject-branch1 | 
  (cd my_project_git && git fast-import && git checkout master)

This will create the git repo with two branches: (darcs) myproject -> (git) master (darcs) myproject-branch1 -> (git) myproject-branch1 with a common prefix, but no merges detected.

Use case 5 in [2] describes a way to change the list of branches that the darcs-bridge is managing.

"What are the limitations?" and "What needs work?" in [2] seem to be saying (hard for me to understand) that darcs merges are not correctly converted unless special tagging is used -- tagging which must be done before the merge, so it is now impossible for me to do.

(3) Darcs-fastconvert (on which darcs-bridge is based): according to [2], did not manage multiple branches

(4) darcs-to-git: acc. to [2], does not support branches

(5) darcs2git: acc. to [2], does not support branches

(6) tailor: acc. to [2], does not support branches easily, has been discontinued in favor of darcs-fastconvert

References:

[1] Darcs-Convert: http://darcs.net/Using/Convert)

[2] Darcs-Bridge: http://darcs.net/DarcsBridgeUsage)

2 Answers2

0

Pipe the git-fast-import format output from darcs convert export through a simple script that modifies the target branch. In most cases, you can just do this:

darcs convert export | sed 's#^commit refs/heads/master$#commit refs/head/your-branch#' | (cd ../mirror && git fast-import)

If you are concerned that your files or other repo data might contain the exact string of bytes

\ncommit refs/heads/master\n

somewhere, then your branch-changing script will need to look for data commands and pass them through unchanged. That's not too hard either - see the git fast-import man page for the details of the data command format - but then you'll need to write a simple program in your favorite programming language.

Yitz
  • 5,057
  • 24
  • 19
0

To offer another option: export your Darcs repositories into separate Git repositories, then choose one Git repository and add the others as remotes to it. Then fetch each and use the remote master branches. This method wastes disk space unless you share the object store of the created Git repositories; see How can one safely use a shared object database in git? for tips if this concerns you.

Ferenc Wágner
  • 246
  • 2
  • 9
  • once i have the darcs forks as git branches in the same git repo (with an isolated history i guess)... would it be possible to simply rebase the branches on top of a selected master? i guess it would require a `darcs optimize reorder` prior to the conversion? – Attila Lendvai Aug 14 '22 at 15:26
  • You don't even need to rebase: since the whole conversion process is deterministic (that's why you can also do it incrementally for speed), if you run it on Darcs repositories differing only in some "final" (in the otherwise immaterial repo order sense) patches, the resulting Git branches will share the common part of their histories. – Ferenc Wágner Aug 16 '22 at 18:00