Skip to content

Commit

Permalink
Fix merging by hash instead of commit.id
Browse files Browse the repository at this point in the history
As commit.id was the first column of the data frame anyway,
merging has not changed the order. But when using the hash column
it is taken as the first colum of the resulting data frame.
Change the order of the columns in order to not break anything
that relies on the order.

See #180

Signed-off-by: Niklas Schneider <[email protected]>
  • Loading branch information
nlschn committed Jan 8, 2021
1 parent 89a6ea6 commit 6e9147e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ test_that("Merge commit messages to commit data", {
# we do not care for their order in the test
rownames(commits) = NULL
rownames(commit.data.expected) = NULL

expect_identical(commits, commit.data.expected)
})

Expand Down
18 changes: 15 additions & 3 deletions util-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@ ProjectData = R6::R6Class("ProjectData",
## get commit messages
commit.messages = self$get.commit.messages()

## drop the hash column as we do not want it twice
commit.messages = commit.messages[-2]
## drop the commit.id column as we do not want it twice
commit.messages = commit.messages[-1]

## now there are only three columns left: commit.id, title, message.body
## check whether to include only title or also the messages
Expand All @@ -721,7 +721,19 @@ ProjectData = R6::R6Class("ProjectData",
}

## merge them into the commit data
commit.data = merge(commit.data, commit.messages, by.x = "hash")
commit.data = merge(commit.data, commit.messages, by.x = "hash", by.y = "hash")

## when merging by hash, the hash column is taken as the first column of the
## resulting data frame
## change that order back depending on how many columns the new data frame has
if (private$project.conf$get.value("commit.messages") == "title") {
## one column less as message.body is not included
commit.data = commit.data[, c(2, 3, 4, 5, 6, 7, 8, 1, 9, 10, 11, 12, 13, 14, 15, 16, 17)]
}
else {
commit.data = commit.data[, c(2, 3, 4, 5, 6, 7, 8, 1, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)]
}

}

## store commit data
Expand Down

0 comments on commit 6e9147e

Please sign in to comment.