summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <tsaunier@gnome.org>2016-08-10 10:26:43 -0400
committerThibault Saunier <tsaunier@gnome.org>2016-08-10 12:15:09 -0400
commite9d35eccd77e36b0f8a296727292bf3897f269ee (patch)
tree887357755a93cad355c00cd68b01c7f7ddc9df08
parentfef7843866fcccfffa0f09e04b27bcf53a7373fe (diff)
Use same code path to handle `fetch --checkout` as `fetch` alone
That code was duplicated so unify it. Reviewed-by: Daniel Stone <daniels@collabora.com> Differential Revision: https://phabricator.freedesktop.org/D1271
-rwxr-xr-xgit-phab96
1 files changed, 34 insertions, 62 deletions
diff --git a/git-phab b/git-phab
index ad00594..07fc1c6 100755
--- a/git-phab
+++ b/git-phab
@@ -1609,44 +1609,51 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1609 os.unlink(filename) 1609 os.unlink(filename)
1610 n += 1 1610 n += 1
1611 1611
1612 branch_name = revision.get('branch') 1612 branch_name = self.clean_phab_branch_name(revision.get('branch'),
1613 if not branch_name: 1613 self.differential)
1614 branch_name = self.differential
1615 else:
1616 branch_name = self.differential + "-" + branch_name
1617 1614
1618 remote = "file://" + self.repo.working_dir 1615 remote = "file://" + self.repo.working_dir
1619 with open(os.path.join(self.repo.working_dir, ".git", 1616 with open(os.path.join(self.repo.working_dir, ".git",
1620 "FETCH_HEAD"), 1617 "FETCH_HEAD"),
1621 "w") as fetch_head_file: 1618 "w") as fetch_head_file:
1622 fetch_head_file.write("%s branch '%s' of file://%s" % ( 1619 fetch_head_file.write("%s branch '%s' of %s" % (
1623 self.repo.head.commit.hexsha, branch_name, remote)) 1620 self.repo.head.commit.hexsha, branch_name, remote))
1624 1621
1625 current_branch.checkout() 1622 current_branch.checkout()
1623 commit = self.repo.commit('FETCH_HEAD')
1626 1624
1627 return remote, branch_name 1625 return commit, remote, branch_name
1628 1626
1629 def do_fetch(self): 1627 def do_fetch(self):
1630 if not self.differential and not self.task: 1628 if not self.differential and not self.task:
1631 self.die("No task or revision provided. Aborting.") 1629 self.die("No task or revision provided. Aborting.")
1632 1630
1633 if self.checkout:
1634 self.do_checkout()
1635 return
1636
1637 if self.differential: 1631 if self.differential:
1638 infos = self.fetch_from_revision() 1632 commit, remote, branch_name = self.fetch_from_revision()
1639 if not isinstance(infos[0], git.Commit):
1640 remote, branch_name = self.create_fake_fetch(*infos)
1641 else:
1642 commit, branch_name = infos
1643 remote = self.staging_url
1644 else: 1633 else:
1645 commit, remote, branch_name = self.fetch_from_task() 1634 commit, remote, branch_name = self.fetch_from_task()
1646 1635
1647 print("From %s\n" 1636 if not self.checkout:
1648 " * branch %s -> FETCH_HEAD" % ( 1637 print("From %s\n"
1649 remote, branch_name)) 1638 " * branch %s -> FETCH_HEAD" % (
1639 remote, branch_name))
1640 return
1641
1642 self.checkout_branch(commit, remote, branch_name)
1643
1644 def clean_phab_branch_name(self, branch_name, default):
1645 if not branch_name or branch_name in ['master']:
1646 return default
1647
1648 revision = self.revision_from_branchname(branch_name)
1649 if revision:
1650 return branch_name[len(revision + '-'):]
1651
1652 task = self.task_from_branchname(branch_name)
1653 if task:
1654 return branch_name[len(task + '-'):]
1655
1656 return branch_name
1650 1657
1651 def fetch_from_revision(self): 1658 def fetch_from_revision(self):
1652 did = self.differential.strip("D") 1659 did = self.differential.strip("D")
@@ -1654,39 +1661,17 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1654 revision, diff = self.get_revision_and_diff(diff=did) 1661 revision, diff = self.get_revision_and_diff(diff=did)
1655 1662
1656 if not self.fetch_staging_commits(diff): 1663 if not self.fetch_staging_commits(diff):
1657 return revision, diff 1664 return self.create_fake_fetch(revision, diff)
1658 1665
1659 return (self.repo.rev_parse("FETCH_HEAD"), 1666 return (self.repo.rev_parse("FETCH_HEAD"), self.staging_url,
1660 self.differential + '-' + revision['branch']) 1667 self.clean_phab_branch_name(revision['branch'],
1668 self.differential))
1661 1669
1662 def do_checkout(self): 1670 def checkout_branch(self, commit, remote, remote_branch_name):
1663 pq = None
1664 if self.differential: 1671 if self.differential:
1665 infos = self.fetch_from_revision() 1672 branchname_match_method = self.revision_from_branchname
1666 if not isinstance(infos[0], git.Commit): 1673 branch_name = self.differential
1667 branchname_match_method = self.revision_from_branchname
1668 branch_name = self.differential
1669 else:
1670 pq = self.get_differentials_to_apply_for_revision()
1671 if not pq:
1672 print("Not differential to apply.")
1673 return
1674
1675 revision, diff = pq[-1]
1676 base_commit = diff.get("sourceControlBaseRevision")
1677 if not base_commit:
1678 self.die("No information about the base commit"
1679 "from which to checkout %s branch"
1680 % self.differential)
1681 commit = self.repo.rev_parse(base_commit)
1682 if not commit:
1683 self.die("Could not checkout base commit %s from"
1684 "which to checkout %s" % (base_commit,
1685 self.differential))
1686 branchname_match_method = self.revision_from_branchname
1687 remote_branch_name = branch_name = self.differential
1688 else: 1674 else:
1689 commit, remote, remote_branch_name = self.fetch_from_task()
1690 branchname_match_method = self.task_from_branchname 1675 branchname_match_method = self.task_from_branchname
1691 branch_name = self.task 1676 branch_name = self.task
1692 1677
@@ -1710,19 +1695,6 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1710 1695
1711 branch.checkout() 1696 branch.checkout()
1712 1697
1713 if pq:
1714 n = 0
1715 while pq != []:
1716 (r, d) = pq.pop()
1717
1718 filename = self.write_patch_file(r, d)
1719 print("Applying D{}".format(r['id']))
1720
1721 self.am_patch(filename, None)
1722 os.unlink(filename)
1723 n += 1
1724 return
1725
1726 def do_browse(self): 1698 def do_browse(self):
1727 urls = [] 1699 urls = []
1728 if not self.objects: 1700 if not self.objects: