Add relative path to jiri snapshot diff.
Bug: [google internal] b/188809674
Testing:
- Unit tests
- Manual testing of jiri diff command.
Change-Id: I0687ff521af44d3405f3f3587df6c6487445cc2e
Change-Id: I012e20b3b02f680654944bb2ecd524fbf83108e3
Reviewed-on: https://fuchsia-review.googlesource.com/c/jiri/+/537870
Reviewed-by: Nathan Mulcahey <nmulcahey@google.com>
Commit-Queue: Ian Kasprzak <iankaz@google.com>
diff --git a/cmd/jiri/diff.go b/cmd/jiri/diff.go
index 98705df..c54fe2b 100644
--- a/cmd/jiri/diff.go
+++ b/cmd/jiri/diff.go
@@ -9,6 +9,7 @@
"fmt"
"net/url"
"os"
+ "path/filepath"
"sort"
"sync"
@@ -42,6 +43,7 @@
{
name: name,
path: path,
+ relative_path: relative-path,
remote: remote,
revision: rev
},{...}...
@@ -50,6 +52,7 @@
{
name: name,
path: path,
+ relative_path: relative-path,
remote: remote,
revision: rev
},{...}...
@@ -58,10 +61,12 @@
{
name: name,
path: path,
+ relative_path: relative-path,
remote: remote,
revision: rev
old_revision: old-rev, // if updated
old_path: old-path //if moved
+ old_relative_path: old-relative-path //if moved
cls:[
{
number: num,
@@ -93,15 +98,17 @@
}
type DiffProject struct {
- Name string `json:"name"`
- Remote string `json:"remote"`
- Path string `json:"path"`
- OldPath string `json:"old_path,omitempty"`
- Revision string `json:"revision"`
- OldRevision string `json:"old_revision,omitempty"`
- Cls []DiffCl `json:"cls,omitempty"`
- Error string `json:"error,omitempty"`
- HasMoreCls bool `json:"has_more_cls,omitempty"`
+ Name string `json:"name"`
+ Remote string `json:"remote"`
+ Path string `json:"path"`
+ RelativePath string `json:"relative_path"`
+ OldPath string `json:"old_path,omitempty"`
+ OldRelativePath string `json:"old_relative_path,omitempty"`
+ Revision string `json:"revision"`
+ OldRevision string `json:"old_revision,omitempty"`
+ Cls []DiffCl `json:"cls,omitempty"`
+ Error string `json:"error,omitempty"`
+ HasMoreCls bool `json:"has_more_cls,omitempty"`
}
type DiffProjectsByName []DiffProject
@@ -169,11 +176,17 @@
// Get deleted projects
for key, p1 := range projects1 {
if _, ok := projects2[key]; !ok {
+ rp, err := filepath.Rel(jirix.Root, p1.Path)
+ if err != nil {
+ // should not happen
+ panic(err)
+ }
diff.DeletedProjects = append(diff.DeletedProjects, DiffProject{
- Name: p1.Name,
- Remote: p1.Remote,
- Path: p1.Path,
- Revision: p1.Revision,
+ Name: p1.Name,
+ Remote: p1.Remote,
+ Path: p1.Path,
+ RelativePath: rp,
+ Revision: p1.Revision,
})
}
}
@@ -182,11 +195,18 @@
updatedProjectKeys := make(chan project.ProjectKey, len(projects2))
for key, p2 := range projects2 {
if p1, ok := projects1[key]; !ok {
+ rp, err := filepath.Rel(jirix.Root, p2.Path)
+ if err != nil {
+ // should not happen
+ panic(err)
+ }
+
diff.NewProjects = append(diff.NewProjects, DiffProject{
- Name: p2.Name,
- Remote: p2.Remote,
- Path: p2.Path,
- Revision: p2.Revision,
+ Name: p2.Name,
+ Remote: p2.Remote,
+ Path: p2.Path,
+ RelativePath: rp,
+ Revision: p2.Revision,
})
} else {
if p1.Path != p2.Path || p1.Revision != p2.Revision {
@@ -200,14 +220,26 @@
processUpdatedProject := func(key project.ProjectKey) DiffProject {
p1 := projects1[key]
p2 := projects2[key]
+ rp, err := filepath.Rel(jirix.Root, p2.Path)
+ if err != nil {
+ // should not happen
+ panic(err)
+ }
diffP := DiffProject{
- Name: p2.Name,
- Remote: p2.Remote,
- Path: p2.Path,
- Revision: p2.Revision,
+ Name: p2.Name,
+ Remote: p2.Remote,
+ Path: p2.Path,
+ RelativePath: rp,
+ Revision: p2.Revision,
}
if p1.Path != p2.Path {
+ rp, err := filepath.Rel(jirix.Root, p1.Path)
+ if err != nil {
+ // should not happen
+ panic(err)
+ }
diffP.OldPath = p1.Path
+ diffP.OldRelativePath = rp
}
if p1.Revision != p2.Revision {
diffP.OldRevision = p1.Revision
diff --git a/cmd/jiri/diff_test.go b/cmd/jiri/diff_test.go
index 23a4534..b469603 100644
--- a/cmd/jiri/diff_test.go
+++ b/cmd/jiri/diff_test.go
@@ -44,23 +44,27 @@
d.DeletedProjects[0].Name = m1.Projects[i].Name
d.DeletedProjects[0].Remote = m1.Projects[i].Remote
d.DeletedProjects[0].Path = filepath.Join(rootDir, m1.Projects[i].Path)
+ d.DeletedProjects[0].RelativePath = m1.Projects[i].Path
d.DeletedProjects[0].Revision = m1.Projects[i].Revision
d.NewProjects[0] = d.DeletedProjects[0]
m2.Projects[i].Name = fmt.Sprintf("new-project-%d", i)
m2.Projects[i].Path = fmt.Sprintf("new-path-%d", i)
d.NewProjects[0].Name = m2.Projects[i].Name
d.NewProjects[0].Path = filepath.Join(rootDir, m2.Projects[i].Path)
+ d.NewProjects[0].RelativePath = m2.Projects[i].Path
i = 4
d.DeletedProjects[1].Name = m1.Projects[i].Name
d.DeletedProjects[1].Remote = m1.Projects[i].Remote
d.DeletedProjects[1].Path = filepath.Join(rootDir, m1.Projects[i].Path)
+ d.DeletedProjects[1].RelativePath = m1.Projects[i].Path
d.DeletedProjects[1].Revision = m1.Projects[i].Revision
d.NewProjects[1] = d.DeletedProjects[1]
m2.Projects[i].Name = fmt.Sprintf("new-project-%d", i)
m2.Projects[i].Path = fmt.Sprintf("new-path-%d", i)
d.NewProjects[1].Name = m2.Projects[i].Name
d.NewProjects[1].Path = filepath.Join(rootDir, m2.Projects[i].Path)
+ d.NewProjects[1].RelativePath = m2.Projects[i].Path
// update revision
i = 0
@@ -68,6 +72,7 @@
d.UpdatedProjects[0].Name = m1.Projects[i].Name
d.UpdatedProjects[0].Remote = m1.Projects[i].Remote
d.UpdatedProjects[0].Path = filepath.Join(rootDir, m1.Projects[i].Path)
+ d.UpdatedProjects[0].RelativePath = m1.Projects[i].Path
d.UpdatedProjects[0].OldRevision = m1.Projects[i].Revision
d.UpdatedProjects[0].Revision = m2.Projects[i].Revision
d.UpdatedProjects[0].Error = "no gerrit host"
@@ -78,7 +83,9 @@
d.UpdatedProjects[1].Name = m1.Projects[i].Name
d.UpdatedProjects[1].Remote = m1.Projects[i].Remote
d.UpdatedProjects[1].Path = filepath.Join(rootDir, m2.Projects[i].Path)
+ d.UpdatedProjects[1].RelativePath = m2.Projects[i].Path
d.UpdatedProjects[1].OldPath = filepath.Join(rootDir, m1.Projects[i].Path)
+ d.UpdatedProjects[1].OldRelativePath = m1.Projects[i].Path
d.UpdatedProjects[1].Revision = m1.Projects[i].Revision
// rename project