Commit | Line | Data |
---|---|---|
4d0ba818 KH |
1 | # -*- coding: utf-8 -*- |
2 | ||
3 | __copyright__ = """ | |
4 | Copyright (C) 2006, Karl Hasselström <kha@treskal.com> | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License version 2 as | |
8 | published by the Free Software Foundation. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | """ | |
19 | ||
20 | import sys, os | |
21 | from optparse import OptionParser, make_option | |
22 | ||
23 | from stgit.commands.common import * | |
24 | from stgit.utils import * | |
5e888f30 | 25 | from stgit.out import * |
4d0ba818 KH |
26 | from stgit import stack, git |
27 | ||
28 | help = 'StGIT-ify any GIT commits made on top of your StGIT stack' | |
29 | usage = """%prog [options] | |
30 | ||
31 | If you have made GIT commits on top of your stack of StGIT patches, | |
32 | many StGIT commands will refuse to work. This command converts any | |
33 | such commits to StGIT patches, preserving their contents. | |
34 | ||
35 | Only GIT commits with exactly one parent can be assimilated; in other | |
36 | words, if you have committed a merge on top of your stack, this | |
37 | command cannot help you.""" | |
38 | ||
39 | options = [] | |
40 | ||
41 | def func(parser, options, args): | |
42 | """Assimilate a number of patches. | |
43 | """ | |
44 | ||
45 | def nothing_to_do(): | |
27ac2b7e | 46 | out.info('No commits to assimilate') |
4d0ba818 KH |
47 | |
48 | top_patch = crt_series.get_current_patch() | |
49 | if not top_patch: | |
50 | return nothing_to_do() | |
51 | ||
52 | victims = [] | |
53 | victim = git.get_commit(git.get_head()) | |
54 | while victim.get_id_hash() != top_patch.get_top(): | |
55 | victims.append(victim) | |
56 | parents = victim.get_parents() | |
57 | if not parents: | |
58 | raise CmdException, 'Commit %s has no parents, aborting' % victim | |
59 | elif len(parents) > 1: | |
60 | raise CmdException, 'Commit %s is a merge, aborting' % victim | |
61 | victim = git.get_commit(parents[0]) | |
62 | ||
63 | if not victims: | |
64 | return nothing_to_do() | |
65 | ||
66 | if crt_series.get_protected(): | |
67 | raise CmdException( | |
68 | 'This branch is protected. Modification is not permitted') | |
69 | ||
70 | patch2name = {} | |
71 | name2patch = {} | |
72 | ||
73 | def name_taken(name): | |
74 | return name in name2patch or crt_series.patch_exists(name) | |
75 | ||
76 | for victim in victims: | |
b839b1cf | 77 | patchname = make_patch_name(victim.get_log(), name_taken) |
4d0ba818 KH |
78 | patch2name[victim] = patchname |
79 | name2patch[patchname] = victim | |
80 | ||
81 | victims.reverse() | |
82 | for victim in victims: | |
27ac2b7e KH |
83 | out.info('Creating patch "%s" from commit %s' |
84 | % (patch2name[victim], victim)) | |
4d0ba818 KH |
85 | aname, amail, adate = name_email_date(victim.get_author()) |
86 | cname, cmail, cdate = name_email_date(victim.get_committer()) | |
87 | crt_series.new_patch( | |
88 | patch2name[victim], | |
0ec93bfd | 89 | can_edit = False, before_existing = False, commit = False, |
4d0ba818 KH |
90 | top = victim.get_id_hash(), bottom = victim.get_parent(), |
91 | message = victim.get_log(), | |
92 | author_name = aname, author_email = amail, author_date = adate, | |
93 | committer_name = cname, committer_email = cmail) |