fast-import: add 'ls' command
PATCH v3 1/1 fast-import: add 'ls' command
From: David Barr <[email protected]>
Date: Thu, 2 Dec 2010 21:40:20 +1100
Introduce an "ls" command to read directory entries from the active commit or a named commit. This allows printing a blob from the active commit or copying a blob or tree from a previous commit for use in the current one.
There are two forms of the 'ls' command: the two-argument form prints the entry at <path> for the tree underlying the tree, commit, or tag named by <dataref>:
'ls' SP <dataref> SP <path> LF
The one-argument form prints the entry at <path> in fast-import's active commit.
'ls' SP <path> LF
Dirty hack: for now, git fast-import will treat missing paths as empty subtrees and print them as
040000 tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 path/to/nowhere
to avoid confusing frontends that inserted such a path before. But an alternate output format
'missing' SP <path> LF
is also allowed, so other backends (and perhaps git some day) can convey the difference between an empty subtree and no subtree at all.
Proposed updates to svn-fe use the "ls" command to delegate responsibility for knowledge about paths to git. Reading such information from the target repository instead of a data structure maintained by the fast-import frontend simplifies the frontend a great deal and means support for resuming an import in a separate fast-import run (i.e., incremental import) is basically free.
---
Last seen at [1].
Changes from v2:
- clearer documentation
- has a corresponding 'feature'
- tiny clarification to parse_ls
- rebased against master (also applies on maint fwiw).
The vcs-fast-import-devs don't seem to dislike it, at least. :)
Thanks for the help and patience.
[1] http://thread.gmane.org/gmane.comp.version-control.git/162698/focus=165553
Documentation/git-fast-import.txt | 65 ++++++++++++++- fast-import.c | 164 ++++++++++++++++++++++++++++++++++++- t/t9300-fast-import.sh | 112 +++++++++++++++++++++++-- 3 files changed, 327 insertions(+), 14 deletions(-)
Documentation/git-fast-import.txt +62 -3
@@ -196,7 +196,8 @@ especially when a higher level language such as Perl, Python or Ruby is being used. fast-import is very strict about its input. Where we say SP below we mean -*exactly* one space. Likewise LF means one (and only one) linefeed. +*exactly* one space. Likewise LF means one (and only one) linefeed +and HT one (and only one) horizontal tab. Supplying additional whitespace characters will cause unexpected results, such as branch names or file names with leading or trailing spaces in their name, or early termination of fast-import when it encounters
@@ -334,6 +335,11 @@ and control the current import process. More detailed discussion format to the file descriptor set with `--cat-blob-fd` or `stdout` if unspecified. +`ls`:: + Causes fast-import to print a directory entry in 'ls-tree' + format to the file descriptor set with `--cat-blob-fd` or + `stdout` if unspecified. + `feature`:: Require that fast-import supports the specified feature, or abort if it does not.
@@ -919,6 +925,57 @@ This command can be used anywhere in the stream that comments are accepted. In particular, the `cat-blob` command can be used in the middle of a commit but not in the middle of a `data` command. +`ls` +~~~~ +Prints a directory entry to a file descriptor previously arranged with +the `--cat-blob-fd` argument. This allows printing a blob from the +active commit (with `cat-blob`) or copying a blob or tree from a +previous commit for use in the current one (with `filemodify`). + +The `ls` command can be used anywhere in the stream that comments are +accepted, including the middle of a commit. + +Reading from the active commit:: + This form can only be used in the middle of a `commit`. + The path names a directory entry within fast-import's + active commit. The path must be quoted in this case. ++ +.... + 'ls' SP <path> LF +.... + +Reading from a named tree:: + The `<dataref>` can be a mark reference (`:<idnum>`) or the + full 40-byte SHA-1 of a Git tag, commit, or tree object, + preexisting or waiting to be written. + The path is relative to the top level of the tree + named by `<dataref>`. ++ +.... + 'ls' SP <dataref> SP <path> LF +.... + +See `filemodify` above for a detailed description of `<path>`. + +Output uses the same format as `git ls-tree <tree> -- <path>`: + +==== + <mode> SP ('blob' | 'tree' | 'commit') SP <dataref> HT <path> LF +==== + +The <dataref> represents the blob, tree, or commit object at <path> +and can be used in later 'cat-blob', 'filemodify', or 'ls' commands. + +Git repositories do not distinguish between missing paths and empty +subtrees. If a path is not found, 'git fast-import' will report it as +an empty tree. Backends that do have a notion of empty trees may write + +==== + missing SP <path> LF +==== + +for paths that do not correspond to a blob or subtree. + `feature` ~~~~~~~~~ Require that fast-import supports the specified feature, or abort if
@@ -946,8 +1003,10 @@ import-marks:: any "feature import-marks" command in the stream. cat-blob:: - Ignored. Versions of fast-import not supporting the - "cat-blob" command will exit with a message indicating so. +ls:: + Require that the backend support the 'cat-blob' or 'ls' command. + Versions of fast-import not supporting the specified command + will exit with a message indicating so. This lets the import error out early with a clear message, rather than wasting time on the early part of an import before the unsupported command is detected.
fast-import.c +161 -3
216 lines not on this page · raw message
t/t9300-fast-import.sh +104 -8
136 lines not on this page · raw message
Signature · 1 line
1.7.4
Quoted 12 lines · Jonathan Nieder
From: David Barr <[email protected]>
Date: Thu, 2 Dec 2010 21:40:20 +1100Introduce an "ls" command to read directory entries from the active commit or a named commit. This allows printing a blob from the active commit or copying a blob or tree from a previous commit for use in the current one.
There are two forms of the 'ls' command: the two-argument form prints the entry at <path> for the tree underlying the tree, commit, or tag named by <dataref>:
Quoted 6 lines
'ls' SP <dataref> SP <path> LF
The one-argument form prints the entry at <path> in fast-import's active commit.
'ls' SP <path> LF
Is this really "ls"?
Obviously, an extended SHA-1 that is accepted by the normal git does not have a notion of "marks", but modulo that, the first one looks to me very similar to "rev-parse <ref>:<path>" in spirit, which suggests that "the path in the current one" might be better spelled as "rev-parse :<path>" to make the syntax and the concept more consistent across parts of the system. If it makes sense to allow arbitary <committish> (or <treeish> for that matter) for the <dataref> part of the parameter, this observation becomes even more true, no?
Having said that, I do not deeply care about the token "ls" itself. I just reacted to "<dataref> SP <path>" part.
Quoted 6 lines
Dirty hack: for now, git fast-import will treat missing paths as empty subtrees and print them as
040000 tree
4b825dc642cb6eb9a060e54bf8d69288fbee4904path/to/nowhereto avoid confusing frontends that inserted such a path before.
Sorry, but I am not quite sure what this paragraph is trying to say.
(+cc: vcs-fast-import-devs)
Quoted 5 lines · Junio C Hamano
Quoted 5 lines
There are two forms of the 'ls' command: the two-argument form prints the entry at <path> for the tree underlying the tree, commit, or tag named by <dataref>:
'ls' SP <dataref> SP <path> LF
[...]
Quoted 10 lines
Is this really "ls"?
Obviously, an extended SHA-1 that is accepted by the normal git does not have a notion of "marks", but modulo that, the first one looks to me very similar to "rev-parse <ref>:<path>" in spirit, which suggests that "the path in the current one" might be better spelled as "rev-parse :<path>" to make the syntax and the concept more consistent across parts of the system. If it makes sense to allow arbitary <committish> (or <treeish> for that matter) for the <dataref> part of the parameter, this observation becomes even more true, no?
I suppose so. It is inspired by "git ls-tree <ref> -- <path>", and it is convenient that it prints the mode, too (otherwise how do we tell a regular file from a symlink?).
Quoted 8 lines
Quoted 6 lines
Dirty hack: for now, git fast-import will treat missing paths as empty subtrees and print them as
040000 tree
4b825dc642cb6eb9a060e54bf8d69288fbee4904path/to/nowhereto avoid confusing frontends that inserted such a path before.
Sorry, but I am not quite sure what this paragraph is trying to say.
Where $empty is the empty tree, I might expect:
M 040000 $emptytree some/subdirectory
ls "some/subdirectory"
to result in
040000 tree $empty some/subdirectory
On the other hand, I also would expect
D some/subdirectory
ls "some/subdirectory"
to result in
missing some/subdirectory
Since git fast-import (like git itself) does not track empty subdirectories, the state being reported in both these cases is the same. How can it tell the difference between the two? So the patch arbitrarily uses the former behavior (reporting nonexistent dirents as though they were the empty subtree), which seems to work well in practice.
It is probably be less confusing to use "missing" and let frontends handle that rather shielding the frontend from reality. Like so:
--- Documentation/git-fast-import.txt | 7 +---- fast-import.c | 32 ++++++++++++-------------- t/t9300-fast-import.sh | 44 ++++++++++-------------------------- 3 files changed, 29 insertions(+), 54 deletions(-)
Documentation/git-fast-import.txt +2 -5
@@ -967,16 +967,13 @@ Output uses the same format as `git ls-tree <tree> {litdd} <path>`: The <dataref> represents the blob, tree, or commit object at <path> and can be used in later 'cat-blob', 'filemodify', or 'ls' commands. -Git repositories do not distinguish between missing paths and empty -subtrees. If a path is not found, 'git fast-import' will report it as -an empty tree. Backends that do have a notion of empty trees may write +If there is no file or subtree at that path, 'git fast-import' will +instead report ==== missing SP <path> LF ==== -for paths that do not correspond to a blob or subtree. - `feature` ~~~~~~~~~ Require that fast-import supports the specified feature, or abort if
fast-import.c +15 -17
@@ -2931,12 +2931,20 @@ static void print_ls(int mode, const unsigned char *sha1, const char *path)S_ISDIR (mode) ? tree_type : blob_type; -/* mode SP type SP object_name TAB path LF */ -strbuf_reset (&line); -strbuf_addf (&line,"%06o %s %s\t" , - mode, type,sha1_to_hex (sha1)); -quote_c_style (path, &line,NULL ,0 ); -strbuf_addch (&line,'\n' ); +if (!mode) { +/* missing SP path LF */ +strbuf_reset (&line); +strbuf_addstr (&line,"missing " ); +quote_c_style (path, &line,NULL ,0 ); +strbuf_addch (&line,'\n' ); + }else { +/* mode SP type SP object_name TAB path LF */ +strbuf_reset (&line); +strbuf_addf (&line,"%06o %s %s\t" , + mode, type,sha1_to_hex (sha1)); +quote_c_style (path, &line,NULL ,0 ); +strbuf_addch (&line,'\n' ); + }cat_blob_write (line.buf, line.len); }
@@ -2978,17 +2986,7 @@ static void parse_ls(struct branch *b)if (S_ISDIR (leaf.versions[1 ].mode))store_tree (&leaf); -if (!leaf.versions[1 ].mode) { -/* -* Missing path? Must be an empty subtree! -* -* When git learns to track empty directories, we can report -* this by saying 'missing "path/to/directory"' instead. -*/ -print_ls (S_IFDIR , (const unsigned char *)EMPTY_TREE_SHA1_BIN , p); - }else { -print_ls (leaf.versions[1 ].mode, leaf.versions[1 ].sha1, p); - } +print_ls (leaf.versions[1 ].mode, leaf.versions[1 ].sha1, p);if (!b || root != &b->branch_tree)release_tree_entry (root); }
t/t9300-fast-import.sh +12 -32
70 lines not on this page · raw message
Signature · 1 line
1.7.4
Quoted 2 lines · Jonathan Nieder
It is probably be less confusing to use "missing" and let frontends handle that rather shielding the frontend from reality. Like so:
^
This should say "rather than", as in: "It is confusing to lie to the frontend; let's not do that."
Side note: this adds some complication to frontends. For example, to copy some/path from the commit called :5, without this change, one could do
echo 'ls :5 some/path'
read -r mode type dataref path
echo "M $mode $dataref $path"
but now one would have to do:
echo 'ls :5 some/path'
read -r mode rest
case $mode in
missing)
echo "D some/path"
;;
*)
dataref=${rest#* }
echo "M $mode $dataref some/path"
;;
esac
The former is simpler; the latter is more explicit and probably less confusing.
Sorry for the nonsense.
Jonathan
Heya,
Quoted 4 lines · Jonathan Nieder
Introduce an "ls" command to read directory entries from the active commit or a named commit. This allows printing a blob from the active commit or copying a blob or tree from a previous commit for use in the current one.
Useful addition I think. What happens if you ask it for a path that is not a directory?
Signature · 3 lines
Cheers, Sverre Rabbelier
Quoted 9 lines · Sverre Rabbelier
Quoted 4 lines · Jonathan Nieder
Introduce an "ls" command to read directory entries from the active commit or a named commit. This allows printing a blob from the active commit or copying a blob or tree from a previous commit for use in the current one.
Useful addition I think. What happens if you ask it for a path that is not a directory?
Hmm, the documentation was not at all clear, then. Good catch.
The answer is that it always prints a single dirent, whether the path supplied names a file or a directory.
FE> ls :1 Documentation gfi> 040000 tree 9e6c2b599341d28a2a375f8207507e0a2a627fe9 Documentation FE> ls :1 git.c gfi> 100644 blob 23610aa0366ebe36e65e78fb8c5fba3f2d0b8f77 git.c FE> ls :1 thisfiledoesnotexist gfi> 040000 tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 thisfiledoesnotexist FE> ls :1 RelNotes gfi> 120000 blob b942e499449d97aeb50c73ca2bdc1c6e6d528743 RelNotes FE> ls 9e6c2b599341d28a2a375f8207507e0a2a627fe9 git-fast-import.txt gfi> 100644 blob 4f92954396e3f0f97e75b6838a5635b583708870 git-fast-import.txt FE> cat-blob b942e499449d97aeb50c73ca2bdc1c6e6d528743 gfi> b942e499449d97aeb50c73ca2bdc1c6e6d528743 blob 32 gfi> Documentation/RelNotes/1.7.4.txt
Maybe this patch (for squashing) would help.
---
Documentation/git-fast-import.txt +9 -8
@@ -336,9 +336,9 @@ and control the current import process. More detailed discussion `stdout` if unspecified. `ls`:: - Causes fast-import to print a directory entry in 'ls-tree' - format to the file descriptor set with `--cat-blob-fd` or - `stdout` if unspecified. + Causes fast-import to print a line describing a directory + entry in 'ls-tree' format to the file descriptor set with + `--cat-blob-fd` or `stdout` if unspecified. `feature`:: Require that fast-import supports the specified feature, or
@@ -927,10 +927,11 @@ middle of a commit but not in the middle of a `data` command. `ls` ~~~~ -Prints a directory entry to a file descriptor previously arranged with -the `--cat-blob-fd` argument. This allows printing a blob from the -active commit (with `cat-blob`) or copying a blob or tree from a -previous commit for use in the current one (with `filemodify`). +Prints information about the object at a path to a file descriptor +previously arranged with the `--cat-blob-fd` argument. This allows +printing a blob from the active commit (with `cat-blob`) or copying a +blob or tree from a previous commit for use in the current one (with +`filemodify`). The `ls` command can be used anywhere in the stream that comments are accepted, including the middle of a commit.
@@ -957,7 +958,7 @@ Reading from a named tree:: See `filemodify` above for a detailed description of `<path>`. -Output uses the same format as `git ls-tree <tree> -- <path>`: +Output uses the same format as `git ls-tree <tree> {litdd} <path>`: ==== <mode> SP ('blob' | 'tree' | 'commit') SP <dataref> HT <path> LF
Heya,
Quoted 4 lines · Jonathan Nieder
Hmm, the documentation was not at all clear, then. Good catch.
The answer is that it always prints a single dirent, whether the path supplied names a file or a directory.
Ok, makes sense :).
Signature · 3 lines
Cheers, Sverre Rabbelier