How to print initial letter of committer in git log? - regex

I have prepared an alias to get a short log report in git
# excerpt from ~/.gitconfig
[alias]
lg = log --all --oneline --graph --decorate --pretty='%C(auto)%h %Cgreen%ai %C(reset)%C(auto)%s %d'
git lg generates one nice line per commit, but without information on the user:
* 623beff 2016-11-14 14:18:36 +0100 extended plotstyle option and automatic colors
or as screenshot:
But I want to see the initial letters of the committer real name (the full name is sometimes too long) in each line:
* 623beff 2016-11-14 14:18:36 +0100 (J.S.) extended plotstyle option and automatic colors
How can I get this result?

there is a way to do this to get the first letter of the first name, using %<(3,trunc)%cN:
git log --all --oneline --graph --decorate --pretty='%C(auto)%h %Cgreen%ai %C(reset)%C(auto)(%<(3,trunc)%cN) %s %d'
output:
* 8759307 2009-01-15 16:11:48 +0000 (S..) Remove spurious code trying to tag a branch root before the mark was created. (HEAD -> master, origin/master, origin/HEAD)
* 939f999 2008-12-11 13:41:37 +0000 (S..) When just writing output file, do not try to devise lock target with no repository.

Related

how to pre-fix a piece of text in github "git log" using shell-script

I need to make a github commit (the text), from the git command git log into a link in an email. So the recipient can click on the link and go directly to the change.
I receive a long list containing lines with the text:
commit some_long_string_of_hexadecimals
and I need to transform this into:
commit https://github.com/account/repo/commit/some_long_string_of_hexadecimals
The log I am receiving contain n-amount of these logs, so I need the script to do this for all instances of this (some_long_string_of_hexadecimals).
Here are a few example log statements:
commit a98a897a67896a987698a769786a987a6987697a6
Author: Some Person <some#email.com>
Date: Thu Sep 29 09:48:52 2016 +0200
long message describing change.
commit a98a897a67896a987698a769786a987a6987697a6
Author: Some Person <some#email.com>
Date: Thu Sep 29 09:48:52 2016 +0200
more description
I'd like it to look like this:
commit https://github.com/account/repo/commit/a98a897a67896a987698a769786a987a6987697a6
Author: Some Person <some#email.com>
Date: Thu Sep 29 09:48:52 2016 +0200
added handling of running tests from within a docker container
How do I achieve this using a shell command ?
Thanks in advance.
awk '$1 == "commit" {$2 = "https://github.com/account/repo/commit/" $2} 1'
check if field 1 equals "commit"
if so, prepend to field 2
if line matched, print modified line, else print line as is

CloudWatch logs acting weird

I have two log files with multi-line log statements. Both of them have same datetime format at the begining of each log statement. The configuration looks like this:
state_file = /var/lib/awslogs/agent-state
[/opt/logdir/log1.0]
datetime_format = %Y-%m-%d %H:%M:%S
file = /opt/logdir/log1.0
log_stream_name = /opt/logdir/logs/log1.0
initial_position = start_of_file
multi_line_start_pattern = {datetime_format}
log_group_name = my.log.group
[/opt/logdir/log2-console.log]
datetime_format = %Y-%m-%d %H:%M:%S
file = /opt/logdir/log2-console.log
log_stream_name = /opt/logdir/log2-console.log
initial_position = start_of_file
multi_line_start_pattern = {datetime_format}
log_group_name = my.log.group
The cloudwatch logs agent is sending log1.0 logs correctly to my log group on cloudwatch, however, its not sending log files for log2-console.log.
awslogs.log says:
2016-11-15 08:11:41,308 - cwlogs.push.batch - WARNING - 3593 - Thread-4 - Skip event: {'timestamp': 1479196444000, 'start_position': 42330916L, 'end_position': 42331504L}, reason: timestamp is more than 2 hours in future.
2016-11-15 08:11:41,308 - cwlogs.push.batch - WARNING - 3593 - Thread-4 - Skip event: {'timestamp': 1479196451000, 'start_position': 42331504L, 'end_position': 42332092L}, reason: timestamp is more than 2 hours in future.
Though server time is correct. Also weird thing is Line numbers mentioned in start_position and end_position does not exist in actual log file being pushed.
Anyone else experiencing this issue?
I was able to fix this.
The state of awslogs was broken. The state is stored in a sqlite database in /var/awslogs/state/agent-state. You can access it via
sudo sqlite3 /var/awslogs/state/agent-state
sudo is needed to have write access.
List all streams with
select * from stream_state;
Look up your log stream and note the source_id which is part of a json data structure in the v column.
Then, list all records with this source_id (in my case it was 7675f84405fcb8fe5b6bb14eaa0c4bfd) in the push_state table
select * from push_state where k="7675f84405fcb8fe5b6bb14eaa0c4bfd";
The resulting record has a json data structure in the v column which contains a batch_timestamp. And this batch_timestamp seams to be wrong. It was in the past and any newer (more than 2 hours) log entries were not processed anymore.
The solution is to update this record. Copy the v column, replace the batch_timestamp with the current timestamp and update with something like
update push_state set v='... insert new value here ...' where k='7675f84405fcb8fe5b6bb14eaa0c4bfd';
Restart the service with
sudo /etc/init.d/awslogs restart
I hope it works for you!
We had the same issue and the following steps fixed the issue.
If log groups are not updating with latest events:
Run These steps:
Stopped the awslogs service
Deleted file /var/awslogs/state/agent-state
Updated /var/awslogs/etc/awslogs.conf configuration from hostaname to
instance ID Ex:
log_stream_name = {hostname} to log_stream_name = {instance_id}
Started awslogs service.
I was able to resolve this issue on Amazon Linux by:
sudo yum reinstall awslogs
sudo service awslogs restart
This method retained my config files in /var/awslogs/, though you may wish to back them up before a reinstall.
Note: In my troubleshooting, I had also deleted my Log Group via the AWS Console. The restart fully reloaded all historical logs, but at the present timestamp, which is of less value. I'm unsure if deleting the Log Group was this was necessary for this method to work. You might want to look at setting the initial_position config to end_of_file before you restart.
I found the reason. The time zone in my docker container is inconsistent with the time zone of my host computer. After setting the two time zones to be consistent, the problem is solved

