libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.16k stars 889 forks source link

Exposing low level method for external application #602

Closed amibar closed 10 years ago

amibar commented 10 years ago

Hi,

I am writing a tool to convert a TFS repository into a git repository. To do this the tool replays the TFS changesets into a git repository. The tool also keeps the original branches structure.

To make the tool fast I update the Index directly and avoid using the working area. To achieve this I use some low level methods of the libgit2sharp library, such as:

Index.RemoveFromIndex Index.UpdatePhysicalIndex Index.UpdateIndex (I added it to call to Proxy.git_index_add)

I am also using Repository.Commit, and I added a new parameter:

IEnumerable additionalParents = null

so I can add additional parents to a commit for merging.

I know that my usage is not the common usage and might confuse users, but I need these methods for my utility.

What is the best way to expose them?

Thanks, Ami

nulltoken commented 10 years ago

I am writing a tool to convert a TFS repository into a git repository.

Have you considered tools like git-tfs or git-tf?

I know that my usage is not the common usage and might confuse users, but I need these methods for my utility. [...] What is the best way to expose them?

I'd say the best way is to not use the index to create a commit, but rather to directly generate Blobs, Trees and Commits in the ObjectDatabase. Then, when all your changesets are converted, properly move/create the branch/tag references to make them point to the appropriate commits.

The TreeDefinition type has been specifically created to ease this kind of task.

I'd suggest you to peek at the TreeDefinitionFixture and ObjectDatabaseFixture tests to get a better understanding of the intended usage.

@ethomson @spraints

ethomson commented 10 years ago

Have you considered tools like git-tfs or git-tf?

Indeed, I'd be curious about what is lacking in either of these tools that makes yet another one a desirable option.

amibar commented 10 years ago

Actually I am using git-tfs as a basis. The problem is that it gets into infinite loop during the conversion, so I had to fix it.

amibar commented 10 years ago

It is also too slow.

amibar commented 10 years ago

I think that the ObjectDatabase will make the conversion faster because I won't need to switch between branches. I just need to keep internally the last commit of each branch.

nulltoken commented 10 years ago

@amibar Git-Tfs is currently transitioning from the index-based approach to the TreeDefinition one. I'm sure they'd love some help with this and I'd gladly provide any needed support to make this happen. How would you feel about forking git-tfs and starting a pull request?

amibar commented 10 years ago

I wanted to this after I make sure I can use the libgit2sharp public release. So here I am, talking with you.

nulltoken commented 10 years ago

See https://github.com/libgit2/libgit2sharp/issues/587 for reference.

/cc @KindDragon @sc68cal

amibar commented 10 years ago

Converting my TFS repository takes about 4 hours (about 6000 changesets) The first 2400 takes about 30min. I know that part of it is because of branch switching. I'll rewrite my code using the ObjectDatabase and see how it goes.

Thanks for the help. Ami

nulltoken commented 10 years ago

Cheers!

amibar commented 10 years ago

I ran it again with ObjectDatabase and now it takes 1.5 hours. However, now I got a case sensitive problem, same as described by @kgybels in #587.

kgybels commented 10 years ago

@amibar

1.5 hours instead of 4 hours is a nice improvement! How big is your repository (number of commits, number of files, ...)?

Are you willing to try out git-tfs/git-tfs#524 on your repository?

amibar commented 10 years ago

@kgybels

I rewrote the clone --with-braches because the original one got into infinite loop on my TFS repository. I can call my version clone --a-branch, because it clones a single branch. I need to reorder the code, once I do, I'll upload it as a new branch so you can see it.