Permalink
Browse files

Partial and full uploading of submodules

 - Import `git.Submodule`

 - Only build up the directory structure for file status A(dded). For a
   blob build up all the parent directories, for a submodule build the
   parent directory and the submodule directory itself.

 - Upload the item. If it's not a blob get the properties of the
   submodule:

   * `module` (used like `git.Repo`)
   * `module_tree` (the tree to upload)
   * `module_oldtree` (the tree to diff against for M, an empty tree for A)
   * `module_base` (Base directory of the module. Change to this
     directory, then perform a recursive upload_diff. Don't forget to
     change back afterwards.)

 - Bump copyright to 2011

 - Add myself to the copyright notice.
   Thanks for the invitation to do so.

Possible uncovered cases:

 - A submodule could be manually deleted from `.gitmodules` and
   `.git/config`. File status is D in that case, but the submodules files
   will not be deleted on the server.
   A warning will be logged in this case.

 - Be `file` the path of a submodule. Then `tree[file]` is a
   `git.Submodule`. However `oldtree[file]` must not necessarily be a
   submodule.
   An assertion will fail in this case.

Also note:

 - The optional quiet parameter on upload_blob is no longer used, but I
   didn't remove it.
  • Loading branch information...
1 parent b966b12 commit a3fcd3e00c61a2a48ff5cd49612850f557635119 @niklasf niklasf committed May 13, 2011
Showing with 32 additions and 10 deletions.
  1. +32 −10 git-ftp.py
View
@@ -3,8 +3,9 @@
"""
git-ftp: painless, quick and easy working copy syncing over FTP
-Copyright (c) 2008-2009
-Edward Z. Yang <ezyang@mit.edu> and Mauro Lizaur <mauro@cacavoladora.org>
+Copyright (c) 2008-2011
+Edward Z. Yang <ezyang@mit.edu>, Mauro Lizaur <mauro@cacavoladora.org> and
+Niklas Fiekas <niklas.fiekas@googlemail.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
@@ -44,7 +45,7 @@
# convenience keep track of this if you access the blob from an index.
# This ends up considerably simplifying our code, but do be careful!
-from git import Tree, Blob, Repo, Git
+from git import Tree, Blob, Repo, Git, Submodule
class BranchNotFound(Exception):
pass
@@ -252,19 +253,40 @@ def generate_parent_dirs(x):
break
else:
node = tree[file]
- assert isinstance(node, Blob)
- try:
- upload_blob(node, ftp)
- except ftplib.error_perm:
- # ok, try building up the directory
+
+ if status == "A":
+ # try building up the parent directory
subtree = tree
- for c in file.split("/")[:-1]:
+ if isinstance(node, Blob):
+ directories = file.split("/")[:-1]
+ else:
+ # for submodules also add the directory itself
+ assert isinstance(node, Submodule)
+ directories = file.split("/")
+ for c in directories:
subtree = subtree/c
try:
ftp.mkd(subtree.path)
except ftplib.error_perm:
pass
- upload_blob(node, ftp, quiet = True)
+
+ if isinstance(node, Blob):
+ upload_blob(node, ftp)
+ else:
+ module = node.module()
+ module_tree = module.commit(node.hexsha).tree
+ if status == "A":
+ module_oldtree = get_empty_tree(module)
+ else:
+ oldnode = oldtree[file]
+ assert isinstance(oldnode, Submodule) # TODO: What if not?
+ module_oldtree = module.commit(oldnode.hexsha).tree
+ module_base = posixpath.join(base, node.path)
+ logging.info('Entering submodule %s', node.path)
+ ftp.cwd(module_base)
+ upload_diff(module, module_oldtree, module_tree, ftp, module_base)
+ logging.info('Leaving submodule %s', node.path)
+ ftp.cwd(base)
def is_special_file(name):
"""Returns true if a file is some special Git metadata and not content."""

0 comments on commit a3fcd3e

Please sign in to comment.