From eb65d5d7b4846b249c38cf1f03496bf4103a4444 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Mon, 9 Aug 2010 12:50:34 +0200 Subject: Remove all current working directory stuff Only use git.Repo's internal dir tracking. --- src/pyfedpkg/initial_merge.py | 85 ++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/src/pyfedpkg/initial_merge.py b/src/pyfedpkg/initial_merge.py index 65de052..7f60aeb 100755 --- a/src/pyfedpkg/initial_merge.py +++ b/src/pyfedpkg/initial_merge.py @@ -36,8 +36,9 @@ import pyfedpkg __all__ = [ 'add_parser_to', - 'handle_path', 'handle_curdir' + 'handle_path', + 'handle_repo', ] @@ -100,23 +101,6 @@ class Branch(object): return "%(sha)s %(origbranch)s" % self.__dict__ -def do_initial_merge(into, to_merge): - print - print "######## Merging", [ x.localbranch for x in to_merge ], \ - "into", into.localbranch, "########" - pyfedpkg.switch_branch(into.localbranch) - repo = git.Repo() - print "Merging", [ x.origbranch for x in to_merge], "into", into.localbranch - repo.git.merge('-m', 'Initial peudo merge for dist-git setup', - '-s', 'ours', - *[x.origbranch for x in to_merge]) - for t in to_merge: - pyfedpkg.switch_branch(t.localbranch) - print "Merging", into.localbranch, "into", t.localbranch - repo.git.merge(into.localbranch) - pyfedpkg.switch_branch(into.localbranch) - - class Filter(object): """Branch filter @@ -126,25 +110,39 @@ class Filter(object): and call do_initial_merge() for them. """ + def __init__(self, repo): + self.repo = repo + self.__reset() + def __reset(self): self.branch_list = [] - def __init__(self): - self.__reset() - - def __git_merge(self): - head = self.branch_list[-1] - others = self.branch_list[:-1] - do_initial_merge(head, others) + def do_initial_merge(self, into, to_merge): + print "#### Merging", [ x.localbranch for x in to_merge ], \ + "into", into.localbranch, "####" + pyfedpkg.switch_branch(into.localbranch, self.repo.working_tree_dir) + print "Merging", [ x.origbranch for x in to_merge], "into", into.localbranch + self.repo.git.merge('-m', 'Initial peudo merge for dist-git setup', + '-s', 'ours', + *[x.origbranch for x in to_merge]) + for t in to_merge: + pyfedpkg.switch_branch(t.localbranch, self.repo.working_tree_dir) + print "Merging", into.localbranch, "into", t.localbranch + self.repo.git.merge(into.localbranch) + pyfedpkg.switch_branch(into.localbranch, self.repo.working_tree_dir) def flush(self): if len(self.branch_list) < 2: return - # print "Flush", self.branch_list - self.__git_merge() + + head = self.branch_list[-1] + others = self.branch_list[:-1] + self.do_initial_merge(head, others) + self.__reset() def eat(self, item): + """Feed item to the filter. The filter will decide what to do with it.""" if self.branch_list: last = self.branch_list[-1] if last.sha == item.sha: @@ -158,8 +156,8 @@ class Filter(object): self.branch_list = [item] -def handle_curdir(): - repo = git.Repo() +def handle_repo(repo): + print "########", "initial-merge", repo.working_tree_dir, "########" _locals, remotes = pyfedpkg._list_branches(repo=repo) aa = [ Branch(repo.git.rev_parse('%s^{tree}' % b), b) for b in remotes ] aa.sort(cmp_Branch) @@ -167,25 +165,25 @@ def handle_curdir(): for x in aa: print " ", x n = 0 - f = Filter() + f = Filter(repo) while n < len(aa): f.eat(aa[n]) n = n + 1 f.flush() - print - print "FINISHED." + print "########", "/initial-merge", repo.working_tree_dir, "########" + + +def handle_curdir(): + repo = git.Repo() + handle_repo(repo) def handle_path(path=None): if not path: path = os.getcwd() - oldcwd = os.getcwd() - os.chdir(path) - print "########", "Entering", path, "########" - handle_curdir() - print "Leaving", os.getcwd() - os.chdir(oldcwd) + repo = git.Repo(path) + handle_repo(repo) class DirListAction(argparse.Action): @@ -202,8 +200,13 @@ class DirListAction(argparse.Action): def fedpkg_command(args): - for repo in args.repos: - handle_path(repo) + is_first = True + for repo_path in args.repo_path: + if is_first: + is_first = False + else: + print + handle_path(repo_path) _module_doc = __doc__ @@ -214,7 +217,7 @@ def add_parser_to(subparsers): help = 'git merge to join branches with identical trees', formatter_class=argparse.RawDescriptionHelpFormatter, description = _module_doc) - sp.add_argument('repos', metavar='repo-path', + sp.add_argument('repo_path', metavar='repo-path', nargs='*', default=['.'], action=DirListAction, help = 'Path to a repo to initial-merge') -- cgit