import sys
from getopt import getopt
+from dulwich import porcelain
from dulwich.client import get_transport_and_path
from dulwich.errors import ApplyDeltaError
from dulwich.index import Index
from dulwich.pack import Pack, sha_to_hex
+from dulwich.patch import write_tree_diff
from dulwich.repo import Repo
-from dulwich.server import update_server_info
def cmd_archive(args):
opts, args = getopt(args, "", [])
client, path = get_transport_and_path(args.pop(0))
+ location = args.pop(0)
committish = args.pop(0)
- client.archive(path, committish, sys.stdout.write, sys.stderr.write)
+ porcelain.archive(location, committish, outstream=sys.stdout,
+ errstream=sys.stderr)
+
+
+def cmd_add(args):
+ opts, args = getopt(args, "", [])
+
+ porcelain.add(".", paths=args)
def cmd_fetch_pack(args):
if "--all" in opts:
determine_wants = r.object_store.determine_wants_all
refs = client.fetch(path, r, progress=sys.stdout.write)
+ print "Remote refs:"
+ for item in refs.iteritems():
+ print "%s -> %s" % item
def cmd_log(args):
todo.extend([p for p in commit.parents if p not in done])
+def cmd_diff(args):
+ opts, args = getopt(args, "", [])
+
+ if args == []:
+ print "Usage: dulwich diff COMMITID"
+ sys.exit(1)
+
+ r = Repo(".")
+ commit_id = args[0]
+ commit = r[commit_id]
+ parent_commit = r[commit.parents[0]]
+ write_tree_diff(sys.stdout, r.object_store, parent_commit.tree, commit.tree)
+
+
def cmd_dump_pack(args):
opts, args = getopt(args, "", [])
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)
+ porcelain.init(path, bare=("--bare" in opts))
def cmd_clone(args):
- opts, args = getopt(args, "", [])
+ opts, args = getopt(args, "", ["bare"])
opts = dict(opts)
if args == []:
print "usage: dulwich clone host:path [PATH]"
sys.exit(1)
- client, host_path = get_transport_and_path(args.pop(0))
+ source = args.pop(0)
if len(args) > 0:
- path = args.pop(0)
+ target = args.pop(0)
else:
- path = host_path.split("/")[-1]
+ target = None
- if not os.path.exists(path):
- os.mkdir(path)
- r = Repo.init(path)
- remote_refs = client.fetch(host_path, r,
- determine_wants=r.object_store.determine_wants_all,
- progress=sys.stdout.write)
- r["HEAD"] = remote_refs["HEAD"]
+ porcelain.clone(source, target, bare=("--bare" in opts))
def cmd_commit(args):
opts, args = getopt(args, "", ["message"])
opts = dict(opts)
- r = Repo(".")
- committer = "%s <%s>" % (os.getenv("GIT_COMMITTER_NAME"),
- os.getenv("GIT_COMMITTER_EMAIL"))
- author = "%s <%s>" % (os.getenv("GIT_AUTHOR_NAME"),
- os.getenv("GIT_AUTHOR_EMAIL"))
- r.do_commit(committer=committer, author=author, message=opts["--message"])
+ porcelain.commit(".", message=opts["--message"])
def cmd_update_server_info(args):
- r = Repo(".")
- update_server_info(r)
+ porcelain.update_server_info(".")
commands = {
"clone": cmd_clone,
"archive": cmd_archive,
"update-server-info": cmd_update_server_info,
+ "diff": cmd_diff,
}
if len(sys.argv) < 2: