diff --git a/crates/gitql-engine/src/engine_function.rs b/crates/gitql-engine/src/engine_function.rs index 057c75f5..b7cb68df 100644 --- a/crates/gitql-engine/src/engine_function.rs +++ b/crates/gitql-engine/src/engine_function.rs @@ -23,6 +23,7 @@ fn select_references( fields: Vec, alias_table: HashMap, ) -> Vec { + let repo_path = repo.path().to_str().unwrap().to_string(); let mut gql_references: Vec = Vec::new(); let git_references = repo.references(); if git_references.is_err() { @@ -75,6 +76,15 @@ fn select_references( } } + if is_limit_fields_empty || fields.contains(&String::from("repo")) { + let key = alias_table + .get("repo") + .unwrap_or(&"repo".to_string()) + .to_string(); + + attributes.insert(key, repo_path.to_string()); + } + let gql_reference = GQLObject { attributes }; gql_references.push(gql_reference); } @@ -87,6 +97,8 @@ fn select_commits( fields: Vec, alias_table: HashMap, ) -> Vec { + let repo_path = repo.path().to_str().unwrap().to_string(); + let mut commits: Vec = Vec::new(); let mut revwalk = repo.revwalk().unwrap(); revwalk.push_head().unwrap(); @@ -145,6 +157,15 @@ fn select_commits( attributes.insert(key, commit.time().seconds().to_string()); } + if is_limit_fields_empty || fields.contains(&String::from("repo")) { + let key = alias_table + .get("repo") + .unwrap_or(&"repo".to_string()) + .to_string(); + + attributes.insert(key, repo_path.to_string()); + } + let gql_commit = GQLObject { attributes }; commits.push(gql_commit); } @@ -165,6 +186,7 @@ fn select_diffs( let select_insertions = fields.contains(&String::from("insertions")); let select_deletions = fields.contains(&String::from("deletions")); let select_file_changed = fields.contains(&String::from("files_changed")); + let repo_path = repo.path().to_str().unwrap().to_string(); for commit_id in revwalk { let commit = repo.find_commit(commit_id.unwrap()).unwrap(); @@ -194,6 +216,15 @@ fn select_diffs( attributes.insert(key, commit.author().email().unwrap_or("").to_string()); } + if is_limit_fields_empty || fields.contains(&String::from("repo")) { + let key = alias_table + .get("repo") + .unwrap_or(&"repo".to_string()) + .to_string(); + + attributes.insert(key, repo_path.to_string()); + } + if is_limit_fields_empty || select_insertions || select_deletions || select_file_changed { let diff = if commit.parents().len() > 0 { repo.diff_tree_to_tree( @@ -247,6 +278,7 @@ fn select_branches( let mut branches: Vec = Vec::new(); let local_branches = repo.branches(None).unwrap(); let is_limit_fields_empty = fields.is_empty(); + let repo_path = repo.path().to_str().unwrap().to_string(); for branch in local_branches { let (branch, _) = branch.unwrap(); @@ -288,6 +320,15 @@ fn select_branches( attributes.insert(key, branch.get().is_remote().to_string()); } + if is_limit_fields_empty || fields.contains(&String::from("repo")) { + let key = alias_table + .get("repo") + .unwrap_or(&"repo".to_string()) + .to_string(); + + attributes.insert(key, repo_path.to_string()); + } + let gql_branch = GQLObject { attributes }; branches.push(gql_branch); } @@ -303,20 +344,32 @@ fn select_tags( let mut tags: Vec = Vec::new(); let tag_names = repo.tag_names(None).unwrap(); let is_limit_fields_empty = fields.is_empty(); + let repo_path = repo.path().to_str().unwrap().to_string(); for tag_name in tag_names.iter() { match tag_name { Some(name) => { let mut attributes: HashMap = HashMap::new(); + if is_limit_fields_empty || fields.contains(&String::from("name")) { let key = alias_table .get("name") .unwrap_or(&"name".to_string()) .to_string(); attributes.insert(key, name.to_string()); - let gql_tag = GQLObject { attributes }; - tags.push(gql_tag); } + + if is_limit_fields_empty || fields.contains(&String::from("repo")) { + let key = alias_table + .get("repo") + .unwrap_or(&"repo".to_string()) + .to_string(); + + attributes.insert(key, repo_path.to_string()); + } + + let gql_tag = GQLObject { attributes }; + tags.push(gql_tag); } None => {} } diff --git a/crates/gitql-parser/src/parser.rs b/crates/gitql-parser/src/parser.rs index 7cd8b06b..65c7674a 100644 --- a/crates/gitql-parser/src/parser.rs +++ b/crates/gitql-parser/src/parser.rs @@ -18,14 +18,22 @@ use gitql_ast::types::TABLES_FIELDS_TYPES; lazy_static! { static ref TABLES_FIELDS_NAMES: HashMap<&'static str, Vec<&'static str>> = { let mut map = HashMap::new(); - map.insert("refs", vec!["name", "full_name", "type"]); + map.insert("refs", vec!["name", "full_name", "type", "repo"]); map.insert( "commits", - vec!["commit_id", "title", "message", "name", "email", "time"], + vec![ + "commit_id", + "title", + "message", + "name", + "email", + "time", + "repo", + ], ); map.insert( "branches", - vec!["name", "commit_count", "is_head", "is_remote"], + vec!["name", "commit_count", "is_head", "is_remote", "repo"], ); map.insert( "diffs", @@ -36,9 +44,10 @@ lazy_static! { "insertions", "deletions", "files_changed", + "repo", ], ); - map.insert("tags", vec!["name"]); + map.insert("tags", vec!["name", "repo"]); map }; } diff --git a/docs/structure/tables.md b/docs/structure/tables.md index 992c9e33..918c6ae7 100644 --- a/docs/structure/tables.md +++ b/docs/structure/tables.md @@ -3,24 +3,26 @@ ### References table -| Name | Type | Description | -| --------- | ---- | ------------------- | -| name | Text | Reference name | -| full_name | Text | Reference full name | -| type | Text | Reference type | +| Name | Type | Description | +| --------- | ---- | -------------------- | +| name | Text | Reference name | +| full_name | Text | Reference full name | +| type | Text | Reference type | +| repo | Text | Repository full path | ### Commits table --- -| Name | Type | Description | -| --------- | ---- | ------------------- | -| commit_id | Text | Commit id | -| title | Text | Commit title | -| message | Text | Commit full message | -| name | Text | Author name | -| email | Text | Author email | -| time | Date | Commit date | +| Name | Type | Description | +| --------- | ---- | -------------------- | +| commit_id | Text | Commit id | +| title | Text | Commit title | +| message | Text | Commit full message | +| name | Text | Author name | +| email | Text | Author email | +| time | Date | Commit date | +| repo | Text | Repository full path | --- @@ -34,6 +36,7 @@ | insertions | Number | Number of inserted lines | | deletions | Number | Number of deleted lines | | files_changed | Number | Number of file changed | +| repo | Text | Repository full path | --- @@ -45,11 +48,13 @@ | 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 | --- ### Tags table -| Name | Type | Description | -| ---- | ---- | ----------- | -| name | Text | Tag name | \ No newline at end of file +| Name | Type | Description | +| ---- | ---- | -------------------- | +| name | Text | Tag name | +| repo | Text | Repository full path | \ No newline at end of file