From: Jeff King <peff@peff.net>
To: Hao Wang <billhao@gmail.com>
Cc: Neal Kreitzinger <nkreitzinger@gmail.com>, git@vger.kernel.org
Subject: Re: process committed files in post-receive hook
Date: Thu, 15 Dec 2011 02:23:01 -0500 [thread overview]
Message-ID: <20111215072301.GC1327@sigill.intra.peff.net> (raw)
In-Reply-To: <4EE95523.9030702@gmail.com>
On Wed, Dec 14, 2011 at 06:02:11PM -0800, Hao Wang wrote:
> Thank you all for providing the options. Just so you know I finally
> went with Alexey's suggestion. I used 'git show' to get both a list
> of files in a directory and the content of each file. It works great
> on a bare repository so there is no need to check out a copy on the
> server.
If you are scripting, we usually encourage the use of "plumbing"
commands whose output is guaranteed not to change ("show" is a
"porcelain" command intended to be used by end-users, and it's possible
that its behavior might change from version to version).
The plumbing command to get a directory listing for a tree is "git
ls-tree" (try the "--name-only" option for terse output, and use "-z" if
you want to be robust in the face of filenames with funny characters).
> # get a list of rule files using git show
> def getRuleFileList(rev):
> # run git show
> p = subprocess.Popen(['git', 'show', rev], stdout=subprocess.PIPE)
> p.wait()
> if p.returncode != 0: return None # error
>
> # parse output
> i = 0
> filelist = []
> for line in p.stdout.readlines():
> filelist.append(line)
> p.stdout.close()
> return filelist
Doesn't this put "tree HEAD:foo", as printed by "git show", at the top
of your filelist? Another reason to use ls-tree.
> # read the content of a file
> def readfile(rev):
> # run git show
> p = subprocess.Popen(['git', 'show', rev], stdout=subprocess.PIPE)
> p.wait()
> if p.returncode != 0: return None # error
> return p.stdout.read()
The plumbing for this is "git cat-file blob ...".
-Peff
next prev parent reply other threads:[~2011-12-15 7:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-10 10:29 process committed files in post-receive hook Hao
2011-12-10 11:21 ` Michael Schubert
2011-12-10 12:06 ` Ivan Heffner
2011-12-10 21:31 ` Alexey Shumkin
2011-12-15 1:04 ` Neal Kreitzinger
2011-12-15 2:02 ` Hao Wang
2011-12-15 7:23 ` Jeff King [this message]
2011-12-15 8:19 ` Hao Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111215072301.GC1327@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=billhao@gmail.com \
--cc=git@vger.kernel.org \
--cc=nkreitzinger@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).