summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-03-08 12:29:30 -0500
committerColin Walters <walters@verbum.org>2010-03-08 12:29:30 -0500
commite0ed6cb76011c642b3713b13a3bc5394a6e263f5 (patch)
tree227594d3addf4daea2699da6903951c28ab3622a
parenta4eea738dadd7ad1475421622438d265379a47e6 (diff)
downloadfedpkg-make-pull-e0ed6cb76011c642b3713b13a3bc5394a6e263f5.tar.gz
fedpkg-make-pull-e0ed6cb76011c642b3713b13a3bc5394a6e263f5.tar.xz
fedpkg-make-pull-e0ed6cb76011c642b3713b13a3bc5394a6e263f5.zip
[fedpkg-vcs] Add new 'retarget' command which takes a specific commit
Rename 'pull-update' to 'pull-retarget'.
-rwxr-xr-xfedpkg-vcs49
1 files changed, 42 insertions, 7 deletions
diff --git a/fedpkg-vcs b/fedpkg-vcs
index 15521dc..7093241 100755
--- a/fedpkg-vcs
+++ b/fedpkg-vcs
@@ -58,6 +58,11 @@ class Vcs(object):
def get_abbreviated_id(self, directory):
raise Exception("not implemented")
+ def switch_to_revision(self, directory, newid):
+ """Switch the working tree to the revision identified by newid.
+If newid is None, then switch to the latest upstream."""
+ raise Exception("not implemented")
+
def _vcs_exec(self, *args, **kwargs):
print "Running: %r" % (args[0], )
if not 'stdout' in kwargs:
@@ -111,6 +116,11 @@ class GitVcs(Vcs):
full_id = self.get_id(directory)
return full_id[0:8]
+ def switch_to_revision(self, directory, newid):
+ if newid is None:
+ newid = 'master'
+ self._vcs_exec(['git', 'checkout', newid], cwd=directory)
+
def get_commit_summary_as_filename(self, directory, commitid):
output = subprocess.Popen(['git', 'show', '--format=%f', commitid], stdout=subprocess.PIPE, cwd=directory).communicate()[0]
return output.split('\n')[0]
@@ -333,18 +343,22 @@ class Spec(object):
def __str__(self):
return self._filename
-
-def command_checkout(spec, vcs, vcsdir, args=[], opts={}):
+def _require_checkout(spec, vcs, vcsdir, verbose=False):
if os.path.exists(vcsdir):
- print "VCS directory %r already exists" % (vcsdir, )
+ if verbose:
+ print "VCS directory %r already exists" % (vcsdir, )
return
print "Checking out from %r into new directory %r" % (vcs.get_url(), vcsdir)
vcs.checkout(vcsdir)
+
+def command_checkout(spec, vcs, vcsdir, args=[], opts={}):
+ _require_checkout(spec, vcs, vcsdir, verbose=True)
def command_pull(spec, vcs, vcsdir, args=[], opts={}):
if not os.path.exists(vcsdir):
command_checkout(spec, vcs, vcsdir, args=args, opts=opts)
print "Updating from %r existing directory %r" % (vcs.get_url(), vcsdir)
+ vcs.switch_to_revision(vcsdir, None)
oldid = vcs.get_id(vcsdir)
vcs.update(vcsdir)
newid = vcs.get_id(vcsdir)
@@ -355,10 +369,28 @@ def command_pull(spec, vcs, vcsdir, args=[], opts={}):
f.write('unchanged')
f.close()
sys.exit(0)
-
-def command_pull_update(spec, vcs, vcsdir, args=[], opts={}):
+
+def command_pull_retarget(spec, vcs, vcsdir, args=[], opts={}):
command_pull(spec, vcs, vcsdir, args=args, opts=opts)
+ command_retarget(spec, vcs, vcsdir, args=['HEAD'], opts=opts)
+
+def command_retarget(spec, vcs, vcsdir, args=[], opts={}):
+ _require_checkout(spec, vcs, vcsdir)
+
+ if len(args) != 1:
+ print "Usage: fedpkg-vcs retarget REVISION"
+ sys.exit(1)
+
+ target = args[0]
+
+ vcs.switch_to_revision(vcsdir, target)
+ try:
+ _impl_retarget(spec, vcs, vcsdir, args=[target], opts=opts)
+ finally:
+ vcs.switch_to_revision(vcsdir, None)
+
+def _impl_retarget(spec, vcs, vcsdir, args=[], opts={}):
name = spec.get_name()
version = spec.get_version()
abbrev_id = vcs.get_abbreviated_id(vcsdir)
@@ -428,13 +460,14 @@ def command_cherrypick(spec, vcs, vcsdir, args=[], opts={}):
def main():
valid_commands = { 'checkout': (command_checkout, "Perform an initial checkout of upstream revision control"),
'pull': (command_pull, "Pull the latest upstream code"),
- 'pull-update': (command_pull_update, "Pull the latest upstream, modify spec file to use it"),
+ 'retarget': (command_retarget, "Modify spec to use given commit id"),
+ 'pull-retarget': (command_pull_retarget, "Pull the latest upstream, modify spec file to use it"),
'cherrypick': (command_cherrypick, "Apply a specific commit id as a patch to specfile") }
def usage(ecode):
print ""
print "Usage: fedpkg-vcs COMMAND [-f]"
print "Valid commands:"
- for cmdname in valid_commands:
+ for cmdname in sorted(valid_commands):
(cmdfunc, description) = valid_commands[cmdname]
print " %s: %s" % (cmdname, description)
sys.exit(ecode)
@@ -448,6 +481,8 @@ def main():
usage(1)
cmd = args[0]
+ if cmd == 'pull-update':
+ cmd = 'pull-retarget'
if not cmd in valid_commands:
usage(1)