[llvm] r305598 - utils: Add a git-r utility for mapping svn revisions to git revisions in the monorepo.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 19 13:26:18 PDT 2017
I'm not interested in participating in an extended bikeshedding debate on
the merits of this or that language. Nor am I interested in rewriting it
myself in some other language. I just wanted to publish a tool that I wrote
that I find useful in the hope that others would too.
I find it sad that this is the reaction, but if people would really prefer
not to have the tool, I will remove it.
Peter
On Mon, Jun 19, 2017 at 12:58 PM, Mehdi AMINI <joker.eph at gmail.com> wrote:
> At least, I'd expect some agreement on llvm-dev if it is OK or not to have
> llvm dev tools depending on go before committing any.
>
>
> --
> Mehdi
>
> 2017-06-19 12:57 GMT-07:00 Mehdi AMINI <joker.eph at gmail.com>:
>
>> I agree, this shouldn't be in go.
>>
>> --
>> Mehdi
>>
>>
>> 2017-06-19 10:59 GMT-07:00 Peter Collingbourne via llvm-commits <
>> llvm-commits at lists.llvm.org>:
>>
>>> I don't particularly care which language it is written in. I chose Go
>>> because I felt most productive in it, and because it seemed entirely
>>> suitable under the coding guidelines (or so I thought).
>>>
>>> If someone wants to rewrite it in python, that's fine with me. But it
>>> seems more useful to have the tool written in Go than not at all.
>>>
>>> Peter
>>>
>>> On Mon, Jun 19, 2017 at 10:02 AM, David Blaikie <dblaikie at gmail.com>
>>> wrote:
>>>
>>>>
>>>>
>>>> On Mon, Jun 19, 2017 at 10:00 AM Peter Collingbourne <peter at pcc.me.uk>
>>>> wrote:
>>>>
>>>>> We already use Go in the LLVM project in a few places (llgo, llvm-go
>>>>> and the Go bindings).
>>>>>
>>>>
>>>> Those somewhat necessarily have to use go - and anyone interested in
>>>> them probably has some context in Go.
>>>>
>>>>
>>>>> We even have a section about it in the coding standards:
>>>>>
>>>>> http://llvm.org/docs/CodingStandards.html#other-languages
>>>>>
>>>>> So I don't see a problem with using Go for this tool, especially given
>>>>> that it is relatively isolated.
>>>>>
>>>>
>>>> Seems like it has broader applicability/usage, though, than the
>>>> existing go usage.
>>>>
>>>> - Dave
>>>>
>>>>
>>>>>
>>>>> Peter
>>>>>
>>>>> On Mon, Jun 19, 2017 at 9:48 AM, David Blaikie <dblaikie at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> I think it's probably best to use a language already used in the LLVM
>>>>>> project (Python? Bash?) than branching out into another language (Go) in
>>>>>> terms of maintainability by other LLVM developers?
>>>>>>
>>>>>> On Fri, Jun 16, 2017 at 3:15 PM Peter Collingbourne via llvm-commits <
>>>>>> llvm-commits at lists.llvm.org> wrote:
>>>>>>
>>>>>>> Author: pcc
>>>>>>> Date: Fri Jun 16 17:15:18 2017
>>>>>>> New Revision: 305598
>>>>>>>
>>>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=305598&view=rev
>>>>>>> Log:
>>>>>>> utils: Add a git-r utility for mapping svn revisions to git
>>>>>>> revisions in the monorepo.
>>>>>>>
>>>>>>> Added:
>>>>>>> llvm/trunk/utils/git-svn/git-r/
>>>>>>> llvm/trunk/utils/git-svn/git-r/git-r.go
>>>>>>>
>>>>>>> Added: llvm/trunk/utils/git-svn/git-r/git-r.go
>>>>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/git-svn
>>>>>>> /git-r/git-r.go?rev=305598&view=auto
>>>>>>> ============================================================
>>>>>>> ==================
>>>>>>> --- llvm/trunk/utils/git-svn/git-r/git-r.go (added)
>>>>>>> +++ llvm/trunk/utils/git-svn/git-r/git-r.go Fri Jun 16 17:15:18 2017
>>>>>>> @@ -0,0 +1,169 @@
>>>>>>> +//===- git-r.go - svn revisions to git revisions
>>>>>>> --------------------------===//
>>>>>>> +//
>>>>>>> +// The LLVM Compiler Infrastructure
>>>>>>> +//
>>>>>>> +// This file is distributed under the University of Illinois Open
>>>>>>> Source
>>>>>>> +// License. See LICENSE.TXT for details.
>>>>>>> +//
>>>>>>> +//===------------------------------------------------------
>>>>>>> ----------------===//
>>>>>>> +//
>>>>>>> +// This is a small program for mapping svn revisions to git
>>>>>>> revisions in the
>>>>>>> +// monorepo.
>>>>>>> +//
>>>>>>> +// To set up:
>>>>>>> +// 1) http://llvm.org/docs/GettingStarted.html#for-developers-to-w
>>>>>>> ork-with-a-git-monorepo
>>>>>>> +// and make sure to follow the instructions for fetching commit
>>>>>>> notes.
>>>>>>> +// 2) go build
>>>>>>> +// 3) cp git-r ~/bin
>>>>>>> +//
>>>>>>> +// To use:
>>>>>>> +// $ git r 1
>>>>>>> +// 09c4b68e68c4fcff64b00e1ac077c4f4a524cbcc
>>>>>>> +//
>>>>>>> +//===------------------------------------------------------
>>>>>>> ----------------===//
>>>>>>> +
>>>>>>> +package main
>>>>>>> +
>>>>>>> +import (
>>>>>>> + "bufio"
>>>>>>> + "bytes"
>>>>>>> + "encoding/gob"
>>>>>>> + "fmt"
>>>>>>> + "log"
>>>>>>> + "os"
>>>>>>> + "os/exec"
>>>>>>> + "strconv"
>>>>>>> + "strings"
>>>>>>> +)
>>>>>>> +
>>>>>>> +func git(args ...string) (*bytes.Buffer, error) {
>>>>>>> + cmd := exec.Command("git", args...)
>>>>>>> +
>>>>>>> + var b bytes.Buffer
>>>>>>> + cmd.Stdout = &b
>>>>>>> + err := cmd.Run()
>>>>>>> +
>>>>>>> + return &b, err
>>>>>>> +}
>>>>>>> +
>>>>>>> +func mkrevmap() []string {
>>>>>>> + revs, err := git("grep", "git-svn-rev", "refs/notes/commits")
>>>>>>> + if err != nil {
>>>>>>> + panic(err)
>>>>>>> + }
>>>>>>> +
>>>>>>> + var revmap []string
>>>>>>> +
>>>>>>> + scanner := bufio.NewScanner(revs)
>>>>>>> + for scanner.Scan() {
>>>>>>> + // refs/notes/commits:00/0b/d4acb
>>>>>>> 454290301c140a1d9c4f7a45aa2fa9c:git-svn-rev: 37235
>>>>>>> +
>>>>>>> + bits := strings.Split(scanner.Text(), ":")
>>>>>>> + gitrev := strings.Replace(bits[1], "/", "", -1)
>>>>>>> + svnrev := bits[3][1:]
>>>>>>> +
>>>>>>> + svnrevn, err := strconv.Atoi(svnrev)
>>>>>>> + if err != nil {
>>>>>>> + panic(err)
>>>>>>> + }
>>>>>>> +
>>>>>>> + if svnrevn >= len(revmap) {
>>>>>>> + newrevmap := make([]string, svnrevn+1)
>>>>>>> + copy(newrevmap, revmap)
>>>>>>> + revmap = newrevmap
>>>>>>> + }
>>>>>>> + revmap[svnrevn] = gitrev
>>>>>>> + }
>>>>>>> +
>>>>>>> + return revmap
>>>>>>> +}
>>>>>>> +
>>>>>>> +type revmap struct {
>>>>>>> + Noterev string
>>>>>>> + Revs []string
>>>>>>> +}
>>>>>>> +
>>>>>>> +func writerevmap(path string, rmap *revmap, svnrev int) {
>>>>>>> + noterevbuf, err := git("rev-parse", "refs/notes/commits")
>>>>>>> + if err != nil {
>>>>>>> + fmt.Fprintf(os.Stderr, "%s: could not find
>>>>>>> refs/notes/commits, see instructions:\n", os.Args[0])
>>>>>>> + fmt.Fprintln(os.Stderr, "
>>>>>>> http://llvm.org/docs/GettingStarted.html#for-developers-to-
>>>>>>> work-with-a-git-monorepo")
>>>>>>> + os.Exit(1)
>>>>>>> + }
>>>>>>> + noterev := noterevbuf.String()
>>>>>>> + noterev = noterev[:len(noterev)-1]
>>>>>>> +
>>>>>>> + if rmap == nil || rmap.Noterev != noterev {
>>>>>>> + var newrmap revmap
>>>>>>> + newrmap.Revs = mkrevmap()
>>>>>>> + newrmap.Noterev = noterev
>>>>>>> +
>>>>>>> + f, err := os.Create(path)
>>>>>>> + if err != nil {
>>>>>>> + panic(err)
>>>>>>> + }
>>>>>>> +
>>>>>>> + enc := gob.NewEncoder(f)
>>>>>>> + err = enc.Encode(newrmap)
>>>>>>> + if err != nil {
>>>>>>> + os.Remove(path)
>>>>>>> + panic(err)
>>>>>>> + }
>>>>>>> +
>>>>>>> + rmap = &newrmap
>>>>>>> + }
>>>>>>> +
>>>>>>> + if svnrev >= len(rmap.Revs) || rmap.Revs[svnrev] == "" {
>>>>>>> + fmt.Fprintf(os.Stderr, "%s: %d: unknown revision\n",
>>>>>>> os.Args[0], svnrev)
>>>>>>> + os.Exit(1)
>>>>>>> + }
>>>>>>> +
>>>>>>> + fmt.Println(rmap.Revs[svnrev])
>>>>>>> +}
>>>>>>> +
>>>>>>> +func main() {
>>>>>>> + if len(os.Args) != 2 {
>>>>>>> + fmt.Fprintf(os.Stderr, "%s: expected a single
>>>>>>> argument\n", os.Args[0])
>>>>>>> + os.Exit(1)
>>>>>>> + }
>>>>>>> + svnrev, err := strconv.Atoi(os.Args[1])
>>>>>>> + if err != nil {
>>>>>>> + fmt.Fprintf(os.Stderr, "%s: %s: expected an integer
>>>>>>> argument\n", os.Args[0], os.Args[1])
>>>>>>> + os.Exit(1)
>>>>>>> + }
>>>>>>> +
>>>>>>> + gitdirbuf, err := git("rev-parse", "--git-common-dir")
>>>>>>> + if err != nil {
>>>>>>> + fmt.Fprintf(os.Stderr, "%s: not in a git
>>>>>>> repository\n", os.Args[0])
>>>>>>> + os.Exit(1)
>>>>>>> + }
>>>>>>> +
>>>>>>> + gitdir := gitdirbuf.String()
>>>>>>> + gitdir = gitdir[:len(gitdir)-1]
>>>>>>> + err = os.Chdir(gitdir)
>>>>>>> + if err != nil {
>>>>>>> + panic(err)
>>>>>>> + }
>>>>>>> +
>>>>>>> + mappath := "git-svn-revmap-cache"
>>>>>>> + f, err := os.Open(mappath)
>>>>>>> + if err != nil {
>>>>>>> + writerevmap(mappath, nil, svnrev)
>>>>>>> + return
>>>>>>> + }
>>>>>>> +
>>>>>>> + dec := gob.NewDecoder(f)
>>>>>>> + var rmap revmap
>>>>>>> + err = dec.Decode(&rmap)
>>>>>>> + if err != nil {
>>>>>>> + writerevmap(mappath, nil, svnrev)
>>>>>>> + return
>>>>>>> + }
>>>>>>> +
>>>>>>> + if svnrev < len(rmap.Revs) && rmap.Revs[svnrev] != "" {
>>>>>>> + fmt.Println(rmap.Revs[svnrev])
>>>>>>> + return
>>>>>>> + }
>>>>>>> +
>>>>>>> + writerevmap(mappath, &rmap, svnrev)
>>>>>>> +}
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> llvm-commits mailing list
>>>>>>> llvm-commits at lists.llvm.org
>>>>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> --
>>>>> Peter
>>>>>
>>>>
>>>
>>>
>>> --
>>> --
>>> Peter
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>
>>>
>>
>
--
--
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170619/b1521d16/attachment.html>
More information about the llvm-commits
mailing list