Skip to content

Commit

Permalink
feat: Implemnet updated column for branches table
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Apr 18, 2024
1 parent 537574e commit f79c737
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
15 changes: 8 additions & 7 deletions docs/structure/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ show tables

### Branches table

| Name | Type | Description |
| ------------ | ------ | -------------------------------- |
| name | Text | Branch name |
| commit_count | Number | Number of commits in this branch |
| is_head | Bool | Is the head branch |
| is_remote | Bool | Is a remote branch |
| repo | Text | Repository full path |
| Name | Type | Description |
| ------------ | -------- | -------------------------------- |
| name | Text | Branch name |
| commit_count | Number | Number of commits in this branch |
| is_head | Bool | Is the head branch |
| is_remote | Bool | Is a remote branch |
| updated | DateTime | Last update Commit date time |
| repo | Text | Repository full path |

---

Expand Down
24 changes: 23 additions & 1 deletion src/git_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ fn select_branches(
let values_len = fields_values.len() as i64;
let padding = names_len - values_len;

for branch in local_and_remote_branches.flatten() {
for mut branch in local_and_remote_branches.flatten() {
let mut values: Vec<Value> = Vec::with_capacity(fields_names.len());

for index in 0..names_len {
Expand Down Expand Up @@ -317,6 +317,28 @@ fn select_branches(
continue;
}

if field_name == "updated" {
if let Ok(top_commit_id) = branch.peel_to_id_in_place() {
let revwalk = top_commit_id.ancestors().all().unwrap();
if let Some(commit_info) = revwalk.into_iter().next() {
let commit_info = commit_info.unwrap();
if let Some(commit_timestamp) = commit_info.commit_time {
values.push(Value::DateTime(commit_timestamp));
continue;
}

let commit = repo.find_object(commit_info.id).unwrap().into_commit();
let commit = commit.decode().unwrap();
let time_stamp = commit.time().seconds;
values.push(Value::DateTime(time_stamp));
continue;
}
}

values.push(Value::Null);
continue;
}

if field_name == "is_head" {
values.push(Value::Boolean(branch.inner == head_ref.inner));
continue;
Expand Down
10 changes: 9 additions & 1 deletion src/git_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lazy_static! {
map.insert("is_head", DataType::Boolean);
map.insert("is_remote", DataType::Boolean);
map.insert("commit_count", DataType::Integer);
map.insert("updated", DataType::DateTime);
map.insert("repo", DataType::Text);
map
};
Expand All @@ -42,7 +43,14 @@ lazy_static! {
);
map.insert(
"branches",
vec!["name", "commit_count", "is_head", "is_remote", "repo"],
vec![
"name",
"commit_count",
"is_head",
"is_remote",
"updated",
"repo",
],
);
map.insert(
"diffs",
Expand Down

0 comments on commit f79c737

Please sign in to comment.