Commit ca73ad2f authored by Eric S. Raymond's avatar Eric S. Raymond

Implement the blob command and a test for it.

Also, some test rebuilds required by 'Improve some stats messages.'
parent 886e03f3
......@@ -2,6 +2,7 @@
3.25: 2015-06-03
Reading hg is now supported through an extractor class, no plugin required.
Now 'blob' command allows creating new content from lift scripts.
3.24: 2015-05-31
Fix repository-type detection bug introduced in 3.23.
......
......@@ -5390,8 +5390,11 @@ def rename(self, newname):
except OSError as e:
raise Fatal(b"repo rename %s -> %s failed: %s"
% (self.subdir(), self.subdir(newname), e))
def addEvent(self, event):
self.events.append(event)
def addEvent(self, event, where=None):
if where is not None:
self.events.insert(where, event)
else:
self.events.append(event)
self.declare_sequence_mutation()
@memoized_iterator(b"_commits")
def commits(self):
......@@ -9283,7 +9286,7 @@ def do_add(self, line):
try:
markval = int(mark[1:])
except ValueError:
raise Recoverable(b"garbled mark %s in add command" % mark)
raise Recoverable(b"non-numeric mark %s in add command" % mark)
if not isinstance(repo.objfind(mark), Blob):
raise Recoverable(b"mark %s in add command does not refer to a blob")
elif markval >= min(self.selection):
......@@ -9318,6 +9321,28 @@ def do_add(self, line):
fileop.construct(optype, source, target)
event.append_operation(fileop)
def help_blob(self):
print(b"""
Syntax:
blob
Create a blob at mark :1 after renumbering other marks starting from
:2. Data is taken from stdin, which may be a here-doc. This can be
used with the add command to patch data into a repository.
""")
def do_blob(self, line):
"Add a fileop to a specified commit."
if not self.chosen():
complain(b"no repo is loaded")
return
self.chosen().renumber(2)
blob = Blob(self.chosen())
blob.set_mark(":1")
self.chosen().addEvent(blob, where=0)
with RepoSurgeon.LineParse(line, capabilities=["stdin"]) as parse:
blob.set_content(parse.stdin.read())
def help_remove(self):
print(b"""
From a specified commit, remove a specified fileop. The syntax is:
......
......@@ -1333,6 +1333,15 @@ behavior may change in a future release.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>blob</command>
</term>
<listitem>
<para>Create a blob at mark :1 after renumbering other marks starting from
:2. Data is taken from stdin, which may be a here-doc. This can be
used with the add command to patch synthetic data into a repository.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>renumber</command>
</term>
<listitem>
......
blob
mark :1
data 30
The thing that ate Sheboygan.
blob
mark :2
data 20
1234567890123456789
commit refs/heads/master
mark :3
committer Ralf Schlatterbeck <rsc@runtux.com> 0 +0000
data 14
First commit.
M 100644 :2 README
M 100644 :1 creature
blob
mark :4
data 20
0123456789012345678
commit refs/heads/master
mark :5
committer Ralf Schlatterbeck <rsc@runtux.com> 10 +0000
data 15
Second commit.
from :3
M 100644 :4 README
## Patch a synthetic blob into a repository
read <min.fi
blob <<EOF
The thing that ate Sheboygan.
EOF
:3 add M 100644 :1 creature
write -
reposurgeon: 4 items modified.
reposurgeon: 4 items modified by filtering.
blob
mark :1
data 20
......
reposurgeon: 11 items modified.
reposurgeon: 0 items modified.
reposurgeon: 8 items modified.
reposurgeon: 1 items modified.
reposurgeon: 2 items modified.
reposurgeon: 2 items modified.
reposurgeon: 11 items modified by filtering.
reposurgeon: 0 items modified by filtering.
reposurgeon: 8 items modified by filtering.
reposurgeon: 1 items modified by filtering.
reposurgeon: 2 items modified by filtering.
reposurgeon: 2 items modified by filtering.
Following substitution should be a no-op
reposurgeon: 0 items modified.
reposurgeon: 18 items modified.
reposurgeon: 1 items modified.
reposurgeon: 0 items modified by filtering.
reposurgeon: 18 items modified by filtering.
reposurgeon: 1 items modified by filtering.
blob
mark :1
data 134
......
[5]
reposurgeon: 1 items modified.
reposurgeon: 1 items modified by transcoding.
# This stream dump contains a Latin-1 character
blob
mark :398168
......
read <tagify.fi
tagify
reposurgeon: 1 commits tagified.
write -
blob
mark :1
......@@ -86,6 +87,7 @@ Third revision, without fileops.
1..:6 tagify --tipdeletes
reposurgeon: 0 commits tagified.
write -
blob
mark :1
......@@ -172,6 +174,7 @@ Third revision, without fileops.
1..$ tagify --tipdeletes
reposurgeon: 1 commits tagified.
write -
blob
mark :1
......@@ -257,6 +260,7 @@ Sixth revision.
tagify --canonicalize --tipdeletes
reposurgeon: 1 commits tagified.
write -
blob
mark :1
......@@ -341,6 +345,7 @@ Fourth revision, with a fileop doing nothing.
tagify --tagify-merges
reposurgeon: 1 commits tagified.
write -
blob
mark :1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment