by
Changes to 4 files · Browse files at 17f51f416b19 Showing diff from parent 8acce018fc41 cc8a271a821a Diff from another changeset...
@@ -98,10 +98,73 @@ except ApplyDeltaError, e:
print "\t%s: Unable to apply delta: %r" % (name, e)
+def cmd_init(args):
+ from dulwich.repo import Repo
+ import os
+ import sys
+ opts, args = getopt(args, "", ["--bare"])
+ opts = dict(opts)
+
+ if args == []:
+ path = os.getcwd()
+ else:
+ path = args[0]
+
+ if not os.path.exists(path):
+ os.mkdir(path)
+
+ if "--bare" in opts:
+ Repo.init_bare(path)
+ else:
+ Repo.init(path)
+
+
+def cmd_clone(args):
+ from dulwich.client import TCPGitClient, SimpleFetchGraphWalker
+ from dulwich.repo import Repo
+ import os
+ import sys
+ opts, args = getopt(args, "", [])
+ opts = dict(opts)
+
+ if args == []:
+ print "usage: dulwich clone host:path [PATH]"
+ sys.exit(1)
+
+ if not ":" in args[0]:
+ print "Usage: dulwich clone host:path [PATH]"
+ sys.exit(1)
+ (host, host_path) = args.pop(0).split(":", 1)
+ client = TCPGitClient(host)
+
+ if len(args) > 0:
+ path = args.pop(0)
+ else:
+ path = host_path.split("/")[-1]
+
+ if not os.path.exists(path):
+ os.mkdir(path)
+ Repo.init(path)
+ r = Repo(path)
+ determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
+ graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)
+ f, commit = r.object_store.add_pack()
+ try:
+ client.fetch_pack(host_path, determine_wants, graphwalker, f.write,
+ sys.stdout.write)
+ f.close()
+ commit()
+ except:
+ f.close()
+ raise
+
+
commands = {
"fetch-pack": cmd_fetch_pack,
"dump-pack": cmd_dump_pack,
+ "init": cmd_init,
"log": cmd_log,
+ "clone": cmd_clone,
}
if len(sys.argv) < 2:
|
@@ -26,6 +26,7 @@ write_pack_index_v2,
PackData,
)
+import tempfile
PACKDIR = 'pack'
class ObjectStore(object):
@@ -112,3 +113,10 @@ if os.path.getsize(path) > 0:
self.move_in_pack(path)
return f, commit
+
+ def add_objects(self, objects):
+ if len(objects) == 0:
+ return
+ f, commit = self.add_pack()
+ write_pack_data(f, objects, len(objects))
+ commit()
|
@@ -268,6 +268,12 @@ return "<Repo at %r>" % self.path
@classmethod
+ def init(cls, path, mkdir=True):
+ controldir = os.path.join(path, ".git")
+ os.mkdir(controldir)
+ cls.init_bare(controldir)
+
+ @classmethod
def init_bare(cls, path, mkdir=True):
for d in [["objects"],
["objects", "info"],
|
@@ -29,5 +29,12 @@ o = ObjectStore("foo")
self.assertEquals([], o.packs)
+ def test_add_objects_empty(self):
+ o = ObjectStore("foo")
+ o.add_objects([])
-
+ def test_add_commit(self):
+ o = ObjectStore("foo")
+ # TODO: Argh, no way to construct Git commit objects without
+ # access to a serialized form.
+ o.add_objects([])
|
Loading...