Skip to content

Commit 5830f63

Browse files
committed
utils: Add 'git_am' helper
We have the same code duplicated in three places and we're going to be making modifications to it shortly. Drag it out to its own function. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 177d600 commit 5830f63

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

git_pw/bundle.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import logging
6-
import subprocess
76
import sys
87

98
import click
@@ -28,14 +27,7 @@ def apply_cmd(bundle_id, args):
2827
bundle = api.detail('bundles', bundle_id)
2928
mbox = api.get(bundle['mbox']).text
3029

31-
cmd = ['git', 'am']
32-
if args:
33-
cmd.extend(args)
34-
else:
35-
cmd.append('-3')
36-
37-
p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
38-
p.communicate(mbox)
30+
utils.git_am(mbox, args)
3931

4032

4133
@click.command(name='download')

git_pw/patch.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import logging
6-
import subprocess
76
import sys
87

98
import arrow
@@ -41,14 +40,7 @@ def apply_cmd(patch_id, series, deps, args):
4140

4241
mbox = api.get(patch['mbox'], {'series': series}).content
4342

44-
cmd = ['git', 'am']
45-
if args:
46-
cmd.extend(args)
47-
else:
48-
cmd.append('-3')
49-
50-
p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
51-
p.communicate(mbox)
43+
utils.git_am(mbox, args)
5244

5345

5446
@click.command(name='download')

git_pw/series.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import logging
6-
import subprocess
76
import sys
87

98
import arrow
@@ -29,14 +28,7 @@ def apply_cmd(series_id, args):
2928
series = api.detail('series', series_id)
3029
mbox = api.get(series['mbox']).text
3130

32-
cmd = ['git', 'am']
33-
if args:
34-
cmd.extend(args)
35-
else:
36-
cmd.append('-3')
37-
38-
p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
39-
p.communicate(mbox)
31+
utils.git_am(mbox, args)
4032

4133

4234
@click.command(name='download')

git_pw/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22
Utility functions.
33
"""
44

5+
import subprocess
6+
import sys
7+
58

69
def trim(string, length=70): # type: (str, int) -> str
710
"""Trim a string to the given length."""
811
return (string[:length - 1] + '...') if len(string) > length else string
12+
13+
14+
def git_am(mbox, args):
15+
"""Execute git-am on a given mbox file."""
16+
cmd = ['git', 'am']
17+
if args:
18+
cmd.extend(args)
19+
else:
20+
cmd.append('-3')
21+
cmd.append(mbox)
22+
23+
p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
24+
p.communicate(mbox)

0 commit comments

Comments
 (0)