Skip to content

Commit

Permalink
Issue #112: Support query datetime from diffs table
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Jul 2, 2024
1 parent 926f6da commit 931639e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
21 changes: 11 additions & 10 deletions docs/structure/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ show tables

### Diffs table

| Name | Type | Description |
| ------------- | ------ | ------------------------ |
| commit_id | Text | Commit id |
| name | Text | Author name |
| email | Text | Author email |
| insertions | Number | Number of inserted lines |
| deletions | Number | Number of deleted lines |
| files_changed | Number | Number of file changed |
| repo | Text | Repository full path |
| Name | Type | Description |
| ------------- | -------- | ------------------------ |
| commit_id | Text | Commit id |
| name | Text | Author name |
| email | Text | Author email |
| insertions | Number | Number of inserted lines |
| deletions | Number | Number of deleted lines |
| files_changed | Number | Number of file changed |
| datetime | DateTime | Commit date time |
| repo | Text | Repository full path |

---

Expand Down Expand Up @@ -86,4 +87,4 @@ SHOW TABLES;
```sql
DESCRIBE commits;
DESCRIBE branches;
```
```
14 changes: 11 additions & 3 deletions src/git_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ fn select_diffs(repo: &gix::Repository, selected_columns: &[String]) -> Result<V
for commit_info in revwalk {
let commit_info = commit_info.unwrap();
let commit = commit_info.id().object().unwrap().into_commit();
let commit_ref = commit.decode().unwrap();

let mut values: Vec<Value> = Vec::with_capacity(selected_columns.len());

Expand All @@ -328,17 +329,25 @@ fn select_diffs(repo: &gix::Repository, selected_columns: &[String]) -> Result<V
}

if field_name == "name" {
let name = commit.author().unwrap().name.to_string();
let name = commit_ref.author().name.to_string();
values.push(Value::Text(name));
continue;
}

if field_name == "email" {
let email = commit.author().unwrap().email.to_string();
let email = commit_ref.author().email.to_string();
values.push(Value::Text(email));
continue;
}

if field_name == "datetime" {
let time_stamp = commit_info
.commit_time
.unwrap_or_else(|| commit_ref.time().seconds);
values.push(Value::DateTime(time_stamp));
continue;
}

if field_name == "repo" {
values.push(Value::Text(repo_path.to_string()));
continue;
Expand Down Expand Up @@ -416,7 +425,6 @@ fn select_tags(repo: &gix::Repository, selected_columns: &[String]) -> Result<Ve
let repo_path = repo.path().to_str().unwrap().to_string();

let names_len = selected_columns.len() as i64;

let mut rows: Vec<Row> = vec![];

for tag_ref in tag_names.flatten() {
Expand Down
1 change: 1 addition & 0 deletions src/git_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub fn tables_fields_names() -> &'static HashMap<&'static str, Vec<&'static str>
"insertions",
"deletions",
"files_changed",
"datetime",
"repo",
],
);
Expand Down

0 comments on commit 931639e

Please sign in to comment.