Skip to contentSkip to conversation

Teach fast-import to recursively copy files/directories

PATCH New Shawn O. Pearce 1 participant 1 message Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Teach fast-import to recursively copy files/directories

Some source material (e.g. Subversion dump files) perform directory renames by telling us the directory was copied, then deleted in the same revision. This makes it difficult for a frontend to convert such data formats to a fast-import stream, as all the frontend has on hand is "Copy a/ to b/; Delete a/" with no details about what files are in a/, unless the frontend also kept track of all files.

The new 'C' subcommand within a commit allows the frontend to make a recursive copy of one path to another path within the branch, without needing to keep track of the individual file paths. The metadata copy is performed in memory efficiently, but is implemented as a copy-immediately operation, rather than copy-on-write.

With this new 'C' subcommand frontends could obviously implement an 'R' (rename) on their own as a combination of 'C' and 'D' (delete), but since we have already offered up 'R' in the past and it is a trivial thing to keep implemented I'm not going to deprecate it.

---

This and the following changes since commit 9d6f220cc8ffbd71b4c68765b52c3a7c41dd729b:
Josh Triplett (1):
Remove useless uses of cat, and replace with filename arguments

are available in the git repository at:

repo.or.cz:/srv/git/git/fastimport.git master

Marius Storm-Olsen (1):
Fix git-p4 on Windows to not use the Posix sysconf function.

Shawn O. Pearce (2):
Correct trivial typo in fast-import documentation Teach fast-import to recursively copy files/directories

Documentation/git-fast-import.txt | 40 +++++++++++++++--
contrib/fast-import/git-p4 | 6 ++-
fast-import.c | 81 ++++++++++++++++++++++++++++++++++--
t/t9300-fast-import.sh | 83 +++++++++++++++++++++++++++++++++++++
4 files changed, 200 insertions(+), 10 deletions(-)

Hopefully this stuff will make it into 1.5.3 final. This should be the last fastimport update before then.

--

 Documentation/git-fast-import.txt |   40 +++++++++++++++--
 fast-import.c                     |   81 ++++++++++++++++++++++++++++++++++--
 t/t9300-fast-import.sh            |   83 +++++++++++++++++++++++++++++++++++++
 3 files changed, 195 insertions(+), 9 deletions(-)
Documentation/git-fast-import.txt +35 -5
index bf1ba67..30ee98d 100644
@@ -302,7 +302,7 @@ change to the project.
 	data
 	('from' SP <committish> LF)?
 	('merge' SP <committish> LF)?
-	(filemodify | filedelete | filerename | filedeleteall)*
+	(filemodify | filedelete | filecopy | filerename | filedeleteall)*
 	LF
 ....
 
@@ -325,13 +325,13 @@ commit message use a 0 length data.  Commit messages are free-form
 and are not interpreted by Git.  Currently they must be encoded in
 UTF-8, as fast-import does not permit other encodings to be specified.
 
-Zero or more `filemodify`, `filedelete`, `filerename` and
-`filedeleteall` commands
+Zero or more `filemodify`, `filedelete`, `filecopy`, `filerename`
+and `filedeleteall` commands
 may be included to update the contents of the branch prior to
 creating the commit.  These commands may be supplied in any order.
 However it is recommended that a `filedeleteall` command preceed
-all `filemodify` and `filerename` commands in the same commit, as
-`filedeleteall`
+all `filemodify`, `filecopy` and `filerename` commands in the same
+commit, as `filedeleteall`
 wipes the branch clean (see below).
 
 `author`
@@ -497,6 +497,27 @@ here `<path>` is the complete path of the file or subdirectory to
 be removed from the branch.
 See `filemodify` above for a detailed description of `<path>`.
 
+`filecopy`
+^^^^^^^^^^^^
+Recursively copies an existing file or subdirectory to a different
+location within the branch.  The existing file or directory must
+exist.  If the destination exists it will be completely replaced
+by the content copied from the source.
+
+....
+	'C' SP <path> SP <path> LF
+....
+
+here the first `<path>` is the source location and the second
+`<path>` is the destination.  See `filemodify` above for a detailed
+description of what `<path>` may look like.  To use a source path
+that contains SP the path must be quoted.
+
+A `filecopy` command takes effect immediately.  Once the source
+location has been copied to the destination any future commands
+applied to the source location will not impact the destination of
+the copy.
+
 `filerename`
 ^^^^^^^^^^^^
 Renames an existing file or subdirectory to a different location
@@ -517,6 +538,15 @@ location has been renamed to the destination any future commands
 applied to the source location will create new files there and not
 impact the destination of the rename.
 
+Note that a `filerename` is the same as a `filecopy` followed by a
+`filedelete` of the source location.  There is a slight performance
+advantage to using `filerename`, but the advantage is so small
+that it is never worth trying to convert a delete/add pair in
+source material into a rename for fast-import.  This `filerename`
+command is provided just to simplify frontends that already have
+rename information and don't want bother with decomposing it into a
+`filecopy` followed by a `filedelete`.
+
 `filedeleteall`
 ^^^^^^^^^^^^^^^
 Included in a `commit` command to remove all files (and also all
fast-import.c +77 -4

120 lines not on this page · raw message

t/t9300-fast-import.sh +83 -0

87 lines not on this page · raw message

Signature · 1 line
1.5.3.rc0.900.ge7568