git fast-import - how to handle subdirectories when importing from backup files

389 Views Asked by At

I am writing an importer-frontend for git-import to create a repository from our "flat-file-version-control".

I managed to get my directories traversed and I am generating the commit-output for all the files I can find in the directories.

But I fail to understand how to handle subdirectories. Something like this:

/dir
|
+-- file
|
+-- /subdir
    |
    +-- another_file

As far as I understand, I would have to import subdir first, and then another_file. But I do not understand from the documentation how to achive this.

The git documentation about inline data format during commit tells me:

040000: A subdirectory. Subdirectories can only be specified by SHA or through a tree mark set with --import-marks.

How do I retrieve this SHA-hash?

Or am I overcomplicating things here? I remember not having to do git add for directories, as they are added with the files in them. Is it sufficient to only add the files from my source-directory?

1

There are 1 best solutions below

0
Juergen On

Thee is nothing special about it, just put the full path from the root in the commit:

blob
mark :14
data 34
File 6 - rev 1
SubDir: TestFiles1

commit refs/heads/master
mark :15
author abc <[email protected]> 1507618733 +0200
committer abc <[email protected]> 1507618733 +0200
data 3
C3
from :10
M 100644 :11 TF1.txt
M 100644 :12 TF3.txt
M 100644 :13 TF5.txt
M 100644 :14 TestFiles1/TF6.txt

You can simply verify the semantics/syntax of fast-import in creating the needed git structure by hand and do a fast-export into a file. In that case I stumbled over the fact, that fast-import needs '/' and windows uses '\'...