Hi,
I need to checkout kernel revisions by branch, commit id, or tag before
building and testing them.
Here is my patch to extend server/git.py and server/git_kernel.py
I'm very open for any kind of suggestions.
The following new methods exist in GitKernel()
* checkout - Check out a certain branch, tag or revision. Optional
a local branch name can be given for -b
* show_branch - print the current local branch
* show_branches - print the local and/or remote branches
* show_revision - print the current tip commit id (checked out revision)
* extended install - optional a commit id / revision that is checked out before
patching, configure, and build
Therefore the following methods were added to Git()
* get_revision() - To print the current tip commit id (aka revision).
* checkout() - Check out a certain branch, tag or revision.
* get_branch() - return the branches depending on options
Risk: Low (Just extends functionality, doesn't change existing one.)
Visibility: Users who build Linux kernels may profit.
Bye,
Frank
---
diff --git a/server/git.py b/server/git.py
--- a/server/git.py
+++ b/server/git.py
@@ -183,3 +183,69 @@
return True
return False
+
+ def get_revision(self):
+ """
+ Return current HEAD commit id
+ """
+
+ if not self.is_repo_initialized():
+ self.get()
+
+ cmd = 'rev-parse --verify HEAD'
+ gitlog = self.gitcmd(cmd, True)
+ if gitlog.exit_status != 0:
+ print gitlog.stderr
+ raise error.CmdError('Failed to find git sha1 revision', gitlog)
+ else:
+ return gitlog.stdout.strip('\n')
+
+ def checkout(self, remote, local=None):
+ """
+ Check out the git commit id, branch, or tag given by remote.
+
+ Optional give the local branch name as local.
+
+ Note, for git checkout tag git version >= 1.5.0 is required
+ """
+ if not self.is_repo_initialized():
+ self.get()
+
+ assert(isinstance(remote, basestring))
+ if local:
+ cmd = 'checkout -b %s %s' % (local, remote)
+ else:
+ cmd = 'checkout %s' % (remote)
+ gitlog = self.gitcmd(cmd, True)
+ if gitlog.exit_status != 0:
+ print gitlog.stderr
+ raise error.CmdError('Failed to checkout git branch', gitlog)
+ else:
+ print gitlog.stdout
+
+ def get_branch(self, all=False, remote_tracking=False):
+ """
+ Show the branches.
+
+ all - list both remote-tracking branches and local branches.
+ remote_tracking - lists the remote-tracking branches.
+ """
+ if not self.is_repo_initialized():
+ self.get()
+
+ cmd = 'branch --no-color'
+ if all:
+ cmd = " ".join([cmd, "-a"])
+ if remote_tracking:
+ cmd = " ".join([cmd, "-r"])
+
+ gitlog = self.gitcmd(cmd, True)
+ if gitlog.exit_status != 0:
+ print gitlog.stderr
+ raise error.CmdError('Failed to get git branch', gitlog)
+ elif all or remote_tracking:
+ return gitlog.stdout.strip('\n')
+ else:
+ branch = [b.lstrip('* ') for b in gitlog.stdout.split('\n') \
+ if b.startswith('*')][0]
+ return branch
diff --git a/server/git_kernel.py b/server/git_kernel.py
--- a/server/git_kernel.py
+++ b/server/git_kernel.py
@@ -29,21 +29,61 @@
self.__patches = []
self.__config = None
self.__build = None
-
+ self.__branch = None
+ self.__revision = None
def configure(self, config):
self.__config = config
-
def patch(self, patch):
self.__patches.append(patch)
+ def checkout(self, revision, local=None):
+ """
+ Checkout the commit id, branch, or tag
- def install(self, host, build=True, builddir=None):
+ revision:str - name of the git remote branch, revision or tag
+ local:str - name of the local branch, implies -b
+
+ """
+ print 'checking out %s' % (revision,)
+ super(GitKernel, self).checkout(revision)
+ self.__revision = super(GitKernel, self).get_revision()
+ self.__branch = super(GitKernel, self).get_branch()
+ print 'checked out %s on branch %s' % (self.__revision, self.__branch)
+
+ def show_branch(self):
+ """
+ Print the current local branch name
+ """
+ self.__branch = super(GitKernel, self).get_branch()
+ print self.__branch
+
+ def show_branches(self, all=True):
+ """
+ Print the local and remote branches
+ """
+ self.__branch = super(GitKernel, self).get_branch()
+ print super(GitKernel, self).get_branch(all=all)
+
+ def show_revision(self):
+ """
+ Show the current git revision
+ """
+ self.__revision = super(GitKernel, self).get_revision()
+ print self.__revision
+
+ def install(self, host, build=True, builddir=None, revision=None):
# use tmpdir if no builddir specified
# NB: pass a builddir to install() method if you
# need to ensure the build remains after the completion
# of a job
+ # If revision is given, that revision is checked out before
+ if revision:
+ self.checkout(revision)
+ self.__revision = super(GitKernel, self).get_revision()
+ print 'checked out revision: %s' %(self.__revision)
+
if not builddir:
self.__build = os.path.join(host.get_tmp_dir(),"build")
print 'warning: builddir %s is not persistent' %(self.__build)
--
Frank Becker <[email protected]> (jabber|mail) | http://twitter.com/41i3n8
GnuPG: 0xADC29ECD | F01B 5E9C 1D09 981B 5B40 50D3 C80F 7459 ADC2 9ECD
SILC-Net: a8 | Home: http://www.alien8.de | <<</>> http://www.c3d2.de
"> Freedom is just chaos, with better lighting. <" Alan Dean Foster
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest