You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

593 lines
16 KiB

Adds side-by-side diff for images (#6784) * Adds side-by-side diff for images Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Explain blank imports Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use complete word for width and height labels on image compare Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update index.css from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ImageInfo to git commit file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Assign ImageInfo function for template and sets correct target for BeforeSourcePath Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error if ImageInfo failed Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Avoid template panic when ImageInfo failed for some reason Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show file size on image diff Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unused helper function Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Reverts copyright year change Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Close file reader Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update commit.go Sets correct data key * Moves reader.Close() up a few lines * Updates index.css * Updates CSS file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers adjustments for image compare to compare.go file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts variable name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Apply lesshint recommendations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Do not show old image on image compare if it is not in index of base commit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change file size text Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
Adds side-by-side diff for images (#6784) * Adds side-by-side diff for images Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Explain blank imports Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use complete word for width and height labels on image compare Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update index.css from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ImageInfo to git commit file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Assign ImageInfo function for template and sets correct target for BeforeSourcePath Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error if ImageInfo failed Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Avoid template panic when ImageInfo failed for some reason Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show file size on image diff Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unused helper function Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Reverts copyright year change Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Close file reader Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update commit.go Sets correct data key * Moves reader.Close() up a few lines * Updates index.css * Updates CSS file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers adjustments for image compare to compare.go file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts variable name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Apply lesshint recommendations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Do not show old image on image compare if it is not in index of base commit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change file size text Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 years ago
Adds side-by-side diff for images (#6784) * Adds side-by-side diff for images Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Explain blank imports Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use complete word for width and height labels on image compare Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update index.css from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ImageInfo to git commit file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Assign ImageInfo function for template and sets correct target for BeforeSourcePath Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error if ImageInfo failed Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Avoid template panic when ImageInfo failed for some reason Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show file size on image diff Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unused helper function Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Reverts copyright year change Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Close file reader Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update commit.go Sets correct data key * Moves reader.Close() up a few lines * Updates index.css * Updates CSS file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers adjustments for image compare to compare.go file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts variable name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Apply lesshint recommendations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Do not show old image on image compare if it is not in index of base commit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change file size text Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 years ago
Adds side-by-side diff for images (#6784) * Adds side-by-side diff for images Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Explain blank imports Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use complete word for width and height labels on image compare Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update index.css from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ImageInfo to git commit file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Assign ImageInfo function for template and sets correct target for BeforeSourcePath Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error if ImageInfo failed Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Avoid template panic when ImageInfo failed for some reason Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show file size on image diff Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unused helper function Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Reverts copyright year change Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Close file reader Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update commit.go Sets correct data key * Moves reader.Close() up a few lines * Updates index.css * Updates CSS file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers adjustments for image compare to compare.go file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts variable name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Apply lesshint recommendations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Do not show old image on image compare if it is not in index of base commit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change file size text Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
4 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
5 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
4 years ago
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package git
  6. import (
  7. "bufio"
  8. "bytes"
  9. "container/list"
  10. "fmt"
  11. "image"
  12. "image/color"
  13. _ "image/gif" // for processing gif images
  14. _ "image/jpeg" // for processing jpeg images
  15. _ "image/png" // for processing png images
  16. "io"
  17. "net/http"
  18. "strconv"
  19. "strings"
  20. "github.com/go-git/go-git/v5/plumbing/object"
  21. "github.com/mcuadros/go-version"
  22. )
  23. // Commit represents a git commit.
  24. type Commit struct {
  25. Branch string // Branch this commit belongs to
  26. Tree
  27. ID SHA1 // The ID of this commit object
  28. Author *Signature
  29. Committer *Signature
  30. CommitMessage string
  31. Signature *CommitGPGSignature
  32. Parents []SHA1 // SHA1 strings
  33. submoduleCache *ObjectCache
  34. }
  35. // CommitGPGSignature represents a git commit signature part.
  36. type CommitGPGSignature struct {
  37. Signature string
  38. Payload string //TODO check if can be reconstruct from the rest of commit information to not have duplicate data
  39. }
  40. func convertPGPSignature(c *object.Commit) *CommitGPGSignature {
  41. if c.PGPSignature == "" {
  42. return nil
  43. }
  44. var w strings.Builder
  45. var err error
  46. if _, err = fmt.Fprintf(&w, "tree %s\n", c.TreeHash.String()); err != nil {
  47. return nil
  48. }
  49. for _, parent := range c.ParentHashes {
  50. if _, err = fmt.Fprintf(&w, "parent %s\n", parent.String()); err != nil {
  51. return nil
  52. }
  53. }
  54. if _, err = fmt.Fprint(&w, "author "); err != nil {
  55. return nil
  56. }
  57. if err = c.Author.Encode(&w); err != nil {
  58. return nil
  59. }
  60. if _, err = fmt.Fprint(&w, "\ncommitter "); err != nil {
  61. return nil
  62. }
  63. if err = c.Committer.Encode(&w); err != nil {
  64. return nil
  65. }
  66. if _, err = fmt.Fprintf(&w, "\n\n%s", c.Message); err != nil {
  67. return nil
  68. }
  69. return &CommitGPGSignature{
  70. Signature: c.PGPSignature,
  71. Payload: w.String(),
  72. }
  73. }
  74. func convertCommit(c *object.Commit) *Commit {
  75. return &Commit{
  76. ID: c.Hash,
  77. CommitMessage: c.Message,
  78. Committer: &c.Committer,
  79. Author: &c.Author,
  80. Signature: convertPGPSignature(c),
  81. Parents: c.ParentHashes,
  82. }
  83. }
  84. // Message returns the commit message. Same as retrieving CommitMessage directly.
  85. func (c *Commit) Message() string {
  86. return c.CommitMessage
  87. }
  88. // Summary returns first line of commit message.
  89. func (c *Commit) Summary() string {
  90. return strings.Split(strings.TrimSpace(c.CommitMessage), "\n")[0]
  91. }
  92. // ParentID returns oid of n-th parent (0-based index).
  93. // It returns nil if no such parent exists.
  94. func (c *Commit) ParentID(n int) (SHA1, error) {
  95. if n >= len(c.Parents) {
  96. return SHA1{}, ErrNotExist{"", ""}
  97. }
  98. return c.Parents[n], nil
  99. }
  100. // Parent returns n-th parent (0-based index) of the commit.
  101. func (c *Commit) Parent(n int) (*Commit, error) {
  102. id, err := c.ParentID(n)
  103. if err != nil {
  104. return nil, err
  105. }
  106. parent, err := c.repo.getCommit(id)
  107. if err != nil {
  108. return nil, err
  109. }
  110. return parent, nil
  111. }
  112. // ParentCount returns number of parents of the commit.
  113. // 0 if this is the root commit, otherwise 1,2, etc.
  114. func (c *Commit) ParentCount() int {
  115. return len(c.Parents)
  116. }
  117. func isImageFile(data []byte) (string, bool) {
  118. contentType := http.DetectContentType(data)
  119. if strings.Contains(contentType, "image/") {
  120. return contentType, true
  121. }
  122. return contentType, false
  123. }
  124. // IsImageFile is a file image type
  125. func (c *Commit) IsImageFile(name string) bool {
  126. blob, err := c.GetBlobByPath(name)
  127. if err != nil {
  128. return false
  129. }
  130. dataRc, err := blob.DataAsync()
  131. if err != nil {
  132. return false
  133. }
  134. defer dataRc.Close()
  135. buf := make([]byte, 1024)
  136. n, _ := dataRc.Read(buf)
  137. buf = buf[:n]
  138. _, isImage := isImageFile(buf)
  139. return isImage
  140. }
  141. // ImageMetaData represents metadata of an image file
  142. type ImageMetaData struct {
  143. ColorModel color.Model
  144. Width int
  145. Height int
  146. ByteSize int64
  147. }
  148. // ImageInfo returns information about the dimensions of an image
  149. func (c *Commit) ImageInfo(name string) (*ImageMetaData, error) {
  150. if !c.IsImageFile(name) {
  151. return nil, nil
  152. }
  153. blob, err := c.GetBlobByPath(name)
  154. if err != nil {
  155. return nil, err
  156. }
  157. reader, err := blob.DataAsync()
  158. if err != nil {
  159. return nil, err
  160. }
  161. defer reader.Close()
  162. config, _, err := image.DecodeConfig(reader)
  163. if err != nil {
  164. return nil, err
  165. }
  166. metadata := ImageMetaData{
  167. ColorModel: config.ColorModel,
  168. Width: config.Width,
  169. Height: config.Height,
  170. ByteSize: blob.Size(),
  171. }
  172. return &metadata, nil
  173. }
  174. // GetCommitByPath return the commit of relative path object.
  175. func (c *Commit) GetCommitByPath(relpath string) (*Commit, error) {
  176. return c.repo.getCommitByPathWithID(c.ID, relpath)
  177. }
  178. // AddChanges marks local changes to be ready for commit.
  179. func AddChanges(repoPath string, all bool, files ...string) error {
  180. return AddChangesWithArgs(repoPath, GlobalCommandArgs, all, files...)
  181. }
  182. // AddChangesWithArgs marks local changes to be ready for commit.
  183. func AddChangesWithArgs(repoPath string, gloablArgs []string, all bool, files ...string) error {
  184. cmd := NewCommandNoGlobals(append(gloablArgs, "add")...)
  185. if all {
  186. cmd.AddArguments("--all")
  187. }
  188. cmd.AddArguments("--")
  189. _, err := cmd.AddArguments(files...).RunInDir(repoPath)
  190. return err
  191. }
  192. // CommitChangesOptions the options when a commit created
  193. type CommitChangesOptions struct {
  194. Committer *Signature
  195. Author *Signature
  196. Message string
  197. }
  198. // CommitChanges commits local changes with given committer, author and message.
  199. // If author is nil, it will be the same as committer.
  200. func CommitChanges(repoPath string, opts CommitChangesOptions) error {
  201. cargs := make([]string, len(GlobalCommandArgs))
  202. copy(cargs, GlobalCommandArgs)
  203. return CommitChangesWithArgs(repoPath, cargs, opts)
  204. }
  205. // CommitChangesWithArgs commits local changes with given committer, author and message.
  206. // If author is nil, it will be the same as committer.
  207. func CommitChangesWithArgs(repoPath string, args []string, opts CommitChangesOptions) error {
  208. cmd := NewCommandNoGlobals(args...)
  209. if opts.Committer != nil {
  210. cmd.AddArguments("-c", "user.name="+opts.Committer.Name, "-c", "user.email="+opts.Committer.Email)
  211. }
  212. cmd.AddArguments("commit")
  213. if opts.Author == nil {
  214. opts.Author = opts.Committer
  215. }
  216. if opts.Author != nil {
  217. cmd.AddArguments(fmt.Sprintf("--author='%s <%s>'", opts.Author.Name, opts.Author.Email))
  218. }
  219. cmd.AddArguments("-m", opts.Message)
  220. _, err := cmd.RunInDir(repoPath)
  221. // No stderr but exit status 1 means nothing to commit.
  222. if err != nil && err.Error() == "exit status 1" {
  223. return nil
  224. }
  225. return err
  226. }
  227. // AllCommitsCount returns count of all commits in repository
  228. func AllCommitsCount(repoPath string) (int64, error) {
  229. stdout, err := NewCommand("rev-list", "--all", "--count").RunInDir(repoPath)
  230. if err != nil {
  231. return 0, err
  232. }
  233. return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
  234. }
  235. func commitsCount(repoPath string, revision, relpath []string) (int64, error) {
  236. cmd := NewCommand("rev-list", "--count")
  237. cmd.AddArguments(revision...)
  238. if len(relpath) > 0 {
  239. cmd.AddArguments("--")
  240. cmd.AddArguments(relpath...)
  241. }
  242. stdout, err := cmd.RunInDir(repoPath)
  243. if err != nil {
  244. return 0, err
  245. }
  246. return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
  247. }
  248. // CommitsCount returns number of total commits of until given revision.
  249. func CommitsCount(repoPath, revision string) (int64, error) {
  250. return commitsCount(repoPath, []string{revision}, []string{})
  251. }
  252. // CommitsCount returns number of total commits of until current revision.
  253. func (c *Commit) CommitsCount() (int64, error) {
  254. return CommitsCount(c.repo.Path, c.ID.String())
  255. }
  256. // CommitsByRange returns the specific page commits before current revision, every page's number default by CommitsRangeSize
  257. func (c *Commit) CommitsByRange(page, pageSize int) (*list.List, error) {
  258. return c.repo.commitsByRange(c.ID, page, pageSize)
  259. }
  260. // CommitsBefore returns all the commits before current revision
  261. func (c *Commit) CommitsBefore() (*list.List, error) {
  262. return c.repo.getCommitsBefore(c.ID)
  263. }
  264. // HasPreviousCommit returns true if a given commitHash is contained in commit's parents
  265. func (c *Commit) HasPreviousCommit(commitHash SHA1) (bool, error) {
  266. for i := 0; i < c.ParentCount(); i++ {
  267. commit, err := c.Parent(i)
  268. if err != nil {
  269. return false, err
  270. }
  271. if commit.ID == commitHash {
  272. return true, nil
  273. }
  274. commitInParentCommit, err := commit.HasPreviousCommit(commitHash)
  275. if err != nil {
  276. return false, err
  277. }
  278. if commitInParentCommit {
  279. return true, nil
  280. }
  281. }
  282. return false, nil
  283. }
  284. // CommitsBeforeLimit returns num commits before current revision
  285. func (c *Commit) CommitsBeforeLimit(num int) (*list.List, error) {
  286. return c.repo.getCommitsBeforeLimit(c.ID, num)
  287. }
  288. // CommitsBeforeUntil returns the commits between commitID to current revision
  289. func (c *Commit) CommitsBeforeUntil(commitID string) (*list.List, error) {
  290. endCommit, err := c.repo.GetCommit(commitID)
  291. if err != nil {
  292. return nil, err
  293. }
  294. return c.repo.CommitsBetween(c, endCommit)
  295. }
  296. // SearchCommitsOptions specify the parameters for SearchCommits
  297. type SearchCommitsOptions struct {
  298. Keywords []string
  299. Authors, Committers []string
  300. After, Before string
  301. All bool
  302. }
  303. // NewSearchCommitsOptions construct a SearchCommitsOption from a space-delimited search string
  304. func NewSearchCommitsOptions(searchString string, forAllRefs bool) SearchCommitsOptions {
  305. var keywords, authors, committers []string
  306. var after, before string
  307. fields := strings.Fields(searchString)
  308. for _, k := range fields {
  309. switch {
  310. case strings.HasPrefix(k, "author:"):
  311. authors = append(authors, strings.TrimPrefix(k, "author:"))
  312. case strings.HasPrefix(k, "committer:"):
  313. committers = append(committers, strings.TrimPrefix(k, "committer:"))
  314. case strings.HasPrefix(k, "after:"):
  315. after = strings.TrimPrefix(k, "after:")
  316. case strings.HasPrefix(k, "before:"):
  317. before = strings.TrimPrefix(k, "before:")
  318. default:
  319. keywords = append(keywords, k)
  320. }
  321. }
  322. return SearchCommitsOptions{
  323. Keywords: keywords,
  324. Authors: authors,
  325. Committers: committers,
  326. After: after,
  327. Before: before,
  328. All: forAllRefs,
  329. }
  330. }
  331. // SearchCommits returns the commits match the keyword before current revision
  332. func (c *Commit) SearchCommits(opts SearchCommitsOptions) (*list.List, error) {
  333. return c.repo.searchCommits(c.ID, opts)
  334. }
  335. // GetFilesChangedSinceCommit get all changed file names between pastCommit to current revision
  336. func (c *Commit) GetFilesChangedSinceCommit(pastCommit string) ([]string, error) {
  337. return c.repo.getFilesChanged(pastCommit, c.ID.String())
  338. }
  339. // FileChangedSinceCommit Returns true if the file given has changed since the the past commit
  340. // YOU MUST ENSURE THAT pastCommit is a valid commit ID.
  341. func (c *Commit) FileChangedSinceCommit(filename, pastCommit string) (bool, error) {
  342. return c.repo.FileChangedBetweenCommits(filename, pastCommit, c.ID.String())
  343. }
  344. // HasFile returns true if the file given exists on this commit
  345. // This does only mean it's there - it does not mean the file was changed during the commit.
  346. func (c *Commit) HasFile(filename string) (bool, error) {
  347. _, err := c.GetBlobByPath(filename)
  348. if err != nil {
  349. return false, err
  350. }
  351. return true, nil
  352. }
  353. // GetSubModules get all the sub modules of current revision git tree
  354. func (c *Commit) GetSubModules() (*ObjectCache, error) {
  355. if c.submoduleCache != nil {
  356. return c.submoduleCache, nil
  357. }
  358. entry, err := c.GetTreeEntryByPath(".gitmodules")
  359. if err != nil {
  360. if _, ok := err.(ErrNotExist); ok {
  361. return nil, nil
  362. }
  363. return nil, err
  364. }
  365. rd, err := entry.Blob().DataAsync()
  366. if err != nil {
  367. return nil, err
  368. }
  369. defer rd.Close()
  370. scanner := bufio.NewScanner(rd)
  371. c.submoduleCache = newObjectCache()
  372. var ismodule bool
  373. var path string
  374. for scanner.Scan() {
  375. if strings.HasPrefix(scanner.Text(), "[submodule") {
  376. ismodule = true
  377. continue
  378. }
  379. if ismodule {
  380. fields := strings.Split(scanner.Text(), "=")
  381. k := strings.TrimSpace(fields[0])
  382. if k == "path" {
  383. path = strings.TrimSpace(fields[1])
  384. } else if k == "url" {
  385. c.submoduleCache.Set(path, &SubModule{path, strings.TrimSpace(fields[1])})
  386. ismodule = false
  387. }
  388. }
  389. }
  390. return c.submoduleCache, nil
  391. }
  392. // GetSubModule get the sub module according entryname
  393. func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {
  394. modules, err := c.GetSubModules()
  395. if err != nil {
  396. return nil, err
  397. }
  398. if modules != nil {
  399. module, has := modules.Get(entryname)
  400. if has {
  401. return module.(*SubModule), nil
  402. }
  403. }
  404. return nil, nil
  405. }
  406. // GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only')
  407. func (c *Commit) GetBranchName() (string, error) {
  408. binVersion, err := BinVersion()
  409. if err != nil {
  410. return "", fmt.Errorf("Git version missing: %v", err)
  411. }
  412. args := []string{
  413. "name-rev",
  414. }
  415. if version.Compare(binVersion, "2.13.0", ">=") {
  416. args = append(args, "--exclude", "refs/tags/*")
  417. }
  418. args = append(args, "--name-only", "--no-undefined", c.ID.String())
  419. data, err := NewCommand(args...).RunInDir(c.repo.Path)
  420. if err != nil {
  421. // handle special case where git can not describe commit
  422. if strings.Contains(err.Error(), "cannot describe") {
  423. return "", nil
  424. }
  425. return "", err
  426. }
  427. // name-rev commitID output will be "master" or "master~12"
  428. return strings.SplitN(strings.TrimSpace(data), "~", 2)[0], nil
  429. }
  430. // LoadBranchName load branch name for commit
  431. func (c *Commit) LoadBranchName() (err error) {
  432. if len(c.Branch) != 0 {
  433. return
  434. }
  435. c.Branch, err = c.GetBranchName()
  436. return
  437. }
  438. // GetTagName gets the current tag name for given commit
  439. func (c *Commit) GetTagName() (string, error) {
  440. data, err := NewCommand("describe", "--exact-match", "--tags", "--always", c.ID.String()).RunInDir(c.repo.Path)
  441. if err != nil {
  442. // handle special case where there is no tag for this commit
  443. if strings.Contains(err.Error(), "no tag exactly matches") {
  444. return "", nil
  445. }
  446. return "", err
  447. }
  448. return strings.TrimSpace(data), nil
  449. }
  450. // CommitFileStatus represents status of files in a commit.
  451. type CommitFileStatus struct {
  452. Added []string
  453. Removed []string
  454. Modified []string
  455. }
  456. // NewCommitFileStatus creates a CommitFileStatus
  457. func NewCommitFileStatus() *CommitFileStatus {
  458. return &CommitFileStatus{
  459. []string{}, []string{}, []string{},
  460. }
  461. }
  462. // GetCommitFileStatus returns file status of commit in given repository.
  463. func GetCommitFileStatus(repoPath, commitID string) (*CommitFileStatus, error) {
  464. stdout, w := io.Pipe()
  465. done := make(chan struct{})
  466. fileStatus := NewCommitFileStatus()
  467. go func() {
  468. scanner := bufio.NewScanner(stdout)
  469. for scanner.Scan() {
  470. fields := strings.Fields(scanner.Text())
  471. if len(fields) < 2 {
  472. continue
  473. }
  474. switch fields[0][0] {
  475. case 'A':
  476. fileStatus.Added = append(fileStatus.Added, fields[1])
  477. case 'D':
  478. fileStatus.Removed = append(fileStatus.Removed, fields[1])
  479. case 'M':
  480. fileStatus.Modified = append(fileStatus.Modified, fields[1])
  481. }
  482. }
  483. done <- struct{}{}
  484. }()
  485. stderr := new(bytes.Buffer)
  486. err := NewCommand("show", "--name-status", "--pretty=format:''", commitID).RunInDirPipeline(repoPath, w, stderr)
  487. w.Close() // Close writer to exit parsing goroutine
  488. if err != nil {
  489. return nil, concatenateError(err, stderr.String())
  490. }
  491. <-done
  492. return fileStatus, nil
  493. }
  494. // GetFullCommitID returns full length (40) of commit ID by given short SHA in a repository.
  495. func GetFullCommitID(repoPath, shortID string) (string, error) {
  496. commitID, err := NewCommand("rev-parse", shortID).RunInDir(repoPath)
  497. if err != nil {
  498. if strings.Contains(err.Error(), "exit status 128") {
  499. return "", ErrNotExist{shortID, ""}
  500. }
  501. return "", err
  502. }
  503. return strings.TrimSpace(commitID), nil
  504. }
  505. // GetRepositoryDefaultPublicGPGKey returns the default public key for this commit
  506. func (c *Commit) GetRepositoryDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings, error) {
  507. if c.repo == nil {
  508. return nil, nil
  509. }
  510. return c.repo.GetDefaultPublicGPGKey(forceUpdate)
  511. }