-1

I use libgit2 in C++ project for my custom objects store.

I use git_tree_create_updated function from libgit2 for updating trees.

There is a problem for me to do both move and update operation for some tree in one commit. If i remove old tree in old place, and after this add new tree to another place, of course it looks like deleting one tree and adding another tree in the git history.

If i try to add old tree to new place first, afterward to update old tree in new place with new tree, and afterward delete old tree in old place, libgit2 returns error about duplicate entrys in update list(for git_tree_create_updated function). It happens because i use two operations on one entry, but is there another method to ask libgit2 use rename with update?

I know, git provides rename/update operation in one commit, but how can i do the same using libgit2, especially with git_tree_create_updated function?

About duplicating: As i use libgit2, i hope there is a possibility to customize getting diff procedure.

Caxa
  • 19
  • 1
  • 3

2 Answers2

0

Git does not provide a rename operation in one commit: Git does not store any metadata about how one commit changed from another, so it does not store any information about renames.

Git merely looks at your history and compares the deleted items to the added items - if they are similar to each other, textually, then it decides the files were renamed. If not, they were deleted and added.

Since Git does not store this information, there is nothing to configure in libgit2 when changing the index or when creating a commit.

If you want to provide your own, custom function to determine the similarity between files, you can provide your own similarity metric to calculate the similarity between files.

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • I suspected such behavior from git, thank's for explanations. But what about binary data compare? Is there any method to explain through libgit2 compare method, so git could be undarstand that objects are similar? – Caxa May 26 '17 at 13:26
  • Yes, I updated my answer to include the information about similarity metrics. – Edward Thomson Jun 01 '17 at 12:54
0

As i didn't find any possibility to customize getting diff procedure using libgit2, i came to conclusion that i have to iterate through standard git diff result of libgit2, to manually determine rename/update situation and set up my own diff list.

Caxa
  • 19
  • 1
  • 3