plumbing git objects

152 views
Skip to first unread message

Dave MacFarlane

unread,
Dec 2, 2016, 11:27:18 AM12/2/16
to plan9port-dev
I'm adding p9p plumbing support for a text editor/pager that I've been
writing. I'm using 9fans/go for it. Since I use it as my pager, I want
to be able to plumb git objects from git log to git show. I've added
the following rule to my plumbing rules, but something weird seems to
be happening to the working directory that it's executing plumb start
from:

type is text
data matches ('[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]+')
plumb to pager
plumb start git show

This is my code that sends the plumbing message:

func plumb(content []byte, buff *demodel.CharBuffer, v
demodel.Viewport, click int) error {
fid, err := plumblib.Open("send", plan9.OWRITE)
if err != nil {
fmt.Printf("%v", err)
return err
}

wd, _ := os.Getwd()
println("Working directory", wd)
m := plumblib.Message{
Src: "de",
Dst: "",
Dir: wd,
Type: "text",
Data: content,
}
if click != 0 {
m.Attr = &plumblib.Attribute{Name: "click", Value: strconv.Itoa(click)}
}
return m.Send(fid)
}

(Note: I had to vendor 9fans.net/plumb for m.Send to work because of
https://github.com/9fans/go/pull/14)

The debugging println prints the correct working directory, so my
understanding is it should be executing the plumb start from the right
place, but instead I'm getting "fatal: bad object [hash]" errors from
git when I try to plumb a commit from any directory other than the
directory that the p9p plumber was started from.

Is there something obvious I'm missing or any hints for where to poke
around to debug?

- Dave

sqweek

unread,
Dec 2, 2016, 9:34:22 PM12/2/16
to dri...@gmail.com, plan9port-dev
On 2 December 2016 at 23:55, Dave MacFarlane <dri...@gmail.com> wrote:
The debugging println prints the correct working directory, so my
understanding is it should be executing the plumb start from the right
place, but instead I'm getting "fatal: bad object [hash]" errors from
git when I try to plumb a commit from any directory other than the
directory that the p9p plumber was started from.

Because that's the directory the plumber always remains in. The working directory forms part of the plumbing message, but the plumber won't automatically change directories. You can do that yourself by tweaking your plumbing rule - for example here is one that I use to view git commits/objects in acme:

type is text
data matches '[0-9a-f]*[a-f][0-9a-f]*'
data matches '([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]+)'
plumb start rc -c 'cd '$wdir'; cd `{git rev-parse --show-toplevel} && [ -d .git ] && git show '$1' |plumb -i -d edit -a ''action=showdata filename=+git/'$1'''


Can't actually find much documentation on the implications of action=showdata - pinched that bit from the default man page rule.

-sqweek

Dave MacFarlane

unread,
Dec 5, 2016, 10:33:31 AM12/5/16
to sqweek, plan9port-dev
Thanks!

I just assumed that the point of including a dir was so that the
command would start in the dir. Starting it from rc witth the cd $wdir
part fixed it.

- Dave
--
- Dave
Reply all
Reply to author
Forward
0 new messages