Git: Getting commits with a ticket number

Okay, so I'm trying to find out if a ticket has been included in my release branch. The tickets are all built out of a project id and an id number, e.g. (PRO-123). I've tried this command:
git log --date=short --format="%h: %ad (%cn) %s" --abbrev-commit --grep='[A-Z]+-[0-9]+'
But it's not returning anything. If I take away the --grep part there's loads of matches to the pattern. For instance:
a6fdcd0: 2016-03-16 (ajfaraday) Merge remote-tracking branch 'origin/develop_5.2_customer' into release_5.2_customer
85d107a: 2016-03-16 (username) Merge pull request #477 from myapp/fix_CST-827_outline_method_in_use_check
6024bda: 2016-03-16 (Andrew Faraday) Merge pull request #473 from myapp/fix_CST-810_soap_container_create_bounds
eec2a61: 2016-03-16 (ajfaraday) added missing stubs
c03b3cb: 2016-03-15 (username) Merge pull request #472 from myapp/fix_CST-490_options_are_clickable_for_user_without_module_admin_rights
728539b: 2016-03-15 (username) Merge pull request #474 from myapp/fix_CST-873_hidden_error_on_pev_validation
4a11dd7: 2016-03-15 (username) Merge pull request #475 from myapp/fix_CST-854_copy_process_version_project_element_values
4a5af44: 2016-03-15 (ajfaraday) CST-854: fixed in-use check for methods
What am I doing wrong?
Okay, I think I've found the problem. It's some minor language difference in regexes (I'm usually writing them in my Ruby code).
For some reason [A-Z]+ wasn't matching but [A-Z]* is working fine. This line does what I wanted:
git log --date=short --format="%h: %ad (%cn) %s" --abbrev-commit --grep="[A-Z]*-[0-9]*"

How to purge a single checkin of the current branch in fossil?

I am using fossil for some kind of incremential backup database. So far it works very well, except purging old entries.
As this is all automated and meant to be simple all checkins/rollbacks work on the trunk.
Now I tried to add the option to purge old checkins, but I am not able to, always running into the error message:
cannot purge the current checkout
Perhaps I am using purge in a wrong way, though i wasn't able to find how to do it correctly.
Currently i add a tag to the checkins i want to remove, and try to purge them which doesn't work. Removing the trunk tag from those checkins makes no difference. Running purge while my local repository is closed is not possible as fossil requires the vvar table for this operation.
I did an example to illustrate:
D:\_tmp\repo>fossil init test
project-id: d16c0c72d95305884776f5c6e4d440ec687511a3
server-id: 1de96e7234a3e2b6561a31ad0cb9d55243be0bdb
admin-user: usr (initial password is "9dd6fb")
D:\_tmp\repo>fossil open test
project-name: <unnamed>
repository: D:/_tmp/repo/test
local-root: D:/_tmp/repo/
config-db: C:/Users/usr/AppData/Local/_fossil
project-code: d16c0c72d95305884776f5c6e4d440ec687511a3
checkout: 48edad6b8a3a946ad92b96bc41a2911ee709d6b5 2015-08-20 12:54:17 UTC
leaf: open
tags: trunk
comment: initial empty check-in (user: usr)
check-ins: 1
D:\_tmp\repo>fossil addremove
ADDED closedpurge.txt
added 1 files, deleted 0 files
D:\_tmp\repo>fossil commit -m auto
./closedpurge.txt contains CR/NL line endings. Use --no-warnings or the "crnl-gl
ob" setting to disable this warning.
Commit anyhow (a=all/c=convert/y/N)? a
New_Version: 3ffebd89c0d7e8ac92a21f3a0085568c39e113ea
D:\_tmp\repo>fossil addremove
DELETED closedpurge.txt
added 0 files, deleted 1 files
D:\_tmp\repo>fossil commit -m auto
New_Version: be0ac15264616ce86f0fce0b8a2de05c80ea3e0b
D:\_tmp\repo>fossil timeline
=== 2015-08-20 ===
12:55:05 [be0ac15264] *CURRENT* auto (user: usr tags: trunk)
12:54:47 [3ffebd89c0] auto (user: usr tags: trunk)
12:54:17 [48edad6b8a] initial empty check-in (user: usr tags: trunk)
+++ no more data (3) +++
D:\_tmp\repo>fossil tag add topurge 3ffebd89c0
D:\_tmp\repo>fossil timeline
=== 2015-08-20 ===
12:56:37 [98c3a4f991] Edit [3ffebd89c0d7e8ac|3ffebd89c0]: Add tag "topurge".
(user: usr)
12:55:05 [be0ac15264] *CURRENT* auto (user: usr tags: trunk)
12:54:47 [3ffebd89c0] auto (user: usr tags: trunk, topurge)
12:54:17 [48edad6b8a] initial empty check-in (user: usr tags: trunk)
+++ no more data (4) +++
D:\_tmp\repo>fossil purge topurge
cannot purge the current checkout
D:\_tmp\repo>fossil tag cancel trunk 3ffebd89c0
D:\_tmp\repo>fossil timeline
=== 2015-08-20 ===
12:57:30 [21885761c2] Edit [3ffebd89c0d7e8ac|3ffebd89c0]: Cancel tag "trunk".
(user: usr)
12:56:37 [98c3a4f991] Edit [3ffebd89c0d7e8ac|3ffebd89c0]: Add tag "topurge".
(user: usr)
12:55:05 [be0ac15264] *CURRENT* auto (user: usr)
12:54:47 [3ffebd89c0] auto (user: usr tags: topurge)
12:54:17 [48edad6b8a] initial empty check-in (user: usr tags: trunk)
+++ no more data (5) +++
D:\_tmp\repo>fossil purge topurge
cannot purge the current checkout
D:\_tmp\repo>fossil close
D:\_tmp\repo>fossil purge topurge -R test
SQLITE_ERROR: no such table: vvar
fossil: no such table: vvar
SELECT value FROM vvar WHERE name='checkout'
All i did was initializing a new fossil repository; add a single file and commit; rmeove the file and commit again; and try to purge the check in which added the file.
Edit: I tested this using fossil version 1.32 and 1.33
The error message appears to say it all, really: you can't purge the current checkout (which is the checkin marked as *CURRENT* in the timeline), or one of its descendants. From the help for the purge command (emphasis mine):
Move the check-ins identified by TAGS and all of their descendants
out of the repository (…)
The solution is to update or checkout to a different checkin that doesn't depend on the checkin to purge before doing the purge.

Parsing CVS History Output

I just need to get a list of the most recent changes from CVS and parse them.
Example: The CVS user "Lollerskates" checked in a file with spaces. But spaces are the delimiter! And then "skates" checked in a file with a space in a folder name.
% cvs history -c -a -D 2011-03-14
A 2011-03-15 00:17 +0000 jschmoe 1.1 CoolCode.java Awesome/Source/Java/src/com/widgets/foo/ambiguous/abstraction == <remote>
M 2011-03-15 00:17 +0000 sumbody 1.2 MoreCoolCode.java Awesome/Source/Java/src/com/widgets/foo/ambiguous/abstraction == <remote>
A 2011-03-15 00:17 +0000 lollerskates 1.123 This File Name Has Spaces.html Awesome/Source/Java/src/com/widgets/foo/ambiguous/abstraction == <remote>
A 2011-03-15 00:17 +0000 jschmoe 1.1 MyAwesomeProject.java Awesome/Source/Java/src/com/widgets/foo/ambiguous/abstraction == <remote>
M 2011-03-15 00:17 +0000 skates 1.5 BlahBlah.java Awesome/Source/Java/src/com/widgets/foo/content/block type/cart == <remote>
What is a reliable way to parse this?
Alternatively, is there a different CVS command with more easily parsable results?
This regex captures all of these:
\w \d{4}-\d{2}-\d{2} \d{2}:\d{2} \+\d{4} (\w+)\s+(\d+.\d+)\s+([\w\s]+\.\w+)\s+([\w\s/]+)== \<remote\>
The user is in group #1, filename in group #3 and path in group #4.
In this very case probably cut is a better way? If the fields are fixed length...