OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Upload a cherry pick CL to rietveld.""" | |
7 | |
8 import argparse | |
9 import sys | |
10 | |
11 from git_cl import Changelist | |
12 from git_common import run | |
13 from third_party.upload import EncodeMultipartFormData, GitVCS | |
14 from rietveld import Rietveld | |
15 | |
16 | |
17 def cherry_pick(target_branch, commit): | |
18 """Attempt to upload a cherry pick CL to rietveld. | |
19 | |
20 Args: | |
21 target_branch: The branch to cherry pick onto. | |
22 commit: The git hash of the commit to cherry pick. | |
23 """ | |
24 author = run('config', 'user.email') | |
agable
2014/07/15 22:47:20
use config() from git_common, rather than run('con
smut
2014/07/16 17:34:35
Done.
| |
25 | |
26 description = '%s\n\n(cherry picked from commit %s)\n' % ( | |
agable
2014/07/15 22:47:20
I'd lose the parentheses -- match the format creat
smut
2014/07/16 17:34:35
This is the format I get when doing a git cherry-p
| |
27 run('show', '--pretty=%B', '--quiet', commit), commit) | |
agable
2014/07/15 22:47:20
Indent at +4.
smut
2014/07/16 17:34:35
Done.
| |
28 | |
29 parent = run('show', '--pretty=%P', '--quiet', commit) | |
30 print 'Found parent revision:', parent | |
31 | |
32 class EmulateSvnAutoProps(object): | |
33 def __init__(self): | |
34 self.emulate_svn_auto_props = False | |
35 | |
36 content_type, payload = EncodeMultipartFormData([ | |
37 ('base', '%s@%s' % (Changelist().GetRemoteUrl(), target_branch)), | |
agable
2014/07/15 22:47:20
Indent +4.
agable
2014/07/15 22:47:20
Unfortunately, uploading url@branch for the issue
smut
2014/07/16 17:34:35
Done.
smut
2014/07/16 17:34:35
Ah, ok. Then I'll go with your project suggestion.
| |
38 ('cc', run('config', 'rietveld.cc')), | |
39 ('description', description), | |
40 ('project', run('config', 'rietveld.project')), | |
41 ('subject', description.splitlines()[0]), | |
42 ('user', author), | |
43 ], [ | |
44 ('data', 'data.diff', GitVCS(EmulateSvnAutoProps()).PostProcessDiff(run('dif f', parent, commit))), | |
45 ]) | |
46 | |
47 print Rietveld(run('config', 'rietveld.server'), author, None)._send( | |
48 '/upload', payload=payload, content_type=content_type) | |
agable
2014/07/15 22:47:20
Indent +4.
smut
2014/07/16 17:34:35
Done.
| |
49 | |
50 | |
51 def main(): | |
52 parser = argparse.ArgumentParser() | |
53 parser.add_argument( | |
54 '--branch', | |
agable
2014/07/15 22:47:20
Indent +4.
smut
2014/07/16 17:34:35
Done.
| |
55 '-b', | |
56 help='The upstream branch to cherry pick to.', | |
57 metavar='<branch>', | |
58 required=True, | |
59 ) | |
60 parser.add_argument( | |
61 'commit', | |
62 help='SHA to cherry pick.', | |
63 metavar='<commit>', | |
64 ) | |
65 args = parser.parse_args() | |
66 cherry_pick(args.branch, args.commit) | |
67 | |
68 if __name__ == '__main__': | |
69 sys.exit(main()) | |
OLD | NEW